Skip to content

Instantly share code, notes, and snippets.

@kasperhartwich
Last active March 5, 2020 05:49
Show Gist options
  • Save kasperhartwich/bd381ce0f179e75ae1a11cbe8305a91a to your computer and use it in GitHub Desktop.
Save kasperhartwich/bd381ce0f179e75ae1a11cbe8305a91a to your computer and use it in GitHub Desktop.
Install MSSQL server on vagrant with ubuntu/homestead
#!/usr/bin/expect -f
# This installs MSSQL server and drivers on a vagrant ubuntu machine
#
# To use you need to install expect: `sudo apt-get install -y expect`
# and then run the script with the password you want: install-mssql.sh myPass123
# Then log in to the sql server with username `sa`and the password `myPass123`
set password [lindex $argv 0]
#Add MSSQL to package manger
system curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
system curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-2017.list | sudo tee /etc/apt/sources.list.d/mssql-server-2017.list
system sudo apt-get update
#Downgrade openssl
system sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::="--force-confold" --allow-downgrades openssl=1.0.2g-1ubuntu4
#Install MSSQL server
system sudo apt-get install -y mssql-server
##Setup mssql and set administrator password
spawn sudo /opt/mssql/bin/mssql-conf setup
expect "Enter your edition(1-7):"
send "2\r"
expect "Do you accept the license terms?"
send "Yes\r"
expect "Enter the SQL Server system administrator password:"
send "$password\r"
expect "Confirm the SQL Server system administrator password:"
send "$password\r"
expect "Setup has completed successfully. SQL Server is now starting."
#Install MSSQL tools
system sudo ACCEPT_EULA=Y apt-get install -y mssql-tools
system sudo apt-get install unixodbc-dev
system sudo ln -sfn /opt/mssql-tools/bin/sqlcmd /usr/bin/sqlcmd
system sudo ln -sfn /opt/mssql-tools/bin/bcp /usr/bin/bcp
#Install PHP sybase drivers for using MSSQL - Change this to version of PHP!
system sudo rm /var/cache/apt/archives/lock
system sudo DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" install php7.2-sybase
system sudo cp /vagrant/vagrant/freetds.conf /etc/freetds/
interact
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment