#!/bin/bash
scriptdir=$PWD
#=====================================================================
# Use and edit this script as you please.
# I do not take any responsibility if this script might hurt your system,
# so use it at your own risk!
# Set the following variables to your system needs (also used to
# upgrade versions.
#=====================================================================
# Version of mysql
version="mysql-5.0.24"
# Download URL
url="http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.24.tar.gz/from/http://ftp.snt.utwente.nl/pub/software/mysql/"
# tar.gz that is downloaded (only this file format is supported!!!!)
file="mysql-5.0.24.tar.gz"
# Directories to download and extract mysql
downloadDir="/var/downloads"
installDir="/var/install"
# These are the options used to configure
options="--prefix=/usr/local/$version --localstatedir=/usr/local/$version --with-innodb --without-debug --with-tcp-port=3306 --with-mysqld-user=mysql --with-unix-socket-path=/tmp/mysql.sock --with-openssl"
# Global function (echo text bolded)
function echoBold()
{
echo -e "\033[1m$1\033[0m"
}
# Load DirectAdmin setup.txt (clean install!)
if [ -s /usr/local/directadmin/scripts/setup.txt ];
then
# Include the DirectAdmin setup details
chmod 0755 /usr/local/directadmin/scripts/setup.txt
. /usr/local/directadmin/scripts/setup.txt
# Restore file priveledges
chmod 0700 /usr/local/directadmin/scripts/setup.txt
else
mysqluser="root"
mysql="my password"
fi
# Enter a custom username or press enter to use the default
echoBold "- Enter MySQL username (with sufficient priveledges) [ie: $mysqluser]"
read input_mysql_user
if [ ! "$input_mysql_user" = "" ]
then
mysqluser="$input_mysql_user"
fi
# Enter a custom password or press enter to use the default
echoBold "- Enter user password [ie: $mysql]"
read input_mysql
if [ ! "$input_mysql" = "" ]
then
mysql="$input_mysql"
fi
# Begin
echoBold "- Installing version $version"
# Download ncurses (required)
apt-get update
apt-get install ncurses-dev
# Head to the download directory
if [ ! -d $downloadDir ]
then
echoBold "- Error, download directory does not exist"
exit 0
else
cd $downloadDir
fi
# Check to see if the file is downloaded
if [ ! -s $file ]
then
echoBold "- Downloading from $url"
wget $url
else
echoBold "- $file already downloaded"
fi
# Head to the install directory
if [ ! -d $installDir ]
then
echoBold "- Error install directory does not exist"
exit 0
else
cd $installDir
fi
# Untar if necessary
if [ ! -d "$installDir/$version" ]
then
echoBold "- Unpacking $file"
if [ ! -s "$downloadDir/$file" ]
then
echoBold "Error, $file isn't in $downloadDir"
exit 0
fi
# File is downloaded
tar -zxvf "$downloadDir/$file"
else
echoBold "- $file already unpacked"
fi
# Time to configure
if [ ! -d "$installDir/$version" ]
then
echoBold "Error, $installDir/$version dir does not exist"
exit 0
else
# Move to installation directory
cd $installDir/$version
# Makefile present
if [ -s $installDir/$version/Makefile ];
then
echoBold "- Clean previous install"
make clean
fi
echoBold "- Ready to configure"
./configure $options
echoBold "- Make"
make
echoBold "- Make install"
make install
fi
# Check if eventual directory is there
if [ ! -d "/usr/local/$version" ]
then
echoBold "Error, /usr/local/$version not found"
exit 0
fi
# Done installing, create sym links
if [ -L /usr/local/mysql ]
then
# Remove symlink
rm /usr/local/mysql
fi
# Create new symlink
echoBold "- Creating symlink /usr/local/$version /usr/local/mysql"
ln -s "/usr/local/$version" /usr/local/mysql
# Create symlink to data
if [ ! -L /usr/local/mysql/data ]
then
echoBold "- Creating symlink /home/mysql /usr/local/mysql/data"
ln -s /home/mysql /usr/local/mysql/data
fi
# Restart MySQL - IMPORTANT - SLEEP AFTER STOP AND START
/etc/init.d/mysqld stop
sleep 10
/etc/init.d/mysqld start
sleep 5
echoBold "- Installation complete"
echoBold "- Try to do a check"
/usr/local/mysql/bin/mysqlcheck --check-upgrade --all-databases --auto-repair --user=$mysqluser --password=$mysql
echoBold "- Upgrade privileges tables"
/usr/local/mysql/bin/mysql_fix_privilege_tables --user=$mysqluser --password=$mysql
exit 0