Advertisement
dsonbill

Pastebin Bootstrap Script

Sep 9th, 2014
1,032
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.75 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. # System Users
  11. # SysUser[0]="dmpserver"
  12.  
  13. # Dirs
  14. #         Target;chmodkey
  15. # NewDir[0]="/usr/share/dmpserver;755"
  16.  
  17. # Pastebin Targets
  18. #         Target;Key;Directory;chmodkey  (Dir Must Exist)
  19. # Target[0]="dmpserver;X4E46Af5;/usr/bin;755"
  20.  
  21. # Dependencies
  22. # Depends[0]="screen"
  23.  
  24.  
  25. # Disclaimer
  26. Disclaimer="
  27. This will be displayed line-by-line before installing the scripts. It will then ask the user
  28. yes or no."
  29.  
  30. # Post-Installation Script
  31. function postInstall(){
  32.     echo "This function will be called after the above has been accomplished."
  33. }
  34.  
  35.  
  36.  
  37.  
  38. # ---------------------------------------------------------------------------------------------------------
  39. # INSTALLER
  40. # ---------------------------------------------------------------------------------------------------------
  41.  
  42.  
  43. # Variables
  44. PASTEBIN_API="http://pastebin.com/raw.php?i="
  45. ifsNewline=$'\n'
  46. ifsReset=$IFS
  47.  
  48.  
  49. # Functions
  50. function linDistCheck(){
  51.     if hash rpm 2> /dev/null ; then
  52.         D_CHECK="rhel"
  53.     elif hash dpkg 2> /dev/null ; then
  54.         D_CHECK="debian"
  55.     else
  56.         echo "You are (probably) not running a Debian or RHEL based system!"
  57.         echo "Your linux version is (probably) not supported."
  58.         exit 1
  59.     fi
  60.        
  61. }
  62. function printDisclaimer(){
  63.     IFS=$ifsNewline
  64.     for line in $Disclaimer ; do
  65.         echo $line
  66.     done
  67.     IFS=$ifsReset
  68. }
  69.  
  70. function dependencyCheck(){
  71.     for dependency in ${Depends[@]} ; do
  72.         if hash $dependency 2> /dev/null ; then
  73.             :
  74.         else
  75.             echo "This program requires '$dependency' to be available."
  76.             echo "Please install it (try 'apt-get install $dependency' on Debian, or 'yum install $dependency' on RHEL) before continuing."
  77.             exit 1
  78.         fi
  79.     done
  80. }
  81.  
  82. function addSysUserList(){
  83.     for user in ${SysUser[@]} ; do
  84.         echo "Adding system user '$user'..."
  85.         if id -u $user >/dev/null 2> /dev/null;
  86.         then
  87.             echo "User '$user' already exists! Skipping creation."
  88.         else
  89.             case "$D_CHECK" in
  90.                 "rhel")    
  91.                     useradd -r $user
  92.                     usermod -s /bin/false $user
  93.                     ;;
  94.                
  95.                 "debian")
  96.                     adduser -system $user
  97.                     ;;
  98.                
  99.                 *) echo "Distro Not Supported."  ;;
  100.             esac
  101.             echo "Added system user '$user'."
  102.         fi
  103.     done
  104. }
  105.  
  106. function installDirList(){
  107.     for src in ${NewDir[@]} ; do
  108.         tdir=$(echo -n "$src" | awk -F ";" '{print $1}')
  109.         tcode=$(echo -n "$src" | awk -F ";" '{print $2}')
  110.         echo "Adding directory '$tdir'..."
  111.         if [ ! -d $tdir ];
  112.         then
  113.             mkdir $tdir
  114.             chmod $tcode $tdir
  115.             echo "Added directory '$tdir' with chmod code '$tcode'."
  116.         else
  117.             echo -e "Directory '$tdir' already exists! Skipping creation."
  118.         fi
  119.     done
  120. }
  121.  
  122. function getPBinScript(){
  123.     echo "Installing '$2'. File will be downloaded from ${PASTEBIN_API}$1"
  124.     curl --progress-bar ${PASTEBIN_API}$1 | tr -d '\r' > $2
  125.     echo "Installed '$2'."
  126. }
  127.  
  128. function installPBinList(){
  129.     t=0
  130.     for src in ${Target[@]} ; do
  131.         tname=$(echo -n "$src" | awk -F ";" '{print $1}')
  132.         tkey=$(echo -n "$src" | awk -F ";" '{print $2}')
  133.         tdir=$(echo -n "$src" | awk -F ";" '{print $3}')
  134.         tcode=$(echo -n "$src" | awk -F ";" '{print $4}')
  135.        
  136.         if [ ! -d $tdir ];
  137.         then
  138.             echo -e "FATAL: Directory '$tdir' does not exist! Skipping file '$tdir'."
  139.         else
  140.             getPBinScript $tkey $tdir/$tname
  141.             chmod $tcode $tdir/$tname
  142.         fi
  143.         ((t++))
  144.     done
  145. }
  146.  
  147.  
  148.  
  149.  
  150. # ---------------------------------------------------------------------------------------------------------
  151. # EXECUTION
  152. # ---------------------------------------------------------------------------------------------------------
  153.  
  154.  
  155. if [ $(whoami) != 'root' ]; then
  156.         echo "This program must be run with root permissions."
  157.         exit 1
  158. fi
  159.  
  160. printDisclaimer
  161.  
  162.  
  163. echo -n "Do you understand and agree to the terms above? [y/n]: "
  164. read answer
  165. case $answer in
  166.     [Yy]*)
  167.         linDistCheck
  168.         dependencyCheck
  169.         addSysUserList
  170.         installDirList
  171.         installPBinList
  172.         postInstall
  173.         exit
  174.         ;;
  175.    
  176.     [Nn]*) exit;;
  177.    
  178.     *) echo "Answer must be y or n.";;
  179. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement