2019-12-13 09:48:00 -05:00
#!/bin/bash
################################################################################
## File: mysql.sh
## Desc: Installs MySQL Client
################################################################################
## Source the helpers for use with the script
source $HELPER_SCRIPTS /document.sh
export ACCEPT_EULA = Y
2020-06-25 16:21:08 +07:00
if isUbuntu16 || isUbuntu18 ; then
apt-get install mysql-client -y
fi
2019-12-13 09:48:00 -05:00
2020-06-25 16:21:08 +07:00
if isUbuntu20 ; then
# Install mysql 8 for Ubuntu 20.
2020-01-30 13:30:47 +03:00
2020-06-25 16:21:08 +07:00
debconf-set-selections <<< 'mysql-apt-config mysql-apt-config/select-server select mysql-8.0'
package_version = $( curl https://dev.mysql.com/downloads/repo/apt/ 2> /dev/null | grep "\.deb" | awk -F "[()]" '{print $2}' )
wget https://dev.mysql.com/get/$package_version
dpkg -i $package_version
apt update
fi
# Mysql setting up root password
2019-12-13 09:48:00 -05:00
MYSQL_ROOT_PASSWORD = root
echo "mysql-server mysql-server/root_password password $MYSQL_ROOT_PASSWORD " | debconf-set-selections
echo "mysql-server mysql-server/root_password_again password $MYSQL_ROOT_PASSWORD " | debconf-set-selections
2020-06-25 16:21:08 +07:00
# Install MySQL Server
2019-12-13 09:48:00 -05:00
apt-get install -y mysql-server
2020-06-25 16:21:08 +07:00
#Install MySQL Dev tools
apt install libmysqlclient-dev -y
2019-12-13 09:48:00 -05:00
# Install MS SQL Server client tools (https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-setup-tools?view=sql-server-2017)
apt-get install -y mssql-tools unixodbc-dev
apt-get -f install
ln -s /opt/mssql-tools/bin/* /usr/local/bin/
# Run tests to determine that the software installed as expected
echo "Testing to make sure that script performed as expected, and basic scenarios work"
if ! command -v mysql; then
echo "mysql was not installed"
exit 1
fi
set -e
mysql -vvv -e 'CREATE DATABASE smoke_test' -uroot -proot
mysql -vvv -e 'DROP DATABASE smoke_test' -uroot -proot
set +e
# Document what was added to the image
echo "Lastly, documenting what we added to the metadata file"
DocumentInstalledItem "MySQL ( $( mysql --version) )"
DocumentInstalledItem "MySQL Server (user:root password:root)"
DocumentInstalledItem "MS SQL Server Client Tools"
2020-04-27 14:48:28 +03:00
DocumentInstalledItem "MySQL service is disabled by default. Use the following command as a part of your job to start the service: 'sudo systemctl start mysql.service'"
2020-03-05 10:57:16 +03:00
# Disable mysql.service
2020-04-27 14:48:28 +03:00
systemctl is-active --quiet mysql.service && systemctl stop mysql.service
systemctl disable mysql.service