-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sh
64 lines (56 loc) · 2.06 KB
/
init.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# set -uxo pipefail
set -uo pipefail
contains_forward_slash() {
local string="$1"
if [[ $string == *"/"* ]]; then
echo "true"
else
echo "false"
fi
}
if [ $(contains_forward_slash "$DB_KEY_ENCRYPTION_PASSWORD") == "true" ]; then
echo "Error: DB_KEY_ENCRYPTION_PASSWORD cannot contain forward slash (/)"
kill -9 $(ps aux | grep 'sqlservr' | awk '{print $2}')
exit -1;
elif [ $(contains_forward_slash "$DB_NAME") == "true" ]; then
echo "Error: DB_NAME cannot contain forward slash (/)"
kill -9 $(ps aux | grep 'sqlservr' | awk '{print $2}')
exit -1;
elif [ $(contains_forward_slash "$DB_USER") == "true" ]; then
echo "Error: DB_USER cannot contain forward slash (/)"
kill -9 $(ps aux | grep 'sqlservr' | awk '{print $2}')
exit -1;
elif [ $(contains_forward_slash "$DB_PASSWORD") == "true" ]; then
echo "Error: DB_PASSWORD cannot contain forward slash (/)"
kill -9 $(ps aux | grep 'sqlservr' | awk '{print $2}')
exit -1;
fi
sed -i "s/__DB_KEY_ENCRYPTION_PASSWORD__/$DB_KEY_ENCRYPTION_PASSWORD/g" init.sql
sed -i "s/__DB_NAME__/$DB_NAME/g" init.sql
sed -i "s/__DB_USER__/$DB_USER/g" init.sql
sed -i "s/__DB_PASSWORD__/$DB_PASSWORD/g" init.sql
echo "Logging in to Azure"
az login --service-principal \
--username $AZ_USERNAME \
--password $AZ_PASSWORD \
--tenant $AZ_TENANT
# Allow SQL Server to start and accept connections
# sleep 30
# Wait for the SQL Server to come up
for i in {1..50};
do
echo "Test connection to MS SQL Server"
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "$MSSQL_SA_PASSWORD" -d master -Q "SELECT getdate();"
if [ $? -eq 0 ]
then
echo "Begin Initialization"
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "$MSSQL_SA_PASSWORD" -d master -i init.sql
echo "Initialization Completed. Run Test SQL Command to verify sanity."
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P "$MSSQL_SA_PASSWORD" -d master -Q "SELECT getdate();"
break
else
echo "MS SQL Server not ready yet..."
sleep 1
fi
done