#! /bin/bash -- ### ### Parameters ### if [ -z "$1" ] then echo -n "Create instance in: " read targetdir else targetdir=$1 fi if [ -d "$targetdir" ] then echo "Existing directory: $targetdir" else echo "Creating directory: $targetdir" fi if [ -z "$2" ] then echo -n "Version to use: " read targetversion else targetversion=$2 fi sourceversion=$( echo /usr/local/mysql-*$targetversion* ) if [ -z "$3" ] then echo -n "Port to use: " read targetport else targetport=$3 fi ### ### Check validity ### if [ ! -d $sourceversion ] then echo "Unknown version $sourceversion." exit 1 fi if [ ! -f $sourceversion/my.cnf ] then echo "No my.cnf in $sourceversion" exit 2 fi if [ ! -d $sourceversion/data/mysql ] then echo "No data/mysql in $sourceversion" exit 3 fi echo "Creating $targetversion instance from $sourceversion in $targetdir, listening on port $targetport." ### ### Do the copy ### mkdir $targetdir ( cd $sourceversion; tar -cf - my.cnf data/mysql )| ( cd $targetdir; tar -xf - ) ### ### Create start/stop scripts and wrappers ### cat > $targetdir/start < $targetdir/stop < $targetdir/$i-$targetport << EOF #! /bin/bash -- MYSQL_CMD_DIR=$sourceversion MYSQL_DIR=$targetdir \$MYSQL_CMD_DIR/bin/$i --defaults-file=\$MYSQL_DIR/my.cnf \$@ EOF chmod 755 $targetdir/$i-$targetport ln -s $targetdir/$i-$targetport /usr/local/bin done ### ### patch the my.cnf ### sed -e "s!^server-id.*\$!server-id = $targetport!" \ -e "s!^port.*\$!port = $targetport!" \ -e "s!^socket.*\$!socket = $targetdir/mysql.sock!" < $targetdir/my.cnf > $targetdir/my.cnf.new mv $targetdir/my.cnf.new $targetdir/my.cnf chown -R mysql.mysql $targetdir