Skip to content

Instantly share code, notes, and snippets.

@krabello
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krabello/9a8af071c2c6a37166ab to your computer and use it in GitHub Desktop.
Save krabello/9a8af071c2c6a37166ab to your computer and use it in GitHub Desktop.
Mavericks MySQL Installer
#!/bin/bash
# Vars
greetingLine=$'\n\n#############################################\n\n\n';
mysqlInstalledErr=$'\nYou already have MySQL installed!\n';
osError=$'\nOS X 10.7+ Required. Exiting...\n';
downloadMessage=$'\nDownloading MySQL Installers ... may take a few moments\n';
installMessage=$'\nAttempting to install MySQL. Administrator password Required to continue\n'
mountError=$'\nNo Mountable MySQL Volume found\n';
installDir='/Volumes/mysql-5.6.17-osx10.7-x86_64/';
# ############# #
# Functions #
# ############# #
# Check the os version before continuing
checkOSVersion() {
if [[ $(sw_vers -productVersion | grep '10.[7-9]') ]]
then
return 1;
fi
return 0
}
# Simple greeting message
greeting() {
echo $greetingLine;
echo $'\nMySQL Installer for OSX 10.7+';
echo $'Before continuing make sure that you do not';
echo $'have any mysql running otherwise this script will fail.\n';
echo $greetingLine;
}
# Check if there is a version of MySQL currently installed
# If there is then exit
mysqlCheck() {
if [[ -d /usr/local/mysql && -d /var/mysql ]]
then
echo $mysqlInstalledErr;
exit;
fi
return 1;
}
# Download MySQL
mysqlDownload() {
echo $downloadMessage;
curl -# -o ~/Downloads/MySQL.dmg http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.17-osx10.7-x86_64.dmg
hdiutil attach -quiet ~/Downloads/MySQL.dmg;
cd $installDir;
if [ -d "$installDir" ]; then
mysqlInstall;
else
echo $mountError;
exit;
fi
return 1;
}
# Install MySQL
mysqlInstall() {
echo $installMessage;
sudo installer -pkg mysql-5.6.17-osx10.7-x86_64.pkg -target /;
return 1;
}
# Move Preference pane and start MySQL
mysqlInit() {
cp -R MySQL.prefPane ~/Downloads/MySQL.prefpane;
open ~/Downloads/MySQL.prefPane/;
sleep 15;
sudo /usr/local/mysql/support-files/mysql.server start;
echo "export PATH=$PATH:/usr/local/mysql/bin" >> ~/.bash_profile;
sudo mkdir /var/mysql; sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock;
}
# ############# #
# End functions #
# ############# #
if [[ checkOSVersion ]]
then
# display initial header message
greeting;
else
echo $osError;
exit;
fi
# does user want to continue?
while [[ true ]] ; do
read -p "DO YOU WANT TO CONTINUE? [Y/N]" yn
case $yn in
[Yy]) break ;;
[Nn]) exit ;;
* ) echo "Please answer yes or no.";
esac
done
# check if MySQL is installed
mysqlCheck;
# download and install MySQL
mysqlDownload;
# move files and start MySQL
mysqlInit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment