#!/bin/bash trap finish 2 configure() { echo "#############################################" echo "# You entered script configuration area #" echo "# No change will be performed in your DB #" echo "# I will just ask you some questions about #" echo "# your hosts and DB. #" echo "#############################################" MYSQLDUMPPATH=`which -a mysqldump 2>/dev/null` MYSQLPATH=`which -a mysql 2>/dev/null` if [ $? -ne 0 ]; then echo "We were unable to find MySQL binaries on your path" while : do echo -ne "\nPlease enter MySQL binaries directory (no trailing slash): " read MYSQLBINPATH if [ -e "$MYSQLBINPATH" ] && [ -d "$MYSQLBINPATH" ] && \ [ -e "$MYSQLBINPATH/mysqldump" ] && [ -e "$MYSQLBINPATH/mysql" ]; then MYSQLDUMPPATH="$MYSQLBINPATH/mysqldump" MYSQLPATH="$MYSQLBINPATH/mysql" break else echo "The data you entered is invalid. Please verify and try again." exit 1 fi done fi #LS echo -ne "\nPlease enter MySQL Login Server hostname (default localhost): " read LSDBHOST if [ -z "$LSDBHOST" ]; then LSDBHOST="localhost" fi echo -ne "\nPlease enter MySQL Login Server database name (default lineage2): " read LSDB if [ -z "$LSDB" ]; then LSDB="lineage2" fi echo -ne "\nPlease enter MySQL Login Server user (default root): " read LSUSER if [ -z "$LSUSER" ]; then LSUSER="root" fi echo -ne "\nPlease enter MySQL Login Server $LSUSER's password (won't be displayed) :" stty -echo read LSPASS stty echo echo "" if [ -z "$LSPASS" ]; then echo "Hum.. I'll let it be but don't be stupid and avoid empty passwords" elif [ "$LSUSER" == "$LSPASS" ]; then echo "You're not too brilliant choosing passwords huh?" fi #GS echo -ne "\nPlease enter MySQL Game Server hostname (default $LSDBHOST): " read GSDBHOST if [ -z "$GSDBHOST" ]; then GSDBHOST="localhost" fi echo -ne "\nPlease enter MySQL Game Server database name (default l2jgs): " read GSDB if [ -z "$GSDB" ]; then GSDB="lineage2" fi echo -ne "\nPlease enter MySQL Game Server user (default $LSUSER): " read GSUSER if [ -z "$GSUSER" ]; then GSUSER="root" fi echo -ne "\nPlease enter MySQL Game Server $GSUSER's password (won't be displayed): " stty -echo read GSPASS stty echo echo "" if [ -z "$GSPASS" ]; then echo "Hum.. I'll let it be but don't be stupid and avoid empty passwords" elif [ "$GSUSER" == "$GSPASS" ]; then echo "You're not too brilliant choosing passwords huh?" fi save_config $1 } save_config() { if [ -n "$1" ]; then CONF="$1" else CONF="database_installer.rc" fi echo "" echo "With these data I can generate a configuration file which can be read" echo "on future updates. WARNING: this file will contain clear text passwords!" echo -ne "Shall I generate config file $CONF? (Y/n):" read SAVE if [ "$SAVE" == "y" -o "$SAVE" == "Y" -o "$SAVE" == "" ];then cat <$CONF #Configuration settings for L2J-Datapack database installer script MYSQLDUMPPATH=$MYSQLDUMPPATH MYSQLPATH=$MYSQLPATH LSDBHOST=$LSDBHOST LSDB=$LSDB LSUSER=$LSUSER LSPASS=$LSPASS GSDBHOST=$GSDBHOST GSDB=$GSDB GSUSER=$GSUSER GSPASS=$GSPASS EOF chmod 600 $CONF echo "Configuration saved as $CONF" echo "Permissions changed to 600 (rw- --- ---)" elif [ "$SAVE" != "n" -a "$SAVE" != "N" ]; then save_config fi } load_config() { if [ -n "$1" ]; then CONF="$1" else CONF="database_installer.rc" fi if [ -e "$CONF" ] && [ -f "$CONF" ]; then . $CONF else echo "Settings file not found: $CONF" echo "You can specify an alternate settings filename:" echo $0 config_filename echo "" echo "If file doesn't exist it can be created" echo "If nothing is specified script will try to work with ./database_installer.rc" echo "" configure $CONF fi } asklogin(){ clear echo "#############################################" echo "# WARNING: This section of the script CAN #" echo "# destroy your characters and accounts #" echo "# information. Read questions carefully #" echo "# before you reply. #" echo "#############################################" echo "" echo "Choose full (f) if you don't have and 'accounts' table or would" echo "prefer to erase the existing accounts information." echo "Choose skip (s) to skip loginserver DB installation and go to" echo "gameserver DB installation/upgrade." echo -ne "LOGINSERVER DB install type: (f) full, (s) skip or (q) quit? " read LOGINPROMPT case "$LOGINPROMPT" in "f"|"F") logininstall; loginupgrade;; "s"|"S") gsbackup;; "q"|"Q") finish;; *) asklogin;; esac } logininstall(){ echo "Deleting loginserver tables for new content." $MYL < ls_cleanup.sql } loginupgrade(){ clear echo "Installling new loginserver content." for login in $(ls ./sql/login/*.sql);do echo "Installing loginserver table : $login" $MYL < $login done gsbackup } gsbackup(){ while : do echo "" echo -ne "Do you want to make a backup copy of your GSDB? (y/n): " read LSB if [ "$LSB" == "Y" -o "$LSB" == "y" ]; then echo "Making a backup of the original gameserver database." $MYSQLDUMPPATH --add-drop-table -h $GSDBHOST -u $GSUSER --password=$GSPASS $GSDB > gs_backup.sql if [ $? -ne 0 ];then clear echo "" echo "There was a problem accesing your GS database, either it wasnt created or authentication data is incorrect." exit 1 fi break elif [ "$LSB" == "n" -o "$LSB" == "N" ]; then break fi done asktype } lsbackup(){ while : do clear echo "" echo -ne "Do you want to make a backup copy of your LSDB? (y/n): " read LSB if [ "$LSB" == "Y" -o "$LSB" == "y" ]; then echo "Making a backup of the original loginserver database." $MYSQLDUMPPATH --add-drop-table -h $LSDBHOST -u $LSUSER --password=$LSPASS $LSDB > ls_backup.sql if [ $? -ne 0 ];then clear echo "" echo "There was a problem accesing your LS database, either it wasnt created or authentication data is incorrect." exit 1 fi break elif [ "$LSB" == "n" -o "$LSB" == "N" ]; then break fi done } asktype(){ echo "" echo "" echo "WARNING: A full install (f) will destroy all existing character data." echo -ne "GAMESERVER DB install type: (f) full install, (u) upgrade or (q) quit? " read INSTALLTYPE case "$INSTALLTYPE" in "f"|"F") fullinstall; upgradeinstall I;; "u"|"U") upgradeinstall U;; "q"|"Q") finish;; *) asktype;; esac } fullinstall(){ clear echo "Deleting all gameserver tables for new content." $MYG < gs_cleanup.sql } upgradeinstall(){ clear if [ "$1" == "I" ]; then echo "Installling new gameserver content." else echo "Upgrading gameserver content" fi for gs in $(ls ./sql/server/*.sql);do echo "Installing GameServer table : $gs" $MYG < $gs done finish } finish(){ clear echo "Script execution finished." echo "" exit 0 } clear load_config $1 MYL="$MYSQLPATH -h $LSDBHOST -u $LSUSER --password=$LSPASS -D $LSDB" MYG="$MYSQLPATH -h $GSDBHOST -u $GSUSER --password=$GSPASS -D $GSDB" lsbackup asklogin