[1] | 1 | #!/bin/bash
|
---|
| 2 |
|
---|
| 3 | INSTALLOPTIONALDEPS=0
|
---|
| 4 | ADDCRONJOBS=0
|
---|
| 5 | RUNINSTALL=0
|
---|
| 6 |
|
---|
[7] | 7 | DEPENDENCIES="xvfb mono-runtime rsync libxml2-utils"
|
---|
[1] | 8 | OPTDEPENDENCIES="sendemail sendxmpp"
|
---|
| 9 |
|
---|
| 10 | if [ -n "$(command -v apt-get)" ]; then
|
---|
| 11 | ISDEBIAN=1
|
---|
| 12 | else
|
---|
| 13 | ISDEBIAN=0
|
---|
| 14 | fi
|
---|
| 15 |
|
---|
| 16 | if [ $(uname -m) == 'x86_64' ]; then
|
---|
| 17 | IS64BIT=1
|
---|
| 18 | else
|
---|
| 19 | IS64BIT=0
|
---|
| 20 | fi
|
---|
| 21 |
|
---|
| 22 | if [[ $IS64BIT == 1 ]]; then
|
---|
| 23 | DEPENDENCIES="$DEPENDENCIES lib32gcc1 wine:i386"
|
---|
| 24 | else
|
---|
| 25 | DEPENDENCIES="$DEPENDENCIES wine"
|
---|
| 26 | fi
|
---|
| 27 |
|
---|
| 28 | showHelp() {
|
---|
| 29 | echo "Usage: ./bootstrap.sh [-h] [-o] [-c] -i"
|
---|
| 30 | echo "Parameters:"
|
---|
| 31 | echo " -h Print this help screen and exit"
|
---|
| 32 | echo " -o Install optional dependencies ($OPTDEPENDENCIES)"
|
---|
| 33 | echo " -c Add cron jobs for save backups and memory checking"
|
---|
| 34 | echo " -i Required to actually start the installation"
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | intro() {
|
---|
| 38 | echo
|
---|
| 39 | echo "7DtD Linux dedicated server bootstrapper"
|
---|
| 40 | echo
|
---|
| 41 | echo "This will install a 7DtD server according to the information"
|
---|
| 42 | echo "given on:"
|
---|
| 43 | echo " http://7daystodie.gamepedia.com/Linux_Server"
|
---|
| 44 | echo
|
---|
| 45 | read -p "Press enter to continue"
|
---|
| 46 | echo -e "\n=============================================================\n\n"
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | nonDebianWarning() {
|
---|
| 50 | if [[ $ISDEBIAN == 0 ]]; then
|
---|
| 51 | echo "NOTE: It seems like this system is not based on Debian."
|
---|
| 52 | echo "Although installation of the scripts and SteamCMD/7dtd"
|
---|
| 53 | echo "will work the installed management scripts will probably"
|
---|
| 54 | echo "*NOT* work out of the box and installation of dependencies"
|
---|
| 55 | echo "will fail too."
|
---|
| 56 | echo "Do you want to continue anyway?"
|
---|
| 57 | select yn in "Yes" "No"; do
|
---|
| 58 | case $yn in
|
---|
| 59 | Yes)
|
---|
| 60 | echo "Continuing..."
|
---|
| 61 | break;;
|
---|
| 62 | No)
|
---|
| 63 | echo "Aborting."
|
---|
| 64 | exit 0
|
---|
| 65 | ;;
|
---|
| 66 | esac
|
---|
| 67 | done
|
---|
| 68 | echo -e "\n=============================================================\n\n"
|
---|
| 69 | fi
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | installAptDeps() {
|
---|
| 73 | echo -e "Installing dependencies\n"
|
---|
| 74 | if [[ $IS64BIT == 1 ]]; then
|
---|
| 75 | dpkg --add-architecture i386
|
---|
| 76 | fi
|
---|
| 77 | apt-get update
|
---|
| 78 | apt-get install $DEPENDENCIES
|
---|
| 79 | echo -e "\n=============================================================\n\n"
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | installOptionalDeps() {
|
---|
| 83 | echo -e "Installing optional dependencies\n"
|
---|
| 84 | apt-get install $OPTDEPENDENCIES
|
---|
| 85 | echo -e "\n=============================================================\n\n"
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | setupUser() {
|
---|
| 89 | echo -e "Setting up user and group \"sdtd\"\n"
|
---|
| 90 | useradd -d /home/sdtd -m -r -s /bin/bash -U sdtd
|
---|
| 91 | echo -e "\n=============================================================\n\n"
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | installManagementScripts() {
|
---|
| 95 | echo -e "Downloading and installing management scripts\n"
|
---|
| 96 | wget -nv http://illy.bz/fi/7dtd/management_scripts.tar.gz -O /tmp/management_scripts.tar.gz
|
---|
| 97 | tar -xzf /tmp/management_scripts.tar.gz --no-same-owner --owner=root --group=root -C /
|
---|
| 98 | chmod go-rwx /etc/7dtd.conf
|
---|
| 99 | chmod +x /etc/init.d/7dtd.sh
|
---|
| 100 | chmod +x /usr/local/bin/7dtd-*
|
---|
| 101 | if [[ $ISDEBIAN == 1 ]]; then
|
---|
| 102 | update-rc.d 7dtd.sh defaults
|
---|
| 103 | fi
|
---|
| 104 | echo -e "\n=============================================================\n\n"
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | setSteamLoginData() {
|
---|
| 108 | echo -e "Steam account data\n"
|
---|
| 109 | echo "Please enter your Steam login data for SteamCMD to get the 7dtd-server files:"
|
---|
| 110 | read -p "Steam username: " username
|
---|
| 111 | read -s -p "Steam password: " password
|
---|
| 112 | sed -i "s/export STEAM_USER=/export STEAM_USER=$username/" /etc/7dtd.conf
|
---|
| 113 | sed -i "s/export STEAM_PASS=/export STEAM_PASS=$password/" /etc/7dtd.conf
|
---|
| 114 | echo -e "\n=============================================================\n\n"
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | installSteamCmdAndSDTD() {
|
---|
| 118 | echo -e "Installing SteamCMD and 7DtD\n"
|
---|
| 119 | 7dtd-update.sh
|
---|
| 120 | cp -p /home/sdtd/7dtd/serverconfig.xml /home/sdtd/
|
---|
| 121 | echo -e "\n=============================================================\n\n"
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | setupServerConfig() {
|
---|
| 125 | echo -e "Setting up basic 7DtD server config\n"
|
---|
| 126 |
|
---|
| 127 | until [[ $public == "y" || $public == "n" ]]; do
|
---|
| 128 | read -p "Should the server be public [yn]? " public
|
---|
| 129 | done
|
---|
| 130 | if [[ "$public" == "y" ]]; then public=true; else public=false; fi
|
---|
| 131 | echo
|
---|
| 132 |
|
---|
| 133 | read -p "Server name: " servername
|
---|
| 134 | echo
|
---|
| 135 | read -p "Server password (empty for none): " serverpassword
|
---|
| 136 | echo
|
---|
| 137 |
|
---|
| 138 | echo "Select world to play on:"
|
---|
| 139 | select worldname in "Navezgane" "MP Forest Horde" "MP Forest Skirmish" "MP Wasteland Horde" "MP Wasteland Skirmish" "MP Wasteland War"; do
|
---|
| 140 | if [[ -n $worldname ]]; then
|
---|
| 141 | break
|
---|
| 142 | fi
|
---|
| 143 | done
|
---|
| 144 | echo
|
---|
| 145 |
|
---|
| 146 | echo "Select game mode:"
|
---|
| 147 | select gamemode in "GameModeSurvival" "GameModeZombieHorde" "GameModeDeathmatch"; do
|
---|
| 148 | if [[ -n $gamemode ]]; then
|
---|
| 149 | break
|
---|
| 150 | fi
|
---|
| 151 | done
|
---|
| 152 | echo
|
---|
| 153 |
|
---|
| 154 | read -p "Game name: " gamename
|
---|
| 155 | echo
|
---|
| 156 | read -p "Difficulty (0-4): " difficulty
|
---|
| 157 | echo
|
---|
| 158 |
|
---|
| 159 | sed -i "s/name=\"ServerIsPublic\".*value=\"[^\"]*\"/name=\"ServerIsPublic\" value=\"$public\"/" /home/sdtd/serverconfig.xml
|
---|
| 160 | sed -i "s/name=\"ServerName\".*value=\"[^\"]*\"/name=\"ServerName\" value=\"$servername\"/" /home/sdtd/serverconfig.xml
|
---|
| 161 | sed -i "s/name=\"ServerPassword\".*value=\"[^\"]*\"/name=\"ServerPassword\" value=\"$serverpassword\"/" /home/sdtd/serverconfig.xml
|
---|
| 162 | sed -i "s/name=\"GameWorld\".*value=\"[^\"]*\"/name=\"GameWorld\" value=\"$worldname\"/" /home/sdtd/serverconfig.xml
|
---|
| 163 | sed -i "s/name=\"GameName\".*value=\"[^\"]*\"/name=\"GameName\" value=\"$gamename\"/" /home/sdtd/serverconfig.xml
|
---|
| 164 | sed -i "s/name=\"GameDifficulty\".*value=\"[^\"]*\"/name=\"GameDifficulty\" value=\"$difficulty\"/" /home/sdtd/serverconfig.xml
|
---|
| 165 | sed -i "s/name=\"GameMode\".*value=\"[^\"]*\"/name=\"GameMode\" value=\"$gamemode\"/" /home/sdtd/serverconfig.xml
|
---|
| 166 | sed -i "s/name=\"TelnetPort\".*value=\"[^\"]*\"/name=\"TelnetPort\" value=\"25003\"/" /home/sdtd/serverconfig.xml
|
---|
| 167 |
|
---|
| 168 | echo -e "\n=============================================================\n\n"
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | addCronJobs() {
|
---|
| 172 | echo -e "Adding cron jobs\n"
|
---|
| 173 |
|
---|
| 174 | echo -e "By default a backup of the save folder will be created once"
|
---|
| 175 | echo -e " per hour. This can be changed in /etc/cron.d/7dtd-backup."
|
---|
| 176 | echo -e "Memory monitor will be run every five minutes by default."
|
---|
| 177 | echo -e " This can be changed in /etc/cron.d/7dtd-check_mem."
|
---|
| 178 |
|
---|
| 179 | echo "0 * * * * root /usr/local/bin/7dtd-backup.sh" > /etc/cron.d/7dtd-backup
|
---|
| 180 | echo "*/5 * * * * root /usr/local/bin/7dtd-check_mem.sh" > /etc/cron.d/7dtd-check_mem
|
---|
| 181 |
|
---|
| 182 | echo -e "\nNOTE: Do not forget to edit /etc/7dtd.conf to match\nyour notification needs!"
|
---|
| 183 | echo -e "\n=============================================================\n\n"
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | finish() {
|
---|
| 187 | echo -e "\n ALL DONE\n"
|
---|
| 188 | echo -e "You should now be able to start your 7dtd server by running\n"
|
---|
| 189 | echo -e " 7dtd-start.sh\n"
|
---|
| 190 | echo
|
---|
| 191 | echo -e "For further configuration options check:"
|
---|
| 192 | echo -e " /etc/7dtd.conf"
|
---|
| 193 | echo -e " /home/sdtd/serverconfig.xml"
|
---|
| 194 | echo
|
---|
| 195 | echo -e "For feedback, suggestions, problems please visit the forum:"
|
---|
| 196 | echo -e " http://7daystodie.com/forums/showthread.php?2188"
|
---|
| 197 | echo
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 | main() {
|
---|
| 201 | intro
|
---|
| 202 | nonDebianWarning
|
---|
| 203 |
|
---|
| 204 | if [[ $ISDEBIAN == 1 ]]; then
|
---|
| 205 | installAptDeps
|
---|
| 206 | if [[ $INSTALLOPTIONALDEPS == 1 ]]; then
|
---|
| 207 | installOptionalDeps
|
---|
| 208 | echo
|
---|
| 209 | fi
|
---|
| 210 | fi
|
---|
| 211 | setupUser
|
---|
| 212 | installManagementScripts
|
---|
| 213 | setSteamLoginData
|
---|
| 214 | installSteamCmdAndSDTD
|
---|
| 215 | if [[ $ADDCRONJOBS == 1 ]]; then
|
---|
| 216 | addCronJobs
|
---|
| 217 | fi
|
---|
| 218 | setupServerConfig
|
---|
| 219 | finish
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | if [[ -z $1 ]]; then
|
---|
| 223 | showHelp
|
---|
| 224 | exit 0
|
---|
| 225 | fi
|
---|
| 226 | while getopts "hcoi" opt; do
|
---|
| 227 | case "$opt" in
|
---|
| 228 | h)
|
---|
| 229 | showHelp
|
---|
| 230 | exit 0
|
---|
| 231 | ;;
|
---|
| 232 | c)
|
---|
| 233 | ADDCRONJOBS=1
|
---|
| 234 | ;;
|
---|
| 235 | o)
|
---|
| 236 | INSTALLOPTIONALDEPS=1
|
---|
| 237 | ;;
|
---|
| 238 | i)
|
---|
| 239 | RUNINSTALL=1
|
---|
| 240 | ;;
|
---|
| 241 | esac
|
---|
| 242 | done
|
---|
| 243 | if [[ $RUNINSTALL == 1 ]]; then
|
---|
| 244 | main
|
---|
| 245 | fi
|
---|
| 246 |
|
---|