SHARE
TWEET

slackin

a guest Jul 17th, 2011 157 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. #----------------------------------------------------------------------------|
  3. #    This program is free software: you can redistribute it and/or modify    |
  4. #    it under the terms of the GNU General Public License as published by    |
  5. #    the Free Software Foundation, either version 3 of the License, or       |
  6. #    (at your option) any later version.                                     |
  7. #                                                                            |
  8. #    This program is distributed in the hope that it will be useful,         |
  9. #    but WITHOUT ANY WARRANTY; without even the implied warranty of          |
  10. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
  11. #    GNU General Public License for more details.                            |
  12. #                                                                            |
  13. #    You should have received a copy of the GNU General Public License       |
  14. #    along with this program.  If not, see <http://www.gnu.org/licenses/>.   |
  15. #----------------------------------------------------------------------------|
  16.  
  17. #----------------------------------------------------------------------------|
  18. # slackin's UrT dedicated server install script!       Version: 0.1          |
  19. # Justin Clark -- slackin35@yahoo.com                                        |
  20. # slackin35 on AIM                                                           |
  21. #                                                                            |
  22. # See the bottom of the script for more information.                         |
  23. #----------------------------------------------------------------------------|
  24.  
  25. ### PLEASE EDIT! #############################################################
  26. # source_dir should be the directory where the folder UrbanTerror            #
  27. # is located. ie, if UrbanTerror is /usr/local/games/UrbanTerror             #
  28. # then you would put: source_dir="/usr/local/games/"                         #
  29. #                                                                            #
  30.  
  31. source_dir="/home/real_template/"
  32.  
  33. #                                                                            #
  34. # That concludes the inscript config!                                        #
  35. #                                                                            #
  36. ### END EDIT! ################################################################
  37.  
  38.  
  39.  
  40. # Read the username from stdin
  41. function get_user {
  42.        
  43.         # Ask user what user account to install to, and read reply into varible user
  44.         color_echo "yellow" "Please enter username:"
  45.         read user
  46. }
  47.  
  48. # Read the port from stdin
  49. function get_port {
  50.  
  51.         # Ask user what port to use for this server, and read reply into varible port
  52.         color_echo "yellow" "Please enter port:"
  53.         read port
  54. }
  55.  
  56. # Color echo function, for using echo with colors in bash, syntax: color_echo "color_name" "message to send"
  57. function color_echo {
  58.  
  59.         # Case statement to set ascii color code from named color
  60.         case "$1" in
  61.                 "blue" )
  62.                         color="\e[32m"
  63.                         ;;
  64.                 "red" )
  65.                         color="\e[31m"
  66.                         ;;
  67.                 "yellow" )
  68.                         color="\e[33m"
  69.                         ;;
  70.                 "green" )
  71.                         color="\e[34m"
  72.                         ;;
  73.         esac
  74.        
  75.         # Do the actual echo, note the -e to use the escape codes
  76.         # and notice the color reset at the end, always use that.
  77.         echo -e "${color}${2}\e[0m"
  78. }
  79.  
  80. # Install all the maps listed in the maplist file without prompting.
  81. function map_install_all {
  82.         color_echo "green" "Installing all maps"
  83.        
  84.         # Link each map listed in map filelist
  85.         for filename in $map_filelist
  86.         do
  87.                 if ln -s ${source_dir}${filename} ${user_dir}/UrbanTerror/q3ut4 ; then
  88.                         color_echo "green" "File linked: ${user_dir}/${filename}" ; else
  89.  
  90.                         # if link fails, produce error and exit program
  91.                         color_echo "red" "File link FAILED: ${user_dir}/${filename}"
  92.                         exit
  93.                 fi
  94.         done   
  95. }
  96.  
  97. # Install all the maps listen in maplist file and prompt for each map.
  98. function map_install_yes {
  99.         color_echo "green" "Selecting maps one by one"
  100.        
  101.         # Link each map listed, prompting first.
  102.         for filename in $map_filelist
  103.         do
  104.        
  105.                 # Ask user if he want to copy this map, then read his reply.
  106.                 color_echo "green" "Link map: ${filename}  (y)es / (n)o"
  107.                 read yeno
  108.                
  109.                 # if replied "y" then link the map.
  110.                 if [ $yeno == "y" ] ; then
  111.                         if ln -s ${source_dir}${filename} ${user_dir}/UrbanTerror/q3ut4 ; then
  112.                                 color_echo "green" "File linked: ${user_dir}/${filename}" ; else
  113.  
  114.                                 # if link fails, produce error and exit program
  115.                                 color_echo "red" "File link FAILED: ${user_dir}/${filename}"
  116.                                 exit
  117.                         fi
  118.                 fi
  119.         done   
  120. }
  121.  
  122. # Start of install script
  123. function run_install {
  124.         color_echo "green" "slackin's Urban Terror server install script!"
  125.        
  126.         # Load the used ports list, to make sure we don't use the same port twice!
  127.         . used_ports
  128.        
  129.         # Check to see if the username was given at run time.
  130.         if [ -z $user ] ; then
  131.                 get_user
  132.         fi
  133.        
  134.         # Run loop until a valid username is given.
  135.         while [ -z $user_valid ]
  136.         do
  137.                 color_echo "green" "Checking user directory."
  138.                
  139.                 # Check to see if the user name given has a home directory.
  140.                 if [ -e "/home/${user}" ] ; then
  141.                
  142.                         # if user directory exists, set variable so while loop stops.
  143.                         color_echo "blue" "User directory valid!"
  144.                         user_valid="TRUE"
  145.                         user_dir="/home/${user}" ; else
  146.                        
  147.                         # if invalid, return error.
  148.                         color_echo "red" "User directory invalid!"
  149.  
  150.                         # Run user prompt
  151.                         get_user
  152.                 fi
  153.         done
  154.        
  155.         # Run loop until a valid port is given
  156.         while [ -z $port_valid ]
  157.         do
  158.                 color_echo "green" "Checking port."
  159.                
  160.                 # Check to make sure port is within sane range, 1024 < port < 65535
  161.                 # if port is not within that range, return port invalid and return to port prompt
  162.                 if [[ $port -gt "1024" && $port -lt 65535 ]] ; then
  163.                        
  164.                         # Case, if $port is in $port_list return taken and return to port prompt
  165.                         # if not found, default, Tell them port is good.
  166.                         case $port_list in
  167.                                 *"${port}"* )
  168.                                         color_echo "red" "Port taken! Try another."
  169.                                        
  170.                                         # Run port prompt
  171.                                         get_port
  172.                                         ;;
  173.                                 * )
  174.                                         port_valid="TRUE"
  175.                                         color_echo "blue" "Port valid!"
  176.                                         ;;
  177.                         esac ; else
  178.                         color_echo "red" "Port invalid!"
  179.  
  180.                         # Run port prompt
  181.                         get_port
  182.                 fi
  183.         done
  184.        
  185.         # Update used port list with new port
  186.         port_list="${port_list} ${port}"
  187.        
  188.         # Write new used port list to file
  189.         echo "port_list=\"$port_list"\" 1> used_ports
  190.        
  191.         # Create directory UrbanTerror in user's home folder
  192.         if mkdir ${user_dir}/UrbanTerror ; then
  193.                 color_echo "blue" "Directory created: ${user_dir}/UrbanTerror" ; else
  194.                
  195.                 # if failed to create, exit program
  196.                 color_echo "red" "Directory failed to create: ${user_dir}/UrbanTerror"
  197.                 exit
  198.         fi
  199.  
  200.         # Create q3ut4 directory in UrbanTerror
  201.         if mkdir ${user_dir}/UrbanTerror/q3ut4 ; then
  202.                 color_echo "blue" "Directory created: ${user_dir}/UrbanTerror/q3ut4" ; else
  203.  
  204.                 # if failed to create, exit program
  205.                 color_echo "red" "Directory failed to create: ${user_dir}/UrbanTerror/q3ut4"
  206.                 exit
  207.         fi
  208.        
  209.         # Load the list of files to be linked and copied
  210.         . filelist
  211.        
  212.         # Create link for each file in /UrbanTerror/
  213.         for filename in $urt_filelist
  214.         do
  215.                 if ln -s ${source_dir}${filename} ${user_dir}/UrbanTerror/ ; then
  216.                         color_echo "blue" "File linked: ${user_dir}/${filename}" ; else
  217.                        
  218.                         # if link fails, produce error and exit program
  219.                         color_echo "red" "File link FAILED: ${user_dir}/${filename}"
  220.                         exit
  221.                 fi
  222.         done
  223.  
  224.         # Create link for each file in /UrbanTerror/q3ut4 except configs and maplist
  225.         for filename in $q3ut4_filelist
  226.         do
  227.                 if ln -s ${source_dir}${filename} ${user_dir}/UrbanTerror/q3ut4/ ; then
  228.                         color_echo "blue" "File linked: ${user_dir}/${filename}" ; else
  229.  
  230.                         # if link fails, produce error and exit program
  231.                         color_echo "red" "File link FAILED: ${user_dir}/${filename}"
  232.                         exit
  233.                 fi
  234.         done
  235.        
  236.         # Copy baseline server configs and mapcycle.txt to server
  237.         for filename in $cp_filelist
  238.         do
  239.                 if cp ${source_dir}${filename} ${user_dir}/UrbanTerror/q3ut4/ ; then
  240.                         color_echo "blue" "File copied: ${user_dir}/${filename}" ; else
  241.                        
  242.                         # if copy fails, produce error and exit.
  243.                         color_echo "red" "File copy FAILED: ${user_dir}/${filename}"
  244.                         exit
  245.                 fi
  246.         done
  247.        
  248.         # Create the server startup script with port specified earlier
  249.         # in user's home dir, then make it executable.
  250.         echo "#!/bin/bash" 1> ${user_dir}/start.sh
  251.         echo "while true" 1>> ${user_dir}/start.sh
  252.         echo "do" 1>> ${user_dir}/start.sh
  253.         echo "${user_dir}/UrbanTerror/ioUrTded.x86_64 +set fs_game q3ut4 +set dedicated 2 +set net_port ${port} +set com_hunkmegs 256 +exec server.cfg" 1>> ${user_dir}/start.sh
  254.         echo 'echo "server crashed on `date`" > last_crash.txt' 1>> ${user_dir}/start.sh
  255.         echo "done" 1>> ${user_dir}/start.sh
  256.        
  257.         # Changing to executable
  258.         if chmod +x ${user_dir}/start.sh ; then
  259.                 color_echo "blue" "Start script created successfully: ${user_dir}/start.sh" ; else
  260.                
  261.                 # If chmod fails, produce error and exit.
  262.                 color_echo "red" "Start script failed to create: ${user_dir}/start.sh"
  263.                 exit
  264.         fi
  265.        
  266.         # Changing owner ship of entire /UrbanTerror folder to username
  267.         if chown -Rf ${user}:${user} ${user_dir}/UrbanTerror ; then
  268.                 color_echo "blue" "Ownership changed to ${user}:${user}" ; else
  269.                
  270.                 # If failed, produce error and exit.
  271.                 color_echo "red" "Problem changing ownership to ${user}:${user} on directory: ${user_dir}/UrbanTerror"
  272.                 exit
  273.         fi
  274.        
  275.         # Ask user if he would like more maps, and read his reply.
  276.         color_echo "yellow" "Would you like to install additional maps? (a)ll / (y)es / (n)o"
  277.         read inst_maps
  278.        
  279.         # Case: a - install all maps without prompting
  280.         # Case: y - install all maps prompting before each map.
  281.         case "$inst_maps" in
  282.                 "a" )
  283.                
  284.                         # Run function to install w/o prompts
  285.                         map_install_all $map_filelist $user_dir
  286.                         ;;
  287.                 "y" )
  288.                
  289.                         # Run function to install w/ prompts
  290.                         map_install_yes $map_filelist $user_dir
  291.                         ;;
  292.         esac
  293.        
  294.         # Ask user if he would like additional league configs, read reply
  295.         color_echo "yellow" "Install additional configs? (y)es / (n)o"
  296.         read cfg_inst
  297.        
  298.         # If reply "y" then selectively ask for each league config
  299.         if [ $cfg_inst == "y" ] ; then
  300.                 for filename in $cfg_filelist
  301.                 do
  302.                        
  303.                         # Ask user if they would like named config
  304.                         color_echo "yellow" "Copy config: ${filename}  (y)es / (n)o"
  305.                         read yeno
  306.                        
  307.                         # If they replied "y", copy the config to users /UrbanTerror/q3ut4
  308.                         if [ $yeno == "y" ] ; then
  309.                                 if cp ${source_dir}${filename} ${user_dir}/UrbanTerror/q3ut4 ; then
  310.                                         color_echo "blue" "File copied: ${user_dir}/${filename}" ; else
  311.  
  312.                                         # if copy fails, produce error and exit.
  313.                                         color_echo "red" "File copy FAILED: ${user_dir}/${filename}"
  314.                                         exit
  315.                                 fi
  316.                         fi
  317.                 done
  318.                
  319.                 # Ask if installing as a pugbot server.
  320.                 color_echo "yellow" "Install pugbot configs?  (y)es / (n)o"
  321.                 read pug_inst
  322.                
  323.                 # If replied "y" copy all pugbot configs listed.
  324.                 if [ $pug_inst == "y" ] ; then
  325.                         for filename in $pugcfg_filelist
  326.                         do
  327.                                 if cp ${source_dir}${filename} ${user_dir}/UrbanTerror/q3ut4 ; then
  328.                                         color_echo "blue" "File copied: ${user_dir}/${filename}" ; else
  329.  
  330.                                         # if copy fails, produce error and exit.
  331.                                         color_echo "red" "File copy FAILED: ${user_dir}/${filename}"
  332.                                         exit
  333.                                 fi
  334.                         done
  335.                 fi
  336.         fi
  337. }
  338.  
  339. # Set command line parms to user and port, syntax: install-urtded.sh username port
  340. user=$1
  341. port=$2
  342.  
  343. # Run main install function, passing on user and port parms
  344. run_install $user $port
  345.  
  346. #-------------------------------------------------------------------------------------------#
  347. # About the script:                                                                         #
  348. #                                                                                           #
  349. # This script was created so that a server admin of a fairly larger server                  #
  350. # could easily install new urt servers without wasting excessive space                      #
  351. # or wasting even more valuable time.                                                       #
  352. #                                                                                           #
  353. # You can see by the sample files provided the layout of the files pretty easy.             #
  354. # You can add as many maps or configs to the lists as you want.                             #
  355. # I would not advise messing with the base line install file lists,                         #
  356. # they are picked pretty selectively as to make sure min space usage                        #
  357. # but copy any files that server operator may want to change later.                         #
  358. # The file lists are loaded from the same dir as the script.                                #
  359. #                                                                                           #
  360. # Syntax for running: install-urtded.sh username port                                       #
  361. # username should be a valid user on the system with a directory in /home/                  #
  362. # port should be between 1024 and 65535 and not already be taken by another server          #
  363. #                                                                                           #
  364. #                                                                                           #
  365. # Just another one in a collection of tools for UrbanTerror by slackin.                     #
  366. # Check out the Pick-Up game system, PUGBOT @ http://pugbot.com/                            #
  367. # To talk about this script or any other script/tool by slackin,                            #
  368. # try using the pugbot forums, link to the forums: http://forums.pugbot.com/                #
  369. #                                                                                           #
  370. # Hope one of you guys finds this useful!                                                   #
  371. #-------------------------------------------------------------------------------------------#
RAW Paste Data
Top