Advertisement
dsonbill

DMPServer Pastebin Bootstrap

Sep 9th, 2014
1,509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 7.18 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # LICENSE: SEE http://forum.kerbalspaceprogram.com/threads/92665-DMP-Linux-Server-Tools
  4.  
  5.  
  6. # ---------------------------------------------------------------------------------------------------------
  7. # PACKAGE
  8. # ---------------------------------------------------------------------------------------------------------
  9.  
  10.  
  11. # Common Variables
  12. INSTALLDIR="/usr/share/dmpserver"
  13. CONFIGDIR="/etc/dmpserver"
  14. DATADIR="/srv/dmpserver"
  15. LIBDIR="/var/lib/dmpserver"
  16.  
  17. # System Users
  18. SysUser[0]="dmpserver"
  19.  
  20. # Dirs
  21. NewDir[0]="$CONFIGDIR;755"
  22. NewDir[1]="$INSTALLDIR;755"
  23. NewDir[2]="$CONFIGDIR/config;755"
  24. NewDir[3]="$DATADIR;755"
  25. NewDir[8]="$LIBDIR;755"
  26.  
  27. # Pastebin Targets
  28. #         Target;Key;Directory;chmodkey(Must Exist)
  29. Target[0]="dmpbashup;Gx5wFtbx;/usr/bin;755"
  30. Target[1]="dmpserver;X4E46Af5;/usr/bin;755"
  31. Target[2]="dmpserver.cfg;UHaknDCZ;$CONFIGDIR;755"
  32. Target[3]="dmpcmd;ZTTUF4dH;/usr/bin;755"
  33. Target[4]="dmpbashlib;UQnVBYx5;$LIBDIR;755"
  34. Target[5]="dmpenv;FkWEUsfX;/usr/bin;755"
  35.  
  36. # Dependencies
  37. Depends[0]="mono"
  38. Depends[1]="screen"
  39. Depends[2]="curl"
  40.  
  41.  
  42. # Disclaimer
  43. Disclaimer="
  44. This program will download and install DarkMultiplayer, an internet game server for Kerbal Space Program.
  45. The computer or server from which you are running this script will allow other computers to connect to it
  46. from across the internet, and send data to client programs. The client programs will interact with the
  47. data, manipulate it, and send the data back to the server. The server will then receive, manipulate, and
  48. broadcast the data to other clients connected to the server. If you do not understand or agree to the
  49. function described by this message, you should answer no to the next question and refrain from running
  50. this program again.
  51.  
  52.  
  53. Additionally, this program will download and install management and update tools from www.pastebin.com .
  54. These tools are listed in the 'pbpkg' file next to pbinstall. These tools will install and
  55. periodically update DMPServer, allow for easy starting, stopping, and restarting of the DMPServer service,
  56. and allow for the deletion of the DMPServer 'Universe'. DMPServer will be downloaded and installed from
  57. www.godarklight.com , the official repository of DarkMultiplayer. If you do not understand or agree to the
  58. function described by this message, you should answer no to the next question and refrain from running
  59. this program again."
  60.  
  61. # Post-Installation Script
  62. function postInstall(){
  63.     dmpbashup
  64.     dmpenv install default
  65.     dmpserver
  66.    
  67.     echo "DarkMultiPlayer server has been installed. Make sure the correct ports are open"
  68.     echo "and restart the server. Make sure you run as root when using the tools,"
  69.     echo "i.e. 'sudo dmpserver status'."
  70.     echo "To add another server, use dmpenv, i.e. 'sudo dmpenv install server2', and"
  71.     echo "control it with dmpserver [server name], i.e. 'sudo dmpserver server2 start'."
  72. }
  73.  
  74.  
  75.  
  76.  
  77. # ---------------------------------------------------------------------------------------------------------
  78. # INSTALLER
  79. # ---------------------------------------------------------------------------------------------------------
  80.  
  81.  
  82. # Variables
  83. PASTEBIN_API="http://pastebin.com/raw.php?i="
  84. ifsNewline=$'\n'
  85. ifsReset=$IFS
  86.  
  87.  
  88. # Functions
  89. function linDistCheck(){
  90.     if hash rpm 2> /dev/null ; then
  91.         D_CHECK="rhel"
  92.     elif hash dpkg 2> /dev/null ; then
  93.         D_CHECK="debian"
  94.     else
  95.         echo "You are (probably) not running a Debian or RHEL based system!"
  96.         echo "Your linux version is (probably) not supported."
  97.         exit 1
  98.     fi
  99.        
  100. }
  101. function printDisclaimer(){
  102.     IFS=$ifsNewline
  103.     for line in $Disclaimer ; do
  104.         echo $line
  105.     done
  106.     IFS=$ifsReset
  107. }
  108.  
  109. function dependencyCheck(){
  110.     for dependency in ${Depends[@]} ; do
  111.         if hash $dependency 2> /dev/null ; then
  112.             :
  113.         else
  114.             echo "This program requires '$dependency' to be available."
  115.             echo "Please install it (try 'apt-get install $dependency' on Debian, or 'yum install $dependency' on RHEL) before continuing."
  116.             exit 1
  117.         fi
  118.     done
  119. }
  120.  
  121. function addSysUserList(){
  122.     for user in ${SysUser[@]} ; do
  123.         echo "Adding system user '$user'..."
  124.         if id -u $user >/dev/null 2> /dev/null;
  125.         then
  126.             echo "User '$user' already exists! Skipping creation."
  127.         else
  128.             case "$D_CHECK" in
  129.                 "rhel")    
  130.                     useradd -r $user
  131.                     usermod -s /bin/false $user
  132.                     ;;
  133.                
  134.                 "debian")
  135.                     adduser -system $user
  136.                     ;;
  137.                
  138.                 *) echo "Distro Not Supported."  ;;
  139.             esac
  140.             echo "Added system user '$user'."
  141.         fi
  142.     done
  143. }
  144.  
  145. function installDirList(){
  146.     for src in ${NewDir[@]} ; do
  147.         tdir=$(echo -n "$src" | awk -F ";" '{print $1}')
  148.         tcode=$(echo -n "$src" | awk -F ";" '{print $2}')
  149.         echo "Adding directory '$tdir'..."
  150.         if [ ! -d $tdir ];
  151.         then
  152.             mkdir $tdir
  153.             chmod $tcode $tdir
  154.             echo "Added directory '$tdir' with chmod code '$tcode'."
  155.         else
  156.             echo -e "Directory '$tdir' already exists! Skipping creation."
  157.         fi
  158.     done
  159. }
  160.  
  161. function getPBinScript(){
  162.     echo "Installing '$2'. File will be downloaded from ${PASTEBIN_API}$1"
  163.     curl --progress-bar ${PASTEBIN_API}$1 | tr -d '\r' > $2
  164.     echo "Installed '$2'."
  165.     echo
  166. }
  167.  
  168. function installPBinList(){
  169.     t=0
  170.     for src in ${Target[@]} ; do
  171.         tname=$(echo -n "$src" | awk -F ";" '{print $1}')
  172.         tkey=$(echo -n "$src" | awk -F ";" '{print $2}')
  173.         tdir=$(echo -n "$src" | awk -F ";" '{print $3}')
  174.         tcode=$(echo -n "$src" | awk -F ";" '{print $4}')
  175.        
  176.         if [ ! -d $tdir ];
  177.         then
  178.             echo -e "FATAL: Directory '$tdir' does not exist! Skipping file '$tdir'."
  179.         else
  180.             getPBinScript $tkey $tdir/$tname
  181.             chmod $tcode $tdir/$tname
  182.         fi
  183.         ((t++))
  184.     done
  185. }
  186.  
  187.  
  188.  
  189.  
  190. # ---------------------------------------------------------------------------------------------------------
  191. # EXECUTION
  192. # ---------------------------------------------------------------------------------------------------------
  193.  
  194.  
  195. if [ $(whoami) != 'root' ]; then
  196.         echo "This program must be run with root permissions."
  197.         exit 1
  198. fi
  199.  
  200. case "$1" in
  201.     update)
  202.         installPBinList
  203.         exit
  204.         ;;
  205.  
  206.     no-disclaim)
  207.         linDistCheck
  208.         dependencyCheck
  209.         addSysUserList
  210.         installDirList
  211.         installPBinList
  212.         postInstall
  213.         exit
  214.         ;;
  215.  
  216.     *)
  217.         printDisclaimer    
  218.         echo -n "Do you understand and agree to the terms above? [y/n]: "
  219.         read answer
  220.         case $answer in
  221.             [Yy]*)
  222.                 linDistCheck
  223.                 dependencyCheck
  224.                 addSysUserList
  225.                 installDirList
  226.                 installPBinList
  227.                 postInstall
  228.                 exit
  229.                 ;;
  230.            
  231.             [Nn]*) exit;;
  232.            
  233.             *) echo "Answer must be y or n.";;
  234.         esac
  235.         ;;
  236. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement