viewing paste CentOS Hercules/rAthena Installer | Bash

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
#!/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
        echo
        echo "You will be prompted to enter a password, just click intro and carry on with the rest of the script."
        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 username (example: ragnarok): "
        read dbuser
        echo -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 / User creation failed"
                exit 1
                else
        echo "╔════════════════════════════════════════╗"
        echo "║Databases have been created successfully║"
        echo "╚════════════════════════════════════════╝"
        echo " DB Info: "
        echo ""
        echo " ROOT PW: $rootpw <-- 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"
        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.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 Josevill\a"
        fi
        exit
Viewed 1192 times, submitted by unknown.