-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetupServer.sh
More file actions
75 lines (60 loc) · 2.05 KB
/
Copy pathsetupServer.sh
File metadata and controls
75 lines (60 loc) · 2.05 KB
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
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
#https://docs.microsoft.com/pt-br/sql/linux/sample-unattended-install-ubuntu?view=sql-server-linux-2017
# Product ID of the version of SQL server you're installing
MSSQL_PID='express'
if [ -z $DB_PASSWORD ]
then
echo Environment variable DB_PASSWORD must be set for unattended install
exit 1
fi
echo Adding Microsoft repositories...
sudo curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
repoargs="$(curl https://packages.microsoft.com/config/ubuntu/18.04/mssql-server-2017.list)"
sudo add-apt-repository "${repoargs}"
repoargs="$(curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list)"
sudo add-apt-repository "${repoargs}"
echo Running apt-get update -y...
sudo apt-get update -y
echo Installing SQL Server...
sudo apt-get install -y mssql-server
echo Running mssql-conf setup...
sudo MSSQL_SA_PASSWORD=$DB_PASSWORD \
MSSQL_PID=$MSSQL_PID \
/opt/mssql/bin/mssql-conf -n setup accept-eula
echo Installing mssql-tools and unixODBC developer...
sudo ACCEPT_EULA=Y apt-get install -y mssql-tools unixodbc-dev
# Add SQL Server tools to the path by default:
echo Adding SQL Server tools to your path...
echo PATH="$PATH:/opt/mssql-tools/bin" >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# Configure firewall to allow TCP port 1433:
echo Configuring UFW to allow traffic on port 1433...
sudo ufw allow 1433/tcp
sudo ufw reload
# Restart SQL Server after installing:
echo Restarting SQL Server...
sudo systemctl restart mssql-server
# Connect to server and get the version:
counter=1
errstatus=1
while [ $counter -le 5 ] && [ $errstatus = 1 ]
do
echo Waiting for SQL Server to start...
sleep 3s
/opt/mssql-tools/bin/sqlcmd \
-S localhost \
-U SA \
-P $DB_PASSWORD \
-Q "SELECT @@VERSION" 2>/dev/null
errstatus=$?
((counter++))
done
# Display error if connection failed:
if [ $errstatus = 1 ]
then
echo Cannot connect to SQL Server, installation aborted
exit $errstatus
fi
systemctl status mssql-server --no-pager
echo 'SQL SERVER Installed!'