Skip to content

Instantly share code, notes, and snippets.

@musa11971
Created February 19, 2020 22:08
Show Gist options
  • Save musa11971/3280b9a858ecb2902083d6107e5ee6b5 to your computer and use it in GitHub Desktop.
Save musa11971/3280b9a858ecb2902083d6107e5ee6b5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Colours
ORANGE='\033[0;33m'
BLACK='\033[0;30m'
LIME='\033[1;32m'
NC='\033[0m'
mssql() {
if [ -z "$1" ] || [ "$1" = 'help' ] || [ "$1" = '' ]; then
# Help command
echo -e " 📄 \e[1mMSSQL Manager"
echo -e "\e[33mUsage:\e[0m"
echo -e " 'mssql [command]'\n"
echo -e "\e[33mAvailable commands:\e[0m"
echo -e " \e[32mstart\e[0m\t\tStarts the MSSQL server in the background."
echo -e " \e[32mstop\e[0m\t\tKills the MSSQL server."
echo -e " \e[32madmin\e[0m\t\tEnters the MSSQL server as admin."
elif [ "$1" = 'start' ]; then
mssql stop
(trap "" SIGINT; exec -a MSSQLServer nohup sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=BahasaBahasa123' --name 'mssql' -p 1433:1433 microsoft/mssql-server-linux &>/dev/null &)
echo -e "\n${BLACK}[${ORANGE}MSSQL Manager${BLACK}] ${LIME}✔ ${NC}MSSQL server running in background."
echo -e "\n${BLACK}[${ORANGE}MSSQL Manager${BLACK}] ${NC}Use 'mssql admin' to enter as admin, or 'mssql stop' to kill the server."
elif [ "$1" = 'stop' ]; then
sudo docker kill mssql &> /dev/null;
sudo docker rm mssql &> /dev/null;
echo -e "\n${BLACK}[${ORANGE}MSSQL Manager${BLACK}] ${LIME}✔ ${NC}MSSQL server killed."
elif [ "$1" = 'admin' ]; then
sudo docker exec -it mssql /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P BahasaBahasa123
else
echo -e "\n${BLACK}[${ORANGE}MSSQL Manager${BLACK}] ${NC}Unknown command, use 'mssql help' to list all available commands."
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment