daily pastebin goal
5%
SHARE
TWEET

bash <(wget -O-

AdrianLIVE Mar 20th, 2017 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # Vars
  4.  
  5. USERADD=`which useradd`
  6. USERMOD=`which usermod`
  7. USERDEL=`which userdel`
  8. GROUPADD=`which groupadd`
  9. MACHINE=`uname -m`
  10. ipaddress=`ip route get 8.8.8.8 | awk '{print $NF; exit}'`
  11. Instversion="1.3.2"
  12.  
  13. # Functions
  14.  
  15. function greenMessage {
  16.     echo -e "\\033[32;1m${@}\033[0m"
  17. }
  18.  
  19. function magentaMessage {
  20.     echo -e "\\033[35;1m${@}\033[0m"
  21. }
  22.  
  23. function cyanMessage {
  24.     echo -e "\\033[36;1m${@}\033[0m"
  25. }
  26.  
  27. function redMessage {
  28.     echo -e "\\033[31;1m${@}\033[0m"
  29. }
  30.  
  31. function yellowMessage {
  32.     echo -e "\\033[33;1m${@}\033[0m"
  33. }
  34.  
  35. function errorQuit {
  36.     errorExit "Exit now!"
  37. }
  38.  
  39. function errorExit {
  40.     redMessage ${@}
  41.     exit 0
  42. }
  43.  
  44. function errorContinue {
  45.     redMessage "Invalid option."
  46.     return
  47. }
  48.  
  49. function makeDir {
  50.     if [ "$1" != "" -a ! -d $1 ]; then
  51.         mkdir -p $1
  52.     fi
  53. }
  54.  
  55. function checkInstall {
  56.     if [ "`dpkg-query -s $1 2>/dev/null`" == "" ]; then
  57.         greenMessage "Installing package $1"
  58.         apt-get install -y $1 2>/dev/null
  59.     fi
  60. }
  61.  
  62. # Checking Installer version
  63.  
  64. checkInstall wget
  65. showversion=`wget https://sinusbot-installer.de/version -q -O -`
  66. if [ `wget https://sinusbot-installer.de/version -q -O -` == "$Instversion" ]; then
  67.     greenMessage "Installer is uptodate"
  68. else
  69.     errorExit "Please download a newer installer version! Latest version is $showversion!"
  70. fi 
  71.  
  72. # Must be root. Checking...
  73.  
  74. if [ "`id -u`" != "0" ]; then
  75.     cyanMessage "Change to root account required"
  76.     su root
  77.    
  78.     fi
  79.    
  80. if [ "`id -u`" != "0" ]; then
  81.     errorExit "Still not root, aborting"
  82.    
  83.     fi
  84.  
  85. # Start installer
  86.    
  87. if [ -f /etc/debian_version -o -f /etc/centos-release ]; then
  88.     greenMessage "This is the automatic installer for latest Sinusbot. USE AT YOUR OWN RISK!"
  89.     sleep 1
  90.     cyanMessage "You can choose between installing, upgrading and removing the Sinusbot."
  91.     sleep 1
  92.     redMessage "Installer by Philipp Esswein | DAThosting.eu - Your game-/voiceserver hoster (only german)."
  93.     sleep 1
  94.     magentaMessage "Please rate this script at: https://forum.sinusbot.com/resources/sinusbot-installer-script.58/"
  95.     sleep 1
  96.     yellowMessage "You're using Installer $Instversion"
  97.    
  98. # What should be done?
  99.  
  100.     redMessage "What should the Installer do?"
  101.    
  102.     OPTIONS=("Install" "Update" "Remove" "Quit")
  103.     select OPTION in "${OPTIONS[@]}"; do
  104.         case "$REPLY" in
  105.             1|2|3 ) break;;
  106.             4 ) errorQuit;;
  107.             *) errorContinue;;
  108.         esac
  109.     done
  110.    
  111.     if [ "$OPTION" == "Install" ]; then
  112.         INSTALL="Inst"
  113.     elif [ "$OPTION" == "Update" ]; then
  114.         INSTALL="Updt"
  115.     elif [ "$OPTION" == "Remove" ]; then
  116.         INSTALL="Rem"
  117.  
  118.     fi
  119.    
  120. # Check which OS
  121.  
  122. if [ "$INSTALL" != "Rem" ]; then
  123.  
  124.     if [ -f /etc/centos-release ]; then
  125.         greenMessage "Installing redhat-lsb! Please wait."
  126.         yum -y -q install redhat-lsb
  127.         greenMessage "Done!"
  128.    
  129.     fi
  130.    
  131.     if [ -f /etc/debian_version ]; then
  132.         greenMessage "Check if lsb-release and debconf-utils is installed..."
  133.         checkInstall debconf-utils
  134.         checkInstall lsb-release
  135.         greenMessage "Done!"
  136.    
  137.     fi
  138.    
  139. # Functions from lsb_release
  140.  
  141.     OS=`lsb_release -i 2> /dev/null | grep 'Distributor' | awk '{print tolower($3)}'`
  142.     OSBRANCH=`lsb_release -c 2> /dev/null | grep 'Codename' | awk '{print $2}'`
  143.    
  144. fi
  145.  
  146. # Go on
  147.  
  148.     if [ "$INSTALL" != "Rem" ]; then
  149.         if [ "$OS" == "" ]; then
  150.             errorExit "Error: Could not detect OS. Currently only Debian, Ubuntu and CentOS are supported. Aborting!"
  151.             elif [ `cat /etc/debian_version | awk '{print $1}'` == "7" ] || [ `cat /etc/debian_version | grep "7."` ]; then
  152.             errorExit "Debian 7 isn't supported anymore!"
  153.             else
  154.             greenMessage "Detected OS $OS"
  155.            
  156.             fi
  157.            
  158.         if [ "$OSBRANCH" == "" -a ! -f /etc/centos-release ]; then
  159.             errorExit "Error: Could not detect branch of OS. Aborting"
  160.             else
  161.             greenMessage "Detected branch $OSBRANCH"
  162.            
  163.             fi
  164.            
  165.         if [ "$MACHINE" == "x86_64" ]; then
  166.             ARCH="amd64"
  167.             else
  168.             errorExit "$MACHINE is not supported!"
  169.            
  170.             fi 
  171.             fi
  172.            
  173.             if [ "$OS" != "ubuntu" ] && [ "$INSTALL" != "Rem" ]; then
  174.                 yellowMessage "Which start script should be used?"
  175.                 OPTIONS=("system.d" "init.d")
  176.                 select OPTION in "${OPTIONS[@]}"; do
  177.                     case "$REPLY" in
  178.                         1|2 ) break;;
  179.                         *) errorContinue;;
  180.                     esac
  181.                 done
  182.                
  183.                 if [ "$OPTION" == "init.d" ]; then
  184.                     OS="ubuntu"
  185.  
  186.                 fi
  187.                 fi
  188.    
  189. # Set path or continue with normal
  190.        
  191.         yellowMessage "Automatic usage or own directories?"
  192.        
  193.         OPTIONS=("Automatic" "Own path" "Quit")
  194.         select OPTION in "${OPTIONS[@]}"; do
  195.             case "$REPLY" in
  196.                 1|2 ) break;;
  197.                 3 ) errorQuit;;
  198.                 *) errorContinue;;
  199.             esac
  200.         done
  201.        
  202.         if [ "$OPTION" == "Automatic" ]; then
  203.             LOCATION=/opt/sinusbot         
  204.            
  205.         elif [ "$OPTION" == "Own path" ]; then
  206.             yellowMessage "Enter location where the bot should be installed/updated/removed. Like /opt/sinusbot. Include the / at first position and none at the end!"
  207.        
  208.             LOCATION=""
  209.                 while [[ ! -d $LOCATION ]]; do
  210.                     read -p "Location [/opt/sinusbot]: " LOCATION
  211.                     if [ "$INSTALL" != "Inst" ] && [ ! -d $LOCATION ]; then
  212.                         redMessage "Directory not found, try again!"
  213.                         fi
  214.                     if [ "$INSTALL" == "Inst" ]; then
  215.                     if [ "$LOCATION" == "" ]; then
  216.                     LOCATION=/opt/sinusbot
  217.                     fi
  218.                     makeDir $LOCATION
  219.                         fi
  220.                 done
  221.            
  222.             greenMessage "Your directory is $LOCATION."
  223.            
  224.             OPTIONS=("Yes" "No, change it!" "Quit")
  225.                 select OPTION in "${OPTIONS[@]}"; do
  226.                     case "$REPLY" in
  227.                         1|2 ) break;;
  228.                         3 ) errorQuit;;
  229.                         *) errorContinue;;
  230.                     esac
  231.                 done
  232.                
  233.                 if [ "$OPTION" == "No, change it!" ]; then
  234.                     LOCATION=""
  235.                     while [[ ! -d $LOCATION ]]; do
  236.                         read -p "Location [/opt/sinusbot]: " LOCATION
  237.                         if [ "$INSTALL" != "Inst" ] && [ ! -d $LOCATION ]; then
  238.                             redMessage "Directory not found, try again!"
  239.                             fi
  240.                         if [ "$INSTALL" == "Inst" ]; then
  241.                         makeDir $LOCATION
  242.                             fi
  243.                     done
  244.                    
  245.                     greenMessage "Your directory is $LOCATION."
  246.                    
  247.                     fi
  248.                
  249.             fi
  250.            
  251.             LOCATIONex=$LOCATION/sinusbot
  252.            
  253. # Check if Sinusbot already installed and if update is possible
  254.  
  255.     if [ "$INSTALL" == "Inst" ]; then
  256.         if [ -f $LOCATION/sinusbot ]; then
  257.         redMessage "Sinusbot already installed with automatic install option!"
  258.         read -p "Would you like to update the bot instead? [Y / N]: " OPTION
  259.        
  260.             if [ "$OPTION" == "Y" ] || [ "$OPTION" == "y" ]; then
  261.                 INSTALL="Updt"
  262.             elif [ "$OPTION" == "N" ] || [ "$OPTION" == "n" ]; then
  263.                 errorExit "Installer stops now!"
  264.                
  265.                 fi
  266.         else
  267.         greenMessage "Sinusbot isn't installed yet. Installer goes on."
  268.  
  269.         fi
  270.        
  271.     elif [ "$INSTALL" == "Rem" ] || [ "$INSTALL" == "Updt" ]; then
  272.         if [ ! $LOCATION ]; then
  273.         errorExit "Sinusbot isn't installed!"
  274.         else
  275.         greenMessage "Sinusbot is installed. Installer goes on."
  276.  
  277.         fi
  278.         fi
  279.    
  280. # Remove Sinusbot
  281.  
  282. if [ "$INSTALL" == "Rem" ]; then
  283.  
  284.     redMessage "Sinusbot will now be removed completely from your system!"
  285.    
  286.     SINUSBOTUSER=`ls -ld $LOCATION | awk '{print $3}'`
  287.    
  288.         greenMessage "Your Sinusbotuser is \"$SINUSBOTUSER\"? After select Yes it could take a while."     
  289.    
  290.     OPTIONS=("Yes" "No")
  291.     select OPTION in "${OPTIONS[@]}"; do
  292.         case "$REPLY" in
  293.             1 ) break;;
  294.             2 ) errorQuit;;
  295.             *) errorContinue;;
  296.         esac
  297.     done
  298.    
  299.     if [ "`ps ax | grep sinusbot | grep SCREEN`" ]; then
  300.         ps ax | grep sinusbot | grep SCREEN | awk '{print $1}' | while read PID; do
  301.         kill $PID
  302.         done
  303.  
  304.         fi
  305.        
  306.     if [ "`ps ax | grep ts3bot | grep SCREEN`" ]; then
  307.         ps ax | grep ts3bot | grep SCREEN | awk '{print $1}' | while read PID; do
  308.         kill $PID
  309.         done
  310.  
  311.         fi
  312.  
  313.     if [ -f /etc/systemd/system/sinusbot.service ] && [ "$OS" != "ubuntu" ]; then
  314.         if [ `systemctl is-active sinusbot >/dev/null 2>&1 && echo UP || echo DOWN` == "UP" ]; then
  315.             service sinusbot stop
  316.             systemctl disable sinusbot
  317.             rm /etc/systemd/system/sinusbot.service
  318.         else
  319.             rm /etc/systemd/system/sinusbot.service
  320.         fi
  321.     elif [ -f /etc/init.d/sinusbot ]; then
  322.         if [ "`/etc/init.d/sinusbot status | awk '{print $NF; exit}'`" == "UP" ]; then
  323.             su -c "/etc/init.d/sinusbot stop" $SINUSBOTUSER
  324.             su -c "screen -wipe" $SINUSBOTUSER
  325.             update-rc.d -f sinusbot remove >/dev/null 2>&1
  326.             rm /etc/init.d/sinusbot
  327.         else
  328.             rm /etc/init.d/sinusbot
  329.         fi
  330.         fi
  331.  
  332.     if [ "$LOCATION" ]; then
  333.         rm -R $LOCATION >/dev/null 2>&1
  334.         greenMessage "Files removed successfully!"
  335.         else
  336.         redMessage "Error while removing files."
  337.                
  338.         fi
  339.    
  340.     if [ $SINUSBOTUSER != "root" ]; then
  341.    
  342.     redMessage "Remove user \"$SINUSBOTUSER\"?"
  343.    
  344.     OPTIONS=("Yes" "No")
  345.     select OPTION in "${OPTIONS[@]}"; do
  346.         case "$REPLY" in
  347.             1|2 ) break;;
  348.             *) errorContinue;;
  349.         esac
  350.     done
  351.    
  352.     if [ "$OPTION" == "Yes" ]; then
  353.     pkill -9 -u `id -u $SINUSBOTUSER`
  354.     if [ -f /etc/centos-release ]; then
  355.     userdel -f --remove $SINUSBOTUSER >/dev/null 2>&1
  356.     else
  357.     deluser -f --remove-home $SINUSBOTUSER >/dev/null 2>&1
  358.     fi
  359.    
  360.     if [ "`id $SINUSBOTUSER 2> /dev/null`" == "" ]; then
  361.         greenMessage "User removed successfully!"
  362.         else
  363.         redMessage "Error while removing user!"
  364.        
  365.         fi
  366.     fi
  367.     fi
  368.    
  369.     if [ -f /usr/local/bin/youtube-dl ]; then
  370.     redMessage "Remove YoutubeDL?"
  371.    
  372.     OPTIONS=("Yes" "No")
  373.     select OPTION in "${OPTIONS[@]}"; do
  374.         case "$REPLY" in
  375.             1|2 ) break;;
  376.             *) errorContinue;;
  377.         esac
  378.     done
  379.    
  380.     if [ "$OPTION" == "Yes" ]; then
  381.     rm /usr/local/bin/youtube-dl
  382.     greenMessage "Removed YT-DL successfully!"
  383.    
  384.         fi
  385.     fi
  386.            
  387.     greenMessage "Sinusbot removed completely including all directories."
  388.    
  389. exit 0
  390.    
  391. fi
  392.    
  393. # Private usage only!
  394.    
  395.     redMessage "This Sinusbot version is only for private use! Accept?"
  396.    
  397.     OPTIONS=("No" "Yes")
  398.     select OPTION in "${OPTIONS[@]}"; do
  399.         case "$REPLY" in
  400.             1 ) errorQuit;;
  401.             2 ) break;;
  402.             *) errorContinue;;
  403.         esac
  404.     done
  405.    
  406. # Update packages or not
  407.    
  408.     redMessage 'Update the system packages to the latest version? Recommended, as otherwise dependencies might break! Option "No" = Exit'
  409.  
  410.     OPTIONS=("Yes" "Try without" "No")
  411.     select OPTION in "${OPTIONS[@]}"; do
  412.         case "$REPLY" in
  413.             1|2 ) break;;
  414.             3 ) errorQuit;;
  415.             *) errorContinue;;
  416.         esac
  417.     done
  418.        
  419.     greenMessage "Start installer now!"
  420.     sleep 2
  421.    
  422.     if [ "$OPTION" == "Yes" ]; then
  423.     greenMessage "Updating the system in a few seconds silently (no optical output)!"
  424.     sleep 1
  425.     redMessage "This could take a while. Please give it up to 10 minutes!"
  426.     sleep 3
  427.    
  428.     if [ -f /etc/centos-release ]; then
  429.     yum -y -q update && yum -y -q install curl
  430.     else
  431.     apt-get -qq update && apt-get -qq upgrade -y && apt-get -qq install curl -y
  432.     fi
  433.    
  434.     elif [ "$OPTION" == "No" ]; then
  435.     if [ -f /etc/centos-release ]; then
  436.     yum -y -q install curl
  437.     else
  438.     apt-get -qq install curl -y
  439.    
  440.     fi
  441.     fi 
  442.     fi
  443.  
  444. # TeamSpeak3-Client latest check || Deactivated till botupdate
  445.  
  446. #   greenMessage "Searching latest TS3-Client build for hardware type $MACHINE with arch $ARCH."
  447.    
  448. #   for VERSION in ` curl -s http://dl.4players.de/ts/releases/ | grep -Po '(?<=href=")[0-9]+(\.[0-9]+){2,3}(?=/")' | sort -Vr | head -1`; do
  449. #        DOWNLOAD_URL_VERSION="http://dl.4players.de/ts/releases/$VERSION/TeamSpeak3-Client-linux_$ARCH-$VERSION.run"
  450. #        STATUS=`curl -I $DOWNLOAD_URL_VERSION 2>&1 | grep "HTTP/" | awk '{print $2}'`
  451. #        if [ "$STATUS" == "200" ]; then
  452. #            DOWNLOAD_URL=$DOWNLOAD_URL_VERSION
  453. #            break
  454.            
  455. #           fi
  456. #    done
  457.    
  458. #   if [ "$STATUS" == "200" -a "$DOWNLOAD_URL" != "" ]; then
  459. #        greenMessage "Detected latest TS3-Client version as $VERSION with download URL $DOWNLOAD_URL"
  460. #       else
  461. #        errorExit "Could not detect latest TS3-Client version"
  462.        
  463. #       fi
  464.  
  465.         DOWNLOAD_URL="http://ftp.4players.de/pub/hosted/ts3/releases/3.0.19.4/TeamSpeak3-Client-linux_amd64-3.0.19.4.run"
  466.         VERSION="3.0.19.4"
  467.  
  468. # Install necessary aptitudes for sinusbot.
  469.    
  470.     magentaMessage "Installing necessary packages! Please wait..."
  471.    
  472.     if [ -f /etc/centos-release ]; then
  473.     yum -y -q install screen x11vnc xvfb libxcursor1 ca-certificates bzip2 psmisc libglib2.0-0
  474.     else
  475.     apt-get -qq install screen x11vnc xvfb libxcursor1 ca-certificates bzip2 psmisc libglib2.0-0 less -y
  476.     fi
  477.     update-ca-certificates >/dev/null 2>&1
  478.  
  479.    
  480.     greenMessage "Packages installed!"
  481.  
  482. # Create/check user for sinusbot.
  483.  
  484.     if [ "$INSTALL" == "Updt" ]; then
  485.         SINUSBOTUSER=`ls -ld $LOCATION | awk '{print $3}'`
  486.        
  487.     else
  488.    
  489.     cyanMessage 'Please enter the name of the sinusbot user. Typically "sinusbot". If it does not exists, the installer will create it.'
  490.    
  491.             SINUSBOTUSER=""
  492.                     while [[ ! $SINUSBOTUSER ]]; do
  493.                         read -p "Username [sinusbot]: " SINUSBOTUSER
  494.                         if [ "$SINUSBOTUSER" == "" ]; then
  495.                             SINUSBOTUSER=sinusbot
  496.                             fi
  497.                         if [ ! "$SINUSBOTUSER" == "" ]; then
  498.                             greenMessage "Your sinusbot user is: $SINUSBOTUSER"
  499.                             fi
  500.                     done
  501.        
  502.     if [ "`id $SINUSBOTUSER 2> /dev/null`" == "" ]; then
  503.             if [ -d /home/$SINUSBOTUSER ]; then
  504.                 $GROUPADD $SINUSBOTUSER
  505.                 $USERADD -d /home/$SINUSBOTUSER -s /bin/bash -g $SINUSBOTUSER $SINUSBOTUSER
  506.                 else
  507.                 $GROUPADD $SINUSBOTUSER
  508.                 $USERADD -m -b /home -s /bin/bash -g $SINUSBOTUSER $SINUSBOTUSER
  509.                
  510.                 fi
  511.         else
  512.         greenMessage "User \"$SINUSBOTUSER\" already exists."
  513.        
  514.         fi
  515.         fi
  516.  
  517. # Create dirs or remove them.
  518.        
  519.         ps -u $SINUSBOTUSER | grep ts3client | awk '{print $1}' | while read PID; do
  520.         kill $PID
  521.         done
  522.     if [ -f $LOCATION/ts3client_startscript.run ]; then
  523.         rm -rf $LOCATION/*
  524.        
  525.         fi
  526.    
  527.     makeDir $LOCATION/teamspeak3-client
  528.    
  529.     chmod 750 -R $LOCATION
  530.     chown -R $SINUSBOTUSER:$SINUSBOTUSER $LOCATION
  531.     cd $LOCATION/teamspeak3-client
  532.  
  533. # Downloading TS3-Client files.
  534.  
  535.         greenMessage "Downloading TS3 client files."
  536.         su -c "curl -O -s $DOWNLOAD_URL" $SINUSBOTUSER
  537.    
  538.     if [ ! -f TeamSpeak3-Client-linux_$ARCH-$VERSION.run -a ! -f ts3client_linux_$ARCH ]; then
  539.         errorExit "Download failed! Exiting now!"
  540.  
  541.         fi
  542.  
  543. # Installing TS3-Client.
  544.    
  545.     if [ -f TeamSpeak3-Client-linux_$ARCH-$VERSION.run ]; then
  546.         greenMessage "Installing the TS3 client."
  547.         redMessage "Read the eula!"
  548.         sleep 1
  549.         yellowMessage 'Do the following: Press "ENTER" then press "q" after that press "y" and accept it with another "ENTER".'
  550.         sleep 2
  551.    
  552.         chmod 777 ./TeamSpeak3-Client-linux_$ARCH-$VERSION.run
  553.    
  554.         su -c "./TeamSpeak3-Client-linux_$ARCH-$VERSION.run" $SINUSBOTUSER
  555.    
  556.         cp -R ./TeamSpeak3-Client-linux_$ARCH/* ./
  557.         sleep 2
  558.         rm ./ts3client_runscript.sh
  559.         rm ./TeamSpeak3-Client-linux_$ARCH-$VERSION.run
  560.         rm -R ./TeamSpeak3-Client-linux_$ARCH
  561.    
  562.         greenMessage "TS3 client install done."
  563.    
  564.         fi
  565.  
  566. # Downloading latest Sinusbot.
  567.  
  568.     cd $LOCATION
  569.    
  570.         greenMessage "Downloading latest Sinusbot."
  571.         su -c "curl -O -s https://www.sinusbot.com/dl/sinusbot-beta.tar.bz2" $SINUSBOTUSER
  572.    
  573.     if [ ! -f sinusbot-beta.tar.bz2 -a ! -f sinusbot ]; then
  574.         redMessage "Error while downloading with cURL. Trying it with wget."
  575.         if  [ -f /etc/centos-release ]; then
  576.         yum -y -q install wget
  577.         fi
  578.         su -c "wget -q https://www.sinusbot.com/dl/sinusbot-beta.tar.bz2" $SINUSBOTUSER
  579.        
  580.         fi
  581.  
  582.     if [ ! -f sinusbot-beta.tar.bz2 -a ! -f sinusbot ]; then
  583.         errorExit "Download failed! Exiting now!"
  584.        
  585.         fi
  586.        
  587. # Installing latest Sinusbot.
  588.        
  589.         greenMessage "Extracting Sinusbot files."
  590.         su -c "tar -xjf sinusbot-beta.tar.bz2" $SINUSBOTUSER
  591.         rm -f sinusbot-beta.tar.bz2
  592.    
  593.         cp plugin/libsoundbot_plugin.so $LOCATION/teamspeak3-client/plugins
  594.    
  595.         chmod 755 sinusbot
  596.        
  597.         if [ "$INSTALL" == "Inst" ]; then
  598.         greenMessage "Sinusbot installation done."
  599.         elif [ "$INSTALL" == "Updt" ]; then
  600.         greenMessage "Sinusbot update done."
  601.         fi 
  602.        
  603.     if [ ! -f /etc/systemd/system/sinusbot.service ] && [ $OS != "ubuntu" ]; then
  604.        
  605.         cd /etc/systemd/system
  606.         echo '[Unit]
  607. Description = Sinusbot the Teamspeak 3 and Discord MusicBot. by @xuxe
  608. After = syslog.target network.target
  609.  
  610. [Service]
  611. User=hereuser
  612. ExecStart=/home
  613. Type=simple
  614. KillSignal=2
  615. SendSIGKILL=yes
  616.  
  617. [Install]
  618. WantedBy=multi-user.target'>>sinusbot.service
  619.         sed -i 's/User=hereuser/User='$SINUSBOTUSER'/g' /etc/systemd/system/sinusbot.service
  620.         sed -i 's!ExecStart=/home!ExecStart='$LOCATIONex'!g' /etc/systemd/system/sinusbot.service
  621.    
  622.         systemctl daemon-reload
  623.         systemctl enable sinusbot.service
  624.        
  625.         greenMessage 'Installed systemd file to start the Sinusbot with "service sinusbot {start|stop|status|restart}"'
  626.        
  627.     elif [ ! -f /etc/init.d/sinusbot ] && [ $OS == "ubuntu" ]; then
  628.        
  629.         cd /etc/init.d     
  630.         curl -O -s https://raw.githubusercontent.com/Qhiliqq/Sinusbot-Startscript/master/sinusbot
  631.         sed -i 's/USER="mybotuser"/USER="'$SINUSBOTUSER'"/g' /etc/init.d/sinusbot
  632.         sed -i 's!DIR_ROOT="/opt/ts3soundboard/"!DIR_ROOT="'$LOCATION'/"!g' /etc/init.d/sinusbot
  633.    
  634.         chmod +x /etc/init.d/sinusbot
  635.         update-rc.d sinusbot defaults >/dev/null 2>&1
  636.        
  637.         greenMessage 'Installed init.d file to start the Sinusbot with "/etc/init.d/sinusbot {start|stop|status|restart|console|update|backup}"'
  638.    
  639.     else
  640.         if [ $OS != "ubuntu" ]; then
  641.             redMessage "systemd already exists!"
  642.             service sinusbot status
  643.                 if [ $? == "0" ]; then
  644.                 redMessage "Sinusbot stopping now!"
  645.                 service sinusbot stop
  646.                 systemctl disable sinusbot
  647.                 else
  648.                 greenMessage "Sinusbot already stopped."
  649.  
  650.                 fi
  651.            
  652.         elif [ $OS == "ubuntu" ]; then
  653.             redMessage "init.d already exists!"
  654.             if [ `/etc/init.d/sinusbot status | awk '{print $NF; exit}'` == "UP" ]; then
  655.                 redMessage "Sinusbot stopping now!"
  656.                 /etc/init.d/sinusbot stop
  657.                 su -c "screen -wipe" $SINUSBOTUSER
  658.                 update-rc.d -f sinusbot remove >/dev/null 2>&1
  659.                 else
  660.                 greenMessage "Sinusbot already stopped."
  661.                 fi
  662.        
  663.         fi
  664.         fi
  665.    
  666.         cd $LOCATION
  667.  
  668. if [ "$INSTALL" == "Inst" ]; then
  669.    
  670.     if [ ! -f $LOCATION/config.ini ]; then
  671.         echo 'ListenPort = 8087
  672.         ListenHost = "0.0.0.0"
  673.         TS3Path = "'$LOCATION'/teamspeak3-client/ts3client_linux_amd64"
  674.         YoutubeDLPath = ""'>>$LOCATION/config.ini
  675.         greenMessage "Config.ini created successfully."
  676.         else
  677.         redMessage "Config.ini already exists or creation error!"
  678.        
  679.         fi
  680.    
  681. fi
  682.    
  683.     if [ `grep -Pq 'sinusbot' /etc/cron.d/sinusbot &>/dev/null` ]; then
  684.         redMessage "Cronjob already set for Sinusbot updater!"
  685.         else
  686.         greenMessage "Installing Cronjob for automatic Sinusbot update..."
  687.         echo "0 0 * * * su $SINUSBOTUSER $LOCATION/sinusbot -update >/dev/null 2>&1">/etc/cron.d/sinusbot
  688.         greenMessage "Installing Sinusbot update cronjob successful."
  689.        
  690.         fi     
  691.  
  692. # Installing YT-DL.
  693.  
  694.     if [ ! -f /usr/local/bin/youtube-dl ]; then
  695.     redMessage "Should YT-DL be installed?"
  696.     OPTIONS=("Yes" "No")
  697.     select OPTION in "${OPTIONS[@]}"; do
  698.         case "$REPLY" in
  699.             1|2 ) break;;
  700.             *) errorContinue;;
  701.         esac
  702.     done
  703.    
  704.     if [ "$OPTION" == "Yes" ]; then
  705.     greenMessage "Installing YT-Downloader now!"
  706.    
  707.     if [ "`grep -c 'youtube' /etc/cron.d/sinusbot`" -ge 1 ]; then
  708.         redMessage "Cronjob already set for YT-DL updater!"
  709.         else
  710.         greenMessage "Installing Cronjob for automatic YT-DL update..."
  711.         echo "0 0 * * * su $SINUSBOTUSER youtube-dl -U >/dev/null 2>&1">>/etc/cron.d/sinusbot
  712.         greenMessage "Installing successful."
  713.        
  714.         fi
  715.        
  716.         sed -i 's/YoutubeDLPath = \"\"/YoutubeDLPath = \"\/usr\/local\/bin\/youtube-dl\"/g' $LOCATION/config.ini
  717.    
  718.     curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl 2> /dev/null
  719.     chmod a+rx /usr/local/bin/youtube-dl
  720.        
  721.     youtube-dl -U
  722.    
  723.     fi
  724.    
  725.     else
  726.     redMessage "YouTube-DL already installed. Checking for updates."
  727.     youtube-dl -U
  728.     fi
  729.        
  730. # Creating Readme
  731.    
  732.     if [ ! -a "$LOCATION/README_installer.txt" ] && [ $OS != "ubuntu" ] ; then
  733.     echo '##################################################################################
  734. # #
  735. # Usage: service sinusbot {start|stop|status|restart} #
  736. # - start: start the bot #
  737. # - stop: stop the bot #
  738. # - status: display the status of the bot (down or up) #
  739. # - restart: restart the bot #
  740. # #
  741. ##################################################################################'>>$LOCATION/README_installer.txt
  742.     elif [ ! -a "$LOCATION/README_installer.txt" ] && [ $OS == "ubuntu" ] ; then
  743.     echo '##################################################################################
  744. # #
  745. # Usage: /etc/init.d/sinusbot {start|stop|status|restart|console|update|backup} #
  746. # - start: start the bot #
  747. # - stop: stop the bot #
  748. # - status: display the status of the bot (down or up) #
  749. # - restart: restart the bot #
  750. # - console: display the bot console #
  751. # - update: runs the bot updater (with start & stop)
  752. # - backup: archives your bot root directory
  753. # To exit the console without stopping the server, press CTRL + A then D. #
  754. # #
  755. ##################################################################################'>>$LOCATION/README_installer.txt
  756.     fi
  757.  
  758. # Starting Sinusbot first time!
  759.    
  760.     if [ "$INSTALL" != "Updt" ]; then
  761.    
  762.     greenMessage 'Starting the Sinusbot. For first time.'
  763.     chown -R $SINUSBOTUSER:$SINUSBOTUSER $LOCATION
  764.     cd $LOCATION
  765.  
  766. # Password variable
  767.    
  768.     export Q=`su $SINUSBOTUSER -c './sinusbot --initonly'`
  769.     password=`export | awk '/password/{ print $10 }' | tr -d "'"`
  770.     if [ $password == "" ]; then
  771.         errorExit "Failed to read password, try a reinstall again."
  772.     else
  773.         greenMessage "Done"
  774.     fi
  775.  
  776. # Starting bot 
  777.  
  778.     greenMessage "Starting Sinusbot again. Your admin password = '$password'"
  779.     fi
  780.     if [ $OS != "ubuntu" ]; then
  781.     service sinusbot start
  782.     elif [ $OS == "ubuntu" ]; then
  783.     /etc/init.d/sinusbot start
  784.     fi
  785.     yellowMessage "Please wait... This will take some seconds!"
  786.     chown -R $SINUSBOTUSER:$SINUSBOTUSER $LOCATION
  787.     if [ $OS != "ubuntu" ]; then
  788.     sleep 5
  789.     elif [ $OS == "ubuntu" ]; then
  790.     sleep 10
  791.     fi
  792.  
  793. # If startup failed, the script will start normal sinusbot without screen for looking about errors. If startup successed => installation done.
  794.    
  795.     if ([ `systemctl is-active sinusbot >/dev/null 2>&1 && echo UP || echo DOWN` == "DOWN" ] && [ $OS != "ubuntu" ]) || ([ `/etc/init.d/sinusbot status | awk '{print $NF; exit}'` == "DOWN" ] && [ $OS == "ubuntu" ]); then
  796.         redMessage "Sinusbot could not start! Starting it directly. Look for errors!"
  797.         su -c "$LOCATION/sinusbot" $SINUSBOTUSER
  798.        
  799.         else
  800.  
  801.         if [ "$INSTALL" == "Inst" ]; then
  802.         greenMessage "Install done!"
  803.         elif [ "$INSTALL" == "Updt" ]; then
  804.         greenMessage "Update done!"
  805.        
  806.         fi
  807.        
  808.         if [ ! -f "$LOCATION/README_installer.txt" ]; then
  809.         yellowMessage 'Generated a README_installer.txt in '$LOCATION' with all commands for the sinusbot...'
  810.        
  811.         fi
  812.        
  813.         if [ "$INSTALL" == "Updt" ]; then
  814.         greenMessage 'All right. Everything is updated successfully. Sinusbot is UP on "'$ipaddress':8087" :)'
  815.         else
  816.         greenMessage 'All right. Everything is installed successfully. Sinusbot is UP on "'$ipaddress':8087" :) Your login is user = "admin" and password = "'$password'"'
  817.         fi
  818.         if [ $OS != "ubuntu" ]; then
  819.         redMessage 'Stop it with "service sinusbot stop".'
  820.         elif [ $OS == "ubuntu" ]; then
  821.         redMessage 'Stop it with "/etc/init.d/sinusbot stop".'
  822.         fi
  823.         magentaMessage "Don't forget to rate this script on: https://forum.sinusbot.com/resources/sinusbot-installer-script.58/"
  824.         greenMessage "Thank you for using this script! :)"
  825.        
  826.         fi
  827.    
  828. exit 0
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top