Hello
A couple of days ago i was thinking for a way to automate my server instalation process, since i'm one of the few people who "LOVE" to reinstall OS'es on their VPS to see wich one works best.
Then i cameup with the idea of making a bash script, specificaly for Debian 6, so i could just run the script and then wait a couple of seconds 'till the setup finishes...
well...
This is what i got after a few tries:
I think the script is OK but a little confusing... i'm trying to improve it but i felt like it was time to release this now
WARNING!
This script may give a heart attack to someone used to bash scripting, this is my first try on this kind of matter and i REALLY don't know if it's good... i only know that it works
Also
Haven't tried on 64 bits, just 32 bits (blame my vps provider), on Debian 7 it was a mess... but again, blame my vps provider.
#!/bin/bash# InitFILE="/tmp/out.$$"GREP="/bin/grep"#....# Make sure only root can run our scriptif [ "$(id -u)" != "0" ]; then echo "This script must be run as root" 1>&2 exit 1fi#Begginclearecho "Welcome to the"echo "+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+"echo "|H|e|r|c|u|l|e|s| |r|A|t|h|e|n|a|"echo "+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+"echo "Debian 6 Installation Script - By CyDs86"echoecho "Please Select wich emulator do you want to use:"echo "1.- rAthena"echo "2.- Hercules"echoread emulatorna=3if [ "$emulator" -ge "$na" ] then echo "Invalid Selection, aborting" exit elseecho "please input a username for the non-root user that the script will create for the emulator: "read nonrootecho "please enter a name for the folder were i will download the emulator: "read folderread -p "Press [Enter] key to start installation..."clearecho "╔═══════════════════════════════════════════════╗"echo "║Updating distro and downloading necessary files║"echo "╚═══════════════════════════════════════════════╝"# System up-to-dateapt-get update && apt-get -y dist-upgrade # Install all packages we needapt-get install -y git make gcc mysql-server libmysqlclient-dev zlib1g-dev libpcre3-dev screen echo# Add userecho "╔════════════════════════════════════════════╗"echo "║Input the password for the new non root user║"echo "╚════════════════════════════════════════════╝"useradd -m $nonrootpasswd $nonrootclear# Create Databaseechoecho "╔═════════════════════════════════╗"echo "║MySQL User and Databases creation║"echo "╚═════════════════════════════════╝"echoecho -n "Enter the MySQL root password: "read rootpwecho -n "Name for the ragnarok main DB (example: ragnarok_db): "read rodbecho -n "Name for the ragnarok logs DB (example: ragnarok_log): "read rologecho -n "Enter database username (exmaple: ragnarok): "read dbuserecho -n "Enter the password for the database user (example: laliulelo): "read dbupw mysql -u root -p$rootpw -e "CREATE USER '$dbuser'@'localhost' IDENTIFIED BY '$dbupw';"mysql -u root -p$rootpw -e "CREATE DATABASE IF NOT EXISTS $rodb;"mysql -u root -p$rootpw -e "GRANT SELECT,INSERT,UPDATE,DELETE ON $rodb.* TO '$dbuser'@'localhost';"mysql -u root -p$rootpw -e "CREATE DATABASE IF NOT EXISTS $rolog;"mysql -u root -p$rootpw -e "GRANT SELECT,INSERT ON $rolog.* TO '$dbuser'@'localhost';" if [ $? != "0" ]; then echo "[Error]: Database creation failed" exit 1else echo "╔══════════════════════════════════════╗" echo "║Database has been created successfully║" echo "╚══════════════════════════════════════╝" echo " DB Info: " echo "" echo " RO DB : $rodb <--- Ragnarok main DB" echo " Logs DB : $rolog <--- Ragnarok logs DB" echo " DB User : $dbuser <--- can access to both db" echo " DB Pass : $dbupw <--- to access both db" echo "" echo "------------------------------------------"firead -p "Press [Enter] key to continue..."# Test SQL echoecho "Main database test: enter password for the mysql user (not root)"echo "When the MySQL promt appears, type "exit" to end the test"mysql -u $dbuser -p -D $rodbif [ $? != "0" ]; then echo "[Error]: Database creation failed" exit 1elseechoecho "Log database test: enter password for the mysql user (not root)"echo "When the MySQL promt appears, type "exit" to end the test"mysql -u $dbuser -p -D $rologechofiecho "Entering user folder..." cd /home/$nonroot echo "Getting emulator"if [ "$emulator" = 1 ] then git clone https://github.com/rathena/rathena.git /home/$nonroot/$folderelse git clone https://github.com/HerculesWS/Hercules.git /home/$nonroot/$folderficd /home/$nonroot/$folder/sql-filesclearecho "Setting up databases" mysql -u root -p$rootpw $rodb < main.sql mysql -u root -p$rootpw $rodb < item_db.sql mysql -u root -p$rootpw $rodb < item_db2.sql mysql -u root -p$rootpw $rodb < mob_db.sql clear echo "Setting up databases." mysql -u root -p$rootpw $rodb < mob_db2.sql mysql -u root -p$rootpw $rodb < mob_skill_db.sql mysql -u root -p$rootpw $rodb < mob_skill_db2.sql clear echo "Setting up databases.." mysql -u root -p$rootpw $rolog < logs.sql mysql -u root -p$rootpw $rodb < item_db_re.sql mysql -u root -p$rootpw $rodb < item_db2_re.sql clear echo "Setting up databases..." mysql -u root -p$rootpw $rodb < mob_db_re.sql mysql -u root -p$rootpw $rodb < mob_skill_db_re.sqlecho "Giving the non root user $nonroot file ownership"cd /home/$nonrootchown -R $nonroot *clearecho "╔═════════════════════╗"echo "║Installation Finished║"echo "╚═════════════════════╝"echo "Done, don't forget to configure the emulator in the config folder"echo "Your emulator installation is located in /home/$nonroot/$folder"echo "Thanks for using this script! - CyDs86"fiexit
if you have any suggestions please feel free to tell me, even if its something related to take scripting courses or something
Lastly, i decided to release this script here since i like it...
Thanks!
A couple of days ago i was thinking for a way to automate my server instalation process, since i'm one of the few people who "LOVE" to reinstall OS'es on their VPS to see wich one works best.
Then i cameup with the idea of making a bash script, specificaly for Debian 6, so i could just run the script and then wait a couple of seconds 'till the setup finishes...
well...
This is what i got after a few tries:
- Will check if root is running the script
- It will ask you wich kind of server would you like to get: Hercules/rAthena
- it will setup all the tools necessary to run a server (IT WILL NOT COMPILE THE SERVER)
- it will setup and install mysql and databases acording to the options given to the script
I think the script is OK but a little confusing... i'm trying to improve it but i felt like it was time to release this now
WARNING!
This script may give a heart attack to someone used to bash scripting, this is my first try on this kind of matter and i REALLY don't know if it's good... i only know that it works
Also
Haven't tried on 64 bits, just 32 bits (blame my vps provider), on Debian 7 it was a mess... but again, blame my vps provider.
#!/bin/bash# InitFILE="/tmp/out.$$"GREP="/bin/grep"#....# Make sure only root can run our scriptif [ "$(id -u)" != "0" ]; then echo "This script must be run as root" 1>&2 exit 1fi#Begginclearecho "Welcome to the"echo "+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+"echo "|H|e|r|c|u|l|e|s| |r|A|t|h|e|n|a|"echo "+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+"echo "Debian 6 Installation Script - By CyDs86"echoecho "Please Select wich emulator do you want to use:"echo "1.- rAthena"echo "2.- Hercules"echoread emulatorna=3if [ "$emulator" -ge "$na" ] then echo "Invalid Selection, aborting" exit elseecho "please input a username for the non-root user that the script will create for the emulator: "read nonrootecho "please enter a name for the folder were i will download the emulator: "read folderread -p "Press [Enter] key to start installation..."clearecho "╔═══════════════════════════════════════════════╗"echo "║Updating distro and downloading necessary files║"echo "╚═══════════════════════════════════════════════╝"# System up-to-dateapt-get update && apt-get -y dist-upgrade # Install all packages we needapt-get install -y git make gcc mysql-server libmysqlclient-dev zlib1g-dev libpcre3-dev screen echo# Add userecho "╔════════════════════════════════════════════╗"echo "║Input the password for the new non root user║"echo "╚════════════════════════════════════════════╝"useradd -m $nonrootpasswd $nonrootclear# Create Databaseechoecho "╔═════════════════════════════════╗"echo "║MySQL User and Databases creation║"echo "╚═════════════════════════════════╝"echoecho -n "Enter the MySQL root password: "read rootpwecho -n "Name for the ragnarok main DB (example: ragnarok_db): "read rodbecho -n "Name for the ragnarok logs DB (example: ragnarok_log): "read rologecho -n "Enter database username (exmaple: ragnarok): "read dbuserecho -n "Enter the password for the database user (example: laliulelo): "read dbupw mysql -u root -p$rootpw -e "CREATE USER '$dbuser'@'localhost' IDENTIFIED BY '$dbupw';"mysql -u root -p$rootpw -e "CREATE DATABASE IF NOT EXISTS $rodb;"mysql -u root -p$rootpw -e "GRANT SELECT,INSERT,UPDATE,DELETE ON $rodb.* TO '$dbuser'@'localhost';"mysql -u root -p$rootpw -e "CREATE DATABASE IF NOT EXISTS $rolog;"mysql -u root -p$rootpw -e "GRANT SELECT,INSERT ON $rolog.* TO '$dbuser'@'localhost';" if [ $? != "0" ]; then echo "[Error]: Database creation failed" exit 1else echo "╔══════════════════════════════════════╗" echo "║Database has been created successfully║" echo "╚══════════════════════════════════════╝" echo " DB Info: " echo "" echo " RO DB : $rodb <--- Ragnarok main DB" echo " Logs DB : $rolog <--- Ragnarok logs DB" echo " DB User : $dbuser <--- can access to both db" echo " DB Pass : $dbupw <--- to access both db" echo "" echo "------------------------------------------"firead -p "Press [Enter] key to continue..."# Test SQL echoecho "Main database test: enter password for the mysql user (not root)"echo "When the MySQL promt appears, type "exit" to end the test"mysql -u $dbuser -p -D $rodbif [ $? != "0" ]; then echo "[Error]: Database creation failed" exit 1elseechoecho "Log database test: enter password for the mysql user (not root)"echo "When the MySQL promt appears, type "exit" to end the test"mysql -u $dbuser -p -D $rologechofiecho "Entering user folder..." cd /home/$nonroot echo "Getting emulator"if [ "$emulator" = 1 ] then git clone https://github.com/rathena/rathena.git /home/$nonroot/$folderelse git clone https://github.com/HerculesWS/Hercules.git /home/$nonroot/$folderficd /home/$nonroot/$folder/sql-filesclearecho "Setting up databases" mysql -u root -p$rootpw $rodb < main.sql mysql -u root -p$rootpw $rodb < item_db.sql mysql -u root -p$rootpw $rodb < item_db2.sql mysql -u root -p$rootpw $rodb < mob_db.sql clear echo "Setting up databases." mysql -u root -p$rootpw $rodb < mob_db2.sql mysql -u root -p$rootpw $rodb < mob_skill_db.sql mysql -u root -p$rootpw $rodb < mob_skill_db2.sql clear echo "Setting up databases.." mysql -u root -p$rootpw $rolog < logs.sql mysql -u root -p$rootpw $rodb < item_db_re.sql mysql -u root -p$rootpw $rodb < item_db2_re.sql clear echo "Setting up databases..." mysql -u root -p$rootpw $rodb < mob_db_re.sql mysql -u root -p$rootpw $rodb < mob_skill_db_re.sqlecho "Giving the non root user $nonroot file ownership"cd /home/$nonrootchown -R $nonroot *clearecho "╔═════════════════════╗"echo "║Installation Finished║"echo "╚═════════════════════╝"echo "Done, don't forget to configure the emulator in the config folder"echo "Your emulator installation is located in /home/$nonroot/$folder"echo "Thanks for using this script! - CyDs86"fiexit
if you have any suggestions please feel free to tell me, even if its something related to take scripting courses or something
Lastly, i decided to release this script here since i like it...
Thanks!
Last edited by a moderator: