Skip to content

Instantly share code, notes, and snippets.

@jamiejackson

jamiejackson/_simplified.bash Secret

Created Sep 11, 2015
Embed
What would you like to do?
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
sudo add-apt-repository 'deb http://sfo1.mirrors.digitalocean.com/mariadb/repo/5.5/ubuntu precise main'
sudo apt-get update
sudo apt-get -y install mariadb-server
#!/usr/bin/env bash
set -e
description="MariaDB installation"
runfile_name=db_install_mariadb
while :
do
case $1 in
--apt-cache-archive=*)
apt_cache_archive=${1#*=} # Delete everything up till "="
shift
;;
--conf-file-to-patch=*)
conf_file_to_patch=${1#*=} # Delete everything up till "="
shift
;;
--password=*)
password=${1#*=} # Delete everything up till "="
shift
;;
--patch-file=*)
patch_file=${1#*=} # Delete everything up till "="
shift
;;
--provisioned-dir=*)
provisioned_dir=${1#*=} # Delete everything up till "="
shift
;;
--) # End of all options
shift
break
;;
-*)
echo "WARN: Unknown option (ignored): $1" >&2
shift
;;
*) # no more options. Stop while loop
break
;;
esac
done
runfile="${provisioned_dir}/${runfile_name}"
if [ -f "${runfile}" ]; then
echo "${description}: Already run."
exit 0
fi
echo "Preparing to install MariaDB"
echo "Installing some necessary packages"
sudo apt-get -y -o dir::cache::archives="${apt_cache_archive}" install python-software-properties
echo "Add MariaDB repository"
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
sudo add-apt-repository 'deb http://sfo1.mirrors.digitalocean.com/mariadb/repo/5.5/ubuntu precise main'
sudo apt-get update
echo "Preconfiguring root password for unattended installation"
export DEBIAN_FRONTEND=noninteractive
sudo debconf-set-selections <<< "mariadb-server-5.5 mysql-server/root_password password ${password}"
sudo debconf-set-selections <<< "mariadb-server-5.5 mysql-server/root_password_again password ${password}"
echo "Install MariaDB unattended"
# TODO: Temporary procedure, until MariaDB releases their new package
#echo "Package: *
#Pin: origin ftp.osuosl.org
#Pin-Priority: 1000" > /etc/apt/preferences.d/MariaDB.pref
#apt-get -y -o dir::cache::archives="${apt_cache_archive}" install mariadb-server-5.5 mariadb-client-5.5 libmysqlclient18=5.5.42+maria-1~precise mysql-common=5.5.42+maria-1~precise
# Permanent procedure
sudo apt-get -y -o dir::cache::archives="${apt_cache_archive}" install mariadb-server
echo "Configure MariaDB"
echo "Add Barracuda table support and remove local IP binding (so it's accessible externally)"
sudo patch -N "${conf_file_to_patch}" < "${patch_file}" || true
echo "Restart MariaDB for changes to take effect"
echo "Note, if you see errors such as, 'Can't connect to local MySQL server through socket', during the service restart, you can ignore them."
# sudo service mysql restart
# upstart might not work under docker, so we'll start up the old-fashioned way
sudo /etc/init.d/mysql restart
echo "Grant external access to root user"
mysql -u root --password=${password} -e "
# grant external access to root user
grant all privileges on *.* to 'root'@'%' identified by 'mypassword' with grant option;
flush privileges;
"
touch "${runfile}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.