Debian 6 Autoinstaller

cyds86

New member
Messages
3
Points
0
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:

  • 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
default_smile.png


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
default_smile.png


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
default_smile.png


Lastly, i decided to release this script here since i like it...

Thanks!
 

 
Last edited by a moderator:
I translated it to CentOS and fixed some errors, also i added an "Alert" at the final stage of the script to tell the user it has already finished doing its duty.

#!/bin/bash# Init FILE="/tmp/out.$$" GREP="/bin/grep"#....# Make sure only root can run our script if [ "$(id -u)" != "0" ]; then echo "This script must be run as root" 1>&2 exit 1 fi# Script start clear echo "Welcome to the CentOS" echo "+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+" echo "|H|e|r|c|u|l|e|s| |r|A|t|h|e|n|a|" echo "+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+" echo " Installation Script | By CyDs86 - Josevill" echo echo "Please select which emulator you wish to use:" echo "1.- rAthena" echo "2.- Hercules" echo read emulator na=3 if [ "$emulator" -ge "$na" ] then echo "Invalid Selection, aborting!" exit else echo "Please input an username for the non-root user this script will create for running and managing the emulator: " read nonroot echo "Please enter the name of the folder in home-dir (main directory) where the emulator will be downloaded: " read folder read -p "Press [Enter] key to start installation..." clear echo "╔═══════════════════════════════════════════════╗" echo "║Updating distro and downloading necessary files║" echo "╚═══════════════════════════════════════════════╝"# System updating yum update -y # Installin emulator dependancies yum install -y git make gcc mysql mysql-server mysql-devel zlib-devel pcre-devel screen service mysqld start chkconfig mysqld on echo read -p "Press [Enter] key to continue..." clear# Creating the user that will manage the emulator echo "╔════════════════════════════════════════════╗" echo "║Input the password for the new non root user║" echo "╚════════════════════════════════════════════╝" useradd -m -s /bin/bash $nonroot passwd $nonroot clear# Giving MySQL Root user a Password and Creating Databases echo echo "╔═════════════════════════════════╗" echo "║MySQL User and Databases creation║" echo "╚═════════════════════════════════╝" echo echo -n "Enter the MySQL root password: " read rootpw mysqladmin -u root password $rootpw clear echo -n "Name for the ragnarok main DB (example: ragnarok_db): " read rodb echo -n "Name for the ragnarok logs DB (example: ragnarok_log): " read rolog echo -n "Enter database user name (example: ro_user): " read dbuser echo -n "Enter the password for the database user (example: laliulelo): " read dbupw clear echo "Please, re-enter root passwd for MySQL" read rootpw2 mysql -u root -p$rootpw2 -e "CREATE USER '$dbuser'@'localhost' IDENTIFIED BY '$dbupw';" mysql -u root -p$rootpw2 -e "CREATE DATABASE IF NOT EXISTS $rodb;" mysql -u root -p$rootpw2 -e "GRANT SELECT,INSERT,UPDATE,DELETE ON $rodb.* TO '$dbuser'@'localhost';" mysql -u root -p$rootpw2 -e "CREATE DATABASE IF NOT EXISTS $rolog;" mysql -u root -p$rootpw2 -e "GRANT SELECT,INSERT ON $rolog.* TO '$dbuser'@'localhost';" if [ $? != "0" ]; then echo "[Error]: Database / User creation failed" exit 1 else echo "╔══════════════════════════════════════════╗" echo "║ Databases have been created successfully ║" echo "╚══════════════════════════════════════════╝" echo " DB Info: " echo "" echo " ROOT PW: $rootpw2 <-- Save this pw in a safe place" 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 " -------------------------------------------------------" echo "| Remember this user has been created to work locally, |" echo "| if you need to access your data remotely, you will |" echo "| need to create a new user with 'remote host' to do so.|" echo " -------------------------------------------------------" fi read -p "Press [Enter] key to continue..."# Testing SQL echo echo "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 $rodb if [ $? != "0" ]; then echo "[Error]: Database connection failed" exit 1 else echo echo "Logs 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 $rolog echo fi echo "Entering user's folder..." cd /home/$nonroot read -p "Press [Enter] key to continue..." clear echo "Downloading emulator" if [ "$emulator" = 1 ] then git clone https://github.com/rathena/rathena.git /home/$nonroot/$folder else git clone https://github.com/HerculesWS/Hercules.git /home/$nonroot/$folder fi cd /home/$nonroot/$folder/sql-files clear echo "The following database proccedure will require your ROOT MySQL passwd." read -p "Press [Enter] key to continue..." clear echo "Setting up databases" echo "Please, re-enter root passwd for MySQL" read rootpw3 mysql -u root -p$rootpw3 $rodb < main.sql mysql -u root -p$rootpw3 $rodb < item_db.sql mysql -u root -p$rootpw3 $rodb < item_db2.sql mysql -u root -p$rootpw3 $rodb < mob_db.sql mysql -u root -p$rootpw3 $rodb < mob_db2.sql mysql -u root -p$rootpw3 $rodb < mob_skill_db.sql mysql -u root -p$rootpw3 $rodb < mob_skill_db2.sql mysql -u root -p$rootpw3 $rolog < logs.sql mysql -u root -p$rootpw3 $rodb < item_db_re.sql mysql -u root -p$rootpw3 $rodb < mob_db_re.sql mysql -u root -p$rootpw3 $rodb < mob_skill_db_re.sql read -p "Press [Enter] key to continue..." clear echo "Giving $nonroot emulator's ownership" cd /home/$nonroot chown -R $nonroot * read -p "Press [Enter] key to continue..." clear echo "╔══════════════════════╗" echo "║Installation Finished.║" echo "╚══════════════════════╝" echo echo "Please 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" echo -e "CentOS translation and Typos by Josevilla" fi exitEdit: I've been tweaking this script a little more, will post it later in the afternoon, 3:40am right now. Later!
Edit 2: Ok, it's done. Now the script step-by-step will:

[*]Asks which eA based emulator will the user install.

[*]Creates an user to be used for server-only purposes (Running, editing, compiling, updating).

[*]Update your system and install Hercules/rAthena dependancies. (It also does download screen for those who know how to use it.)

[*]Start MySQL Daemon and set it to start every time the VPS/Dedicated Server restarts.

[*]Give the new user a password.

[*]Creates a MySQL Root Password.

[*]Create databases for Ragnarok's Main tables and Log Tables.

[*]Creates a dedicated ragnarok user and passwd.

[*]Download the selected emulator.

[*]Install SQL Data.

[*]Gives the new user rights on the emulator's folder.

[*]Finish.

 
Last edited by a moderator:
I translated it to CentOS and fixed some errors, also i added an "Alert" at the final stage of the script to tell the user it has already finished doing its duty.
Thanks M8, i might add those new features to the script (if you don't mind, of course) and maybe merge it to be able to detect wich OS is running and do the installation a breeze.

Also, i noticed that i don't know what will happen if i use "0" in the emulator selection question... might try it once my pc its fixed (OC stuff :/ )

Thanks for the feedback!

 
Neat script - however it's out dated and yeah, no x64-support.
Also it seems to be wrapped in one line -> makes it super hard to read.

 
Back
Top