daily pastebin goal
80%
SHARE
TWEET

Untitled

a guest Mar 17th, 2018 246 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # SinusBot Installer by Philipp Eßwein - DAThosting.eu philipp.esswein@dathosting.eu
  3.  
  4. # Vars
  5.  
  6. MACHINE=$(uname -m)
  7. Instversion="1.4"
  8.  
  9. USE_SYSTEMD=true
  10.  
  11. # Functions
  12.  
  13. function greenMessage() {
  14.   echo -e "\\033[32;1m${*}\\033[0m"
  15. }
  16.  
  17. function magentaMessage() {
  18.   echo -e "\\033[35;1m${*}\\033[0m"
  19. }
  20.  
  21. function cyanMessage() {
  22.   echo -e "\\033[36;1m${*}\\033[0m"
  23. }
  24.  
  25. function redMessage() {
  26.   echo -e "\\033[31;1m${*}\\033[0m"
  27. }
  28.  
  29. function yellowMessage() {
  30.   echo -e "\\033[33;1m${*}\\033[0m"
  31. }
  32.  
  33. function errorQuit() {
  34.   errorExit 'Exit now!'
  35. }
  36.  
  37. function errorExit() {
  38.   redMessage "${@}"
  39.   exit 1
  40. }
  41.  
  42. function errorContinue() {
  43.   redMessage "Invalid option."
  44.   return
  45. }
  46.  
  47. function makeDir() {
  48.   if [ -n "$1" ] && [ ! -d "$1" ]; then
  49.     mkdir -p "$1"
  50.   fi
  51. }
  52.  
  53. err_report() {
  54.   FAILED_COMMAND=$(wget -q -O - https://raw.githubusercontent.com/Sinusbot/installer-linux/master/sinusbot_installer.sh | sed -e "$1q;d")
  55.   redMessage "Error on line $1. Report this to the author at https://forum.sinusbot.com/threads/sinusbot-installer-script.1200/ only. Not a PN or a bad review, cause this is an error of your system not of the installer script."
  56.   if [[ "$FAILED_COMMAND" == "" ]]; then
  57.     redMessage "Failed command: https://github.com/Sinusbot/installer-linux/blob/master/sinusbot_installer.sh#L""$1"
  58.   else
  59.     redMessage "Command which failed was: \"${FAILED_COMMAND}\". Please try to execute it manually and attach the output to the bug report in the forum thread."
  60.   fi
  61.   exit 1
  62. }
  63.  
  64. trap 'err_report $LINENO' ERR
  65.  
  66. # Update notify
  67.  
  68. cyanMessage "Checking for the latest latest installer version"
  69. if [ -f /etc/centos-release ]; then
  70.   yum -y -q install wget
  71. else
  72.   apt-get -qq install wget -y
  73. fi
  74. LATEST_VERSION=$(wget --no-check-certificate --timeout=60 -qO - https://raw.githubusercontent.com/SinusBot/installer-linux/master/sinusbot_installer.sh | grep -Po '(?<=Instversion=")([0-9]\.[0-9]+)')
  75.  
  76. if [ "$(printf "${LATEST_VERSION}\\n${Instversion}" | sort -V | tail -n 1)" != "$Instversion" ]; then
  77.   errorExit "Outdated installer ${Instversion}. Upgrade your installer to version ${LATEST_VERSION}. Or reuse https://sinusbot-installer.de"
  78. else
  79.   greenMessage "Your installer is up-to-date."
  80.   sleep 1
  81. fi
  82.  
  83. # Check if the script was run as root user. Otherwise exit the script
  84. if [ "$(id -u)" != "0" ]; then
  85.   errorExit "Change to root account required!"
  86. fi
  87.  
  88. # Detect if systemctl is available then use systemd as start script. Otherwise use init.d
  89. if [[ $(command -v systemctl) == "" ]]; then
  90.   USE_SYSTEMD=false
  91. fi
  92.  
  93. # If the linux distribution is not debian and centos, then exit
  94. if [ ! -f /etc/debian_version ] && [ ! -f /etc/centos-release ]; then
  95.   errorExit 'Not supported linux distribution. Only Debian and CentOS are currently supported'!
  96. fi
  97.  
  98. greenMessage "This is the automatic installer for latest SinusBot. USE AT YOUR OWN RISK"!
  99. sleep 1
  100. cyanMessage "You can choose between installing, upgrading and removing the SinusBot."
  101. sleep 1
  102. redMessage "Installer by Philipp Esswein | DAThosting.eu - Your game-/voiceserver hoster (only german)."
  103. sleep 1
  104. magentaMessage "Please rate this script at: https://forum.sinusbot.com/resources/sinusbot-installer-script.58/"
  105. sleep 1
  106. yellowMessage "You're using Installer $Instversion"
  107.  
  108. # selection menu if the installer should install, update, remove or pw reset the SinusBot
  109. redMessage "What should the Installer do?"
  110. OPTIONS=("Install" "Update" "Remove" "PW Reset" "Quit")
  111. select OPTION in "${OPTIONS[@]}"; do
  112.   case "$REPLY" in
  113.   1 | 2 | 3 | 4) break ;;
  114.   5) errorQuit ;;
  115.   *) errorContinue ;;
  116.   esac
  117. done
  118.  
  119. if [ "$OPTION" == "Install" ]; then
  120.   INSTALL="Inst"
  121. elif [ "$OPTION" == "Update" ]; then
  122.   INSTALL="Updt"
  123. elif [ "$OPTION" == "Remove" ]; then
  124.   INSTALL="Rem"
  125. elif [ "$OPTION" == "PW Reset" ]; then
  126.   INSTALL="Res"
  127. fi
  128.  
  129. # PW Reset
  130.  
  131. if [[ $INSTALL == "Res" ]]; then
  132.   yellowMessage "Automatic usage or own directories?"
  133.  
  134.   OPTIONS=("Automatic" "Own path" "Quit")
  135.   select OPTION in "${OPTIONS[@]}"; do
  136.     case "$REPLY" in
  137.     1 | 2) break ;;
  138.     3) errorQuit ;;
  139.     *) errorContinue ;;
  140.     esac
  141.   done
  142.  
  143.   if [ "$OPTION" == "Automatic" ]; then
  144.     LOCATION=/opt/sinusbot
  145.   elif [ "$OPTION" == "Own path" ]; then
  146.     yellowMessage "Enter location where the bot should be installed/updated/removed. Like /opt/sinusbot. Include the / at first position and none at the end"!
  147.  
  148.     LOCATION=""
  149.     while [[ ! -d $LOCATION ]]; do
  150.       read -rp "Location [/opt/sinusbot]: " LOCATION
  151.       if [[ $INSTALL != "Inst" && ! -d $LOCATION ]]; then
  152.         redMessage "Directory not found, try again"!
  153.       fi
  154.     done
  155.  
  156.     greenMessage "Your directory is $LOCATION."
  157.  
  158.     OPTIONS=("Yes" "No, change it" "Quit")
  159.     select OPTION in "${OPTIONS[@]}"; do
  160.       case "$REPLY" in
  161.       1 | 2) break ;;
  162.       3) errorQuit ;;
  163.       *) errorContinue ;;
  164.       esac
  165.     done
  166.  
  167.     if [ "$OPTION" == "No, change it" ]; then
  168.       LOCATION=""
  169.       while [[ ! -d $LOCATION ]]; do
  170.         read -rp "Location [/opt/sinusbot]: " LOCATION
  171.         if [[ $INSTALL != "Inst" && ! -d $LOCATION ]]; then
  172.           redMessage "Directory not found, try again"!
  173.         fi
  174.       done
  175.  
  176.       greenMessage "Your directory is $LOCATION."
  177.     fi
  178.   fi
  179.  
  180.   LOCATIONex=$LOCATION/sinusbot
  181.  
  182.   if [[ ! -f $LOCATION/sinusbot ]]; then
  183.     errorExit "SinusBot wasn't found at $LOCATION. Exiting script."
  184.   fi
  185.  
  186.   PW=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1)
  187.   SINUSBOTUSER=$(ls -ld $LOCATION | awk '{print $3}')
  188.  
  189.   greenMessage "Please login to your SinusBot webinterface as admin and '$PW'"
  190.   yellowMessage "After that change your password under Settings->User Accounts->admin->Edit. The script restart the bot with init.d or systemd."
  191.  
  192.   if [ -f /lib/systemd/system/sinusbot.service ]; then
  193.     if [[ $(systemctl is-active sinusbot >/dev/null && echo UP || echo DOWN) == "UP" ]]; then
  194.       service sinusbot stop
  195.     fi
  196.   elif [ -f /etc/init.d/sinusbot ]; then
  197.     if [ "$(/etc/init.d/sinusbot status | awk '{print $NF; exit}')" == "UP" ]; then
  198.       /etc/init.d/sinusbot stop
  199.     fi
  200.   fi
  201.  
  202.   log="/tmp/sinusbot.log"
  203.   match="USER-PATCH [admin] (admin) OK"
  204.  
  205.   su -c "$LOCATIONex --override-password $PW" $SINUSBOTUSER >"$log" 2>&1 &
  206.   sleep 3
  207.  
  208.   while true; do
  209.     echo -ne '(Waiting for password change!)\r'
  210.  
  211.     if grep -Fq "$match" "$log"; then
  212.       pkill -INT -f $PW
  213.       rm $log
  214.  
  215.       greenMessage "Successfully changed your admin password."
  216.  
  217.       if [ -f /lib/systemd/system/sinusbot.service ]; then
  218.         service sinusbot start
  219.         greenMessage "Started your bot with systemd."
  220.       elif [ -f /etc/init.d/sinusbot ]; then
  221.         /etc/init.d/sinusbot start
  222.         greenMessage "Started your bot with initd."
  223.       else
  224.         redMessage "Please start your bot normally"!
  225.       fi
  226.       exit 0
  227.     fi
  228.   done
  229.  
  230. fi
  231.  
  232. # Check which OS
  233.  
  234. if [ "$INSTALL" != "Rem" ]; then
  235.  
  236.   if [ -f /etc/centos-release ]; then
  237.     greenMessage "Installing redhat-lsb! Please wait."
  238.     yum -y -q install redhat-lsb
  239.     greenMessage "Done"!
  240.  
  241.     yellowMessage "You're running CentOS. Which firewallsystem you're using?"
  242.  
  243.     OPTIONS=("IPtables" "Firewalld")
  244.     select OPTION in "${OPTIONS[@]}"; do
  245.       case "$REPLY" in
  246.       1 | 2) break ;;
  247.       *) errorContinue ;;
  248.       esac
  249.     done
  250.  
  251.     if [ "$OPTION" == "IPtables" ]; then
  252.       FIREWALL="ip"
  253.     elif [ "$OPTION" == "Firewalld" ]; then
  254.       FIREWALL="fd"
  255.     fi
  256.   fi
  257.  
  258.   if [ -f /etc/debian_version ]; then
  259.     greenMessage "Check if lsb-release and debconf-utils is installed..."
  260.     apt-get -qq update
  261.     apt-get -qq install debconf-utils -y
  262.     apt-get -qq install lsb-release -y
  263.     greenMessage "Done"!
  264.   fi
  265.  
  266.   # Functions from lsb_release
  267.  
  268.   OS=$(lsb_release -i 2>/dev/null | grep 'Distributor' | awk '{print tolower($3)}')
  269.   OSBRANCH=$(lsb_release -c 2>/dev/null | grep 'Codename' | awk '{print $2}')
  270.   VIRTUALIZATION_TYPE=""
  271.  
  272.   # Extracted from the virt-what sourcecode: http://git.annexia.org/?p=virt-what.git;a=blob_plain;f=virt-what.in;hb=HEAD
  273.   if [ -f "/.dockerinit" ]; then
  274.     VIRTUALIZATION_TYPE="docker"
  275.   fi
  276.   if [ -d "/proc/vz" -a ! -d "/proc/bc" ]; then
  277.     VIRTUALIZATION_TYPE="openvz"
  278.   fi
  279.  
  280.   if [[ $VIRTUALIZATION_TYPE == "openvz" ]]; then
  281.     redMessage "Warning, your server running under OpenVZ! This is an very old container system and isn't well supported by newer packages."
  282.   elif [[ $VIRTUALIZATION_TYPE == "docker" ]]; then
  283.     redMessage "Warning, your server running under Docker! Maybe there are failures while installing."
  284.   fi
  285.  
  286. fi
  287.  
  288. # Go on
  289.  
  290. if [ "$INSTALL" != "Rem" ]; then
  291.   if [ -z "$OS" ]; then
  292.     errorExit "Error: Could not detect OS. Currently only Debian, Ubuntu and CentOS are supported. Aborting"!
  293.   elif [ -z "$OS" ] && ([ "$(cat /etc/debian_version | awk '{print $1}')" == "7" ] || [ $(cat /etc/debian_version | grep "7.") ]); then
  294.     errorExit "Debian 7 isn't supported anymore"!
  295.   fi
  296.  
  297.   if [ -z "$OSBRANCH" ] && [ -f /etc/centos-release ]; then
  298.     errorExit "Error: Could not detect branch of OS. Aborting"
  299.   fi
  300.  
  301.   if [ "$MACHINE" == "x86_64" ]; then
  302.     ARCH="amd64"
  303.   else
  304.     errorExit "$MACHINE is not supported"!
  305.   fi
  306. fi
  307.  
  308. if [[ "$INSTALL" != "Rem" ]]; then
  309.   if [[ "$USE_SYSTEMD" == true ]]; then
  310.     yellowMessage "Automatically chosen system.d for your startscript"!
  311.   else
  312.     yellowMessage "Automatically chosen init.d for your startscript"!
  313.   fi
  314. fi
  315.  
  316. # Set path or continue with normal
  317.  
  318. yellowMessage "Automatic usage or own directories?"
  319.  
  320. OPTIONS=("Automatic" "Own path" "Quit")
  321. select OPTION in "${OPTIONS[@]}"; do
  322.   case "$REPLY" in
  323.   1 | 2) break ;;
  324.   3) errorQuit ;;
  325.   *) errorContinue ;;
  326.   esac
  327. done
  328.  
  329. if [ "$OPTION" == "Automatic" ]; then
  330.   LOCATION=/opt/sinusbot
  331. elif [ "$OPTION" == "Own path" ]; then
  332.   yellowMessage "Enter location where the bot should be installed/updated/removed. Like /opt/sinusbot. Include the / at first position and none at the end"!
  333.   LOCATION=""
  334.   while [[ ! -d $LOCATION ]]; do
  335.     read -rp "Location [/opt/sinusbot]: " LOCATION
  336.     if [[ $INSTALL != "Inst" && ! -d $LOCATION ]]; then
  337.       redMessage "Directory not found, try again"!
  338.     fi
  339.     if [ "$INSTALL" == "Inst" ]; then
  340.       if [ "$LOCATION" == "" ]; then
  341.         LOCATION=/opt/sinusbot
  342.       fi
  343.       makeDir $LOCATION
  344.     fi
  345.   done
  346.  
  347.   greenMessage "Your directory is $LOCATION."
  348.  
  349.   OPTIONS=("Yes" "No, change it" "Quit")
  350.   select OPTION in "${OPTIONS[@]}"; do
  351.     case "$REPLY" in
  352.     1 | 2) break ;;
  353.     3) errorQuit ;;
  354.     *) errorContinue ;;
  355.     esac
  356.   done
  357.  
  358.   if [ "$OPTION" == "No, change it" ]; then
  359.     LOCATION=""
  360.     while [[ ! -d $LOCATION ]]; do
  361.       read -rp "Location [/opt/sinusbot]: " LOCATION
  362.       if [[ $INSTALL != "Inst" && ! -d $LOCATION ]]; then
  363.         redMessage "Directory not found, try again"!
  364.       fi
  365.       if [ "$INSTALL" == "Inst" ]; then
  366.         makeDir $LOCATION
  367.       fi
  368.     done
  369.  
  370.     greenMessage "Your directory is $LOCATION."
  371.   fi
  372. fi
  373.  
  374. makeDir $LOCATION
  375.  
  376. LOCATIONex=$LOCATION/sinusbot
  377.  
  378. # Check if SinusBot already installed and if update is possible
  379.  
  380. if [[ $INSTALL == "Inst" ]] || [[ $INSTALL == "Updt" ]]; then
  381.  
  382. yellowMessage "Should I install TeamSpeak or only Discord Mode?"
  383.  
  384. OPTIONS=("Both" "Only Discord" "Quit")
  385. select OPTION in "${OPTIONS[@]}"; do
  386.   case "$REPLY" in
  387.   1 | 2) break ;;
  388.   3) errorQuit ;;
  389.   *) errorContinue ;;
  390.   esac
  391. done
  392.  
  393. if [ "$OPTION" == "Both" ]; then
  394.   DISCORD="false"
  395. else
  396.   DISCORD="true"
  397. fi
  398. fi
  399.  
  400. if [[ $INSTALL == "Inst" ]]; then
  401.  
  402.   if [[ -f $LOCATION/sinusbot ]]; then
  403.     redMessage "SinusBot already installed with automatic install option"!
  404.     read -rp "Would you like to update the bot instead? [Y / N]: " OPTION
  405.  
  406.     if [ "$OPTION" == "Y" ] || [ "$OPTION" == "y" ] || [ "$OPTION" == "" ]; then
  407.       INSTALL="Updt"
  408.     elif [ "$OPTION" == "N" ] || [ "$OPTION" == "n" ]; then
  409.       errorExit "Installer stops now"!
  410.     fi
  411.   else
  412.     greenMessage "SinusBot isn't installed yet. Installer goes on."
  413.   fi
  414.  
  415. elif [ "$INSTALL" == "Rem" ] || [ "$INSTALL" == "Updt" ]; then
  416.   if [ ! -d $LOCATION ]; then
  417.     errorExit "SinusBot isn't installed"!
  418.   else
  419.     greenMessage "SinusBot is installed. Installer goes on."
  420.   fi
  421. fi
  422.  
  423. # Remove SinusBot
  424.  
  425. if [ "$INSTALL" == "Rem" ]; then
  426.  
  427.   SINUSBOTUSER=$(ls -ld $LOCATION | awk '{print $3}')
  428.  
  429.   if [ -f /usr/local/bin/youtube-dl ]; then
  430.     redMessage "Remove YoutubeDL?"
  431.  
  432.     OPTIONS=("Yes" "No")
  433.     select OPTION in "${OPTIONS[@]}"; do
  434.       case "$REPLY" in
  435.       1 | 2) break ;;
  436.       *) errorContinue ;;
  437.       esac
  438.     done
  439.  
  440.     if [ "$OPTION" == "Yes" ]; then
  441.       if [ -f /usr/local/bin/youtube-dl ]; then
  442.         rm /usr/local/bin/youtube-dl
  443.       fi
  444.  
  445.       if [ -f /etc/cron.d/ytdl ]; then
  446.         rm /etc/cron.d/ytdl
  447.       fi
  448.  
  449.       greenMessage "Removed YT-DL successfully"!
  450.     fi
  451.   fi
  452.  
  453.   if [[ -z $SINUSBOTUSER ]]; then
  454.     errorExit "No SinusBot found. Exiting now."
  455.   fi
  456.  
  457.   redMessage "SinusBot will now be removed completely from your system"!
  458.  
  459.   greenMessage "Your SinusBot user is \"$SINUSBOTUSER\"? After select Yes it could take a while."
  460.  
  461.   OPTIONS=("Yes" "No")
  462.   select OPTION in "${OPTIONS[@]}"; do
  463.     case "$REPLY" in
  464.     1) break ;;
  465.     2) errorQuit ;;
  466.     *) errorContinue ;;
  467.     esac
  468.   done
  469.  
  470.   if [ "$(ps ax | grep sinusbot | grep SCREEN)" ]; then
  471.     ps ax | grep sinusbot | grep SCREEN | awk '{print $1}' | while read PID; do
  472.       kill $PID
  473.     done
  474.   fi
  475.  
  476.   if [ "$(ps ax | grep ts3bot | grep SCREEN)" ]; then
  477.     ps ax | grep ts3bot | grep SCREEN | awk '{print $1}' | while read PID; do
  478.       kill $PID
  479.     done
  480.   fi
  481.  
  482.   if [ -f /lib/systemd/system/sinusbot.service ]; then
  483.     if [[ $(systemctl is-active sinusbot >/dev/null && echo UP || echo DOWN) == "UP" ]]; then
  484.       service sinusbot stop
  485.       systemctl disable sinusbot
  486.     fi
  487.     rm /lib/systemd/system/sinusbot.service
  488.   elif [ -f /etc/init.d/sinusbot ]; then
  489.     if [ "$(/etc/init.d/sinusbot status | awk '{print $NF; exit}')" == "UP" ]; then
  490.       su -c "/etc/init.d/sinusbot stop" $SINUSBOTUSER
  491.       su -c "screen -wipe" $SINUSBOTUSER
  492.       update-rc.d -f sinusbot remove >/dev/null
  493.     fi
  494.     rm /etc/init.d/sinusbot
  495.   fi
  496.  
  497.   if [ -f /etc/cron.d/sinusbot ]; then
  498.     rm /etc/cron.d/sinusbot
  499.   fi
  500.  
  501.   if [ "$LOCATION" ]; then
  502.     rm -R $LOCATION >/dev/null
  503.     greenMessage "Files removed successfully"!
  504.   else
  505.     redMessage "Error while removing files."
  506.   fi
  507.  
  508.   if [[ $SINUSBOTUSER != "root" ]]; then
  509.     redMessage "Remove user \"$SINUSBOTUSER\"?"
  510.  
  511.     OPTIONS=("Yes" "No")
  512.     select OPTION in "${OPTIONS[@]}"; do
  513.       case "$REPLY" in
  514.       1 | 2) break ;;
  515.       *) errorContinue ;;
  516.       esac
  517.     done
  518.  
  519.     if [ "$OPTION" == "Yes" ]; then
  520.       userdel -r -f $SINUSBOTUSER >/dev/null
  521.  
  522.       if [ "$(id $SINUSBOTUSER 2>/dev/null)" == "" ]; then
  523.         greenMessage "User removed successfully"!
  524.       else
  525.         redMessage "Error while removing user"!
  526.       fi
  527.     fi
  528.   fi
  529.  
  530.   greenMessage "SinusBot removed completely including all directories."
  531.  
  532.   exit 0
  533. fi
  534.  
  535. # Private usage only!
  536.  
  537. redMessage "This SinusBot version is only for private use! Accept?"
  538.  
  539. OPTIONS=("No" "Yes")
  540. select OPTION in "${OPTIONS[@]}"; do
  541.   case "$REPLY" in
  542.   1) errorQuit ;;
  543.   2) break ;;
  544.   *) errorContinue ;;
  545.   esac
  546. done
  547.  
  548. # Ask for YT-DL
  549.  
  550. redMessage "Should YT-DL be installed/updated?"
  551. OPTIONS=("Yes" "No")
  552. select OPTION in "${OPTIONS[@]}"; do
  553.   case "$REPLY" in
  554.   1 | 2) break ;;
  555.   *) errorContinue ;;
  556.   esac
  557. done
  558.  
  559. if [ "$OPTION" == "Yes" ]; then
  560.   YT="Yes"
  561. fi
  562.  
  563. # Update packages or not
  564.  
  565. redMessage 'Update the system packages to the latest version? Recommended, as otherwise dependencies might break! Option "No" will exit the installer'
  566.  
  567. OPTIONS=("Yes" "No")
  568. select OPTION in "${OPTIONS[@]}"; do
  569.   case "$REPLY" in
  570.   1) break ;;
  571.   2) errorQuit ;;
  572.   *) errorContinue ;;
  573.   esac
  574. done
  575.  
  576. greenMessage "Starting the installer now"!
  577. sleep 2
  578.  
  579. if [ "$OPTION" == "Yes" ]; then
  580.   greenMessage "Updating the system in a few seconds"!
  581.   sleep 1
  582.   redMessage "This could take a while. Please wait up to 10 minutes"!
  583.   sleep 3
  584.  
  585.   if [ -f /etc/centos-release ]; then
  586.     yum -y -q update
  587.     yum -y -q upgrade
  588.   else
  589.     apt-get -qq update
  590.     apt-get -qq upgrade
  591.   fi
  592. fi
  593.  
  594. # TeamSpeak3-Client latest check || Deactivated till botupdate
  595.  
  596. if [ "$DISCORD" == "false" ]; then
  597.  
  598. greenMessage "Searching latest TS3-Client build for hardware type $MACHINE with arch $ARCH."
  599.  
  600. for VERSION in $(wget -q -O - http://dl.4players.de/ts/releases/ | grep -Po '(?<=href=")[0-9]+(\.[0-9]+){2,3}(?=/")' | sort -Vr | head -1); do
  601.   DOWNLOAD_URL_VERSION="http://dl.4players.de/ts/releases/$VERSION/TeamSpeak3-Client-linux_$ARCH-$VERSION.run"
  602.   STATUS=$(wget --server-response -L $DOWNLOAD_URL_VERSION 2>&1 | awk '/^  HTTP/{print $2}')
  603.   if [ "$STATUS" == "200" ]; then
  604.     DOWNLOAD_URL=$DOWNLOAD_URL_VERSION
  605.     break
  606.   fi
  607. done
  608.  
  609. if [ "$STATUS" == "200" -a "$DOWNLOAD_URL" != "" ]; then
  610.   greenMessage "Detected latest TS3-Client version as $VERSION"
  611. else
  612.   errorExit "Could not detect latest TS3-Client version"
  613. fi
  614.  
  615. # Install necessary aptitudes for sinusbot.
  616.  
  617. magentaMessage "Installing necessary packages. Please wait..."
  618.  
  619. if [ -f /etc/centos-release ]; then
  620.   yum -y -q install screen x11vnc xvfb libxcursor1 ca-certificates bzip2 psmisc libglib2.0-0 less cron-apt ntp python iproute which dbus libnss3 libegl1-mesa x11-xkb-utils libasound2 >/dev/null
  621.   update-ca-trust extract >/dev/null
  622. else
  623.   apt-get -y -qq install screen x11vnc xvfb libxcursor1 ca-certificates bzip2 psmisc libglib2.0-0 less cron-apt ntp python iproute2 dbus libnss3 libegl1-mesa x11-xkb-utils libasound2 libxcomposite-dev libxi6 >/dev/null
  624.   update-ca-certificates >/dev/null
  625. fi
  626.  
  627. else
  628.  
  629. magentaMessage "Installing necessary packages. Please wait..."
  630.  
  631. if [ -f /etc/centos-release ]; then
  632.   yum -y -q install ca-certificates bzip2 python wget >/dev/null
  633.   update-ca-trust extract >/dev/null
  634. else
  635.   apt-get -qq install ca-certificates bzip2 python wget -y >/dev/null
  636.   update-ca-certificates >/dev/null
  637. fi
  638.  
  639. fi
  640.  
  641. greenMessage "Packages installed"!
  642.  
  643. # Setting server time
  644.  
  645. if [[ $VIRTUALIZATION_TYPE == "openvz" ]]; then
  646.   redMessage "You're using OpenVZ virtualization. You can't set your time, maybe it works but there is no guarantee. Skipping this part..."
  647. else
  648.   if [ -f /etc/centos-release ]; then
  649.     service ntpd stop
  650.     ntpd -s 0.pool.ntp.org
  651.     service ntpd start
  652.     TIME=$(date)
  653.     greenMessage "Automatically set time to" $TIME!
  654.   else
  655.     if [[ $(command -v timedatectl) != "" ]]; then
  656.       service ntp restart
  657.       timedatectl set-ntp yes
  658.       timedatectl
  659.       TIME=$(date)
  660.       greenMessage "Automatically set time to" $TIME!
  661.     else
  662.       redMessage "Unable to configure your date automatically, the installation will still be attempted."
  663.     fi
  664.   fi
  665. fi
  666.  
  667. USERADD=$(which useradd)
  668. GROUPADD=$(which groupadd)
  669. ipaddress=$(ip route get 8.8.8.8 | awk '{print $NF; exit}')
  670.  
  671. # Create/check user for sinusbot.
  672.  
  673. if [ "$INSTALL" == "Updt" ]; then
  674.   SINUSBOTUSER=$(ls -ld $LOCATION | awk '{print $3}')
  675.   if [ "$DISCORD" == "false" ]; then
  676.     sed -i "s|TS3Path = \"\"|TS3Path = \"$LOCATION/teamspeak3-client/ts3client_linux_amd64\"|g" $LOCATION/config.ini && greenMessage "Added TS3 Path to config." || redMessage "Error while updating config"
  677.   fi
  678. else
  679.  
  680.   cyanMessage 'Please enter the name of the sinusbot user. Typically "sinusbot". If it does not exists, the installer will create it.'
  681.  
  682.   SINUSBOTUSER=""
  683.   while [[ ! $SINUSBOTUSER ]]; do
  684.     read -rp "Username [sinusbot]: " SINUSBOTUSER
  685.     if [ -z "$SINUSBOTUSER" ]; then
  686.       SINUSBOTUSER=sinusbot
  687.     fi
  688.     if [ -n "$SINUSBOTUSER" ]; then
  689.       greenMessage "Your sinusbot user is: $SINUSBOTUSER"
  690.     fi
  691.   done
  692.  
  693.   if [ "$(id $SINUSBOTUSER 2>/dev/null)" == "" ]; then
  694.     if [ -d /home/$SINUSBOTUSER ]; then
  695.       $GROUPADD $SINUSBOTUSER
  696.       $USERADD -d /home/$SINUSBOTUSER -s /bin/bash -g $SINUSBOTUSER $SINUSBOTUSER
  697.     else
  698.       $GROUPADD $SINUSBOTUSER
  699.       $USERADD -m -b /home -s /bin/bash -g $SINUSBOTUSER $SINUSBOTUSER
  700.     fi
  701.   else
  702.     greenMessage "User \"$SINUSBOTUSER\" already exists."
  703.   fi
  704.  
  705. chmod 750 -R $LOCATION
  706. chown -R $SINUSBOTUSER:$SINUSBOTUSER $LOCATION
  707.  
  708. fi
  709.  
  710. # Create dirs or remove them.
  711.  
  712. ps -u $SINUSBOTUSER | grep ts3client | awk '{print $1}' | while read PID; do
  713.   kill $PID
  714. done
  715. if [[ -f $LOCATION/ts3client_startscript.run ]]; then
  716.   rm -rf $LOCATION/*
  717. fi
  718.  
  719. if [ "$DISCORD" == "false" ]; then
  720.  
  721. makeDir $LOCATION/teamspeak3-client
  722.  
  723. chmod 750 -R $LOCATION
  724. chown -R $SINUSBOTUSER:$SINUSBOTUSER $LOCATION
  725. cd $LOCATION/teamspeak3-client
  726.  
  727. # Downloading TS3-Client files.
  728.  
  729. if [ -f CHANGELOG ] && [ $(cat CHANGELOG | awk '/Client Release/{ print $4; exit }') == $VERSION ]; then
  730.   greenMessage "TS3 already latest version."
  731. else
  732.  
  733.   greenMessage "Downloading TS3 client files."
  734.   su -c "wget -q $DOWNLOAD_URL" $SINUSBOTUSER
  735.  
  736.   if [[ ! -f TeamSpeak3-Client-linux_$ARCH-$VERSION.run && ! -f ts3client_linux_$ARCH ]]; then
  737.     errorExit "Download failed! Exiting now"!
  738.   fi
  739. fi
  740.  
  741. # Installing TS3-Client.
  742.  
  743. if [ -f TeamSpeak3-Client-linux_$ARCH-$VERSION.run ]; then
  744.   greenMessage "Installing the TS3 client."
  745.   redMessage "Read the eula"!
  746.   sleep 1
  747.   yellowMessage 'Do the following: Press "ENTER" then press "q" after that press "y" and accept it with another "ENTER".'
  748.   sleep 2
  749.  
  750.   chmod 777 ./TeamSpeak3-Client-linux_$ARCH-$VERSION.run
  751.  
  752.   su -c "./TeamSpeak3-Client-linux_$ARCH-$VERSION.run" $SINUSBOTUSER
  753.  
  754.   cp -R ./TeamSpeak3-Client-linux_$ARCH/* ./
  755.   sleep 2
  756.   rm ./ts3client_runscript.sh
  757.   rm ./TeamSpeak3-Client-linux_$ARCH-$VERSION.run
  758.   rm -R ./TeamSpeak3-Client-linux_$ARCH
  759.  
  760.   greenMessage "TS3 client install done."
  761. fi
  762. fi
  763.  
  764. # Downloading latest SinusBot.
  765.  
  766. cd $LOCATION
  767.  
  768. greenMessage "Downloading latest SinusBot."
  769.  
  770. su -c "wget -q https://www.sinusbot.com/dl/sinusbot.current.tar.bz2" $SINUSBOTUSER
  771. if [[ ! -f sinusbot.current.tar.bz2 && ! -f sinusbot ]]; then
  772.   errorExit "Download failed! Exiting now"!
  773. fi
  774.  
  775. # Installing latest SinusBot.
  776.  
  777. greenMessage "Extracting SinusBot files."
  778. su -c "tar -xjf sinusbot.current.tar.bz2" $SINUSBOTUSER
  779. rm -f sinusbot.current.tar.bz2
  780.  
  781. if [ "$DISCORD" == "false" ]; then
  782.  
  783. if [ ! -d teamspeak3-client/plugins/ ]; then
  784.   mkdir teamspeak3-client/plugins/
  785. fi
  786.  
  787. # Copy the SinusBot plugin into the teamspeak clients plugin directory
  788. cp $LOCATION/plugin/libsoundbot_plugin.so $LOCATION/teamspeak3-client/plugins/
  789.  
  790. if [ -f teamspeak3-client/xcbglintegrations/libqxcb-glx-integration.so ]; then
  791.   rm teamspeak3-client/xcbglintegrations/libqxcb-glx-integration.so
  792. fi
  793. fi
  794.  
  795. chmod 755 sinusbot
  796.  
  797. if [ "$INSTALL" == "Inst" ]; then
  798.   greenMessage "SinusBot installation done."
  799. elif [ "$INSTALL" == "Updt" ]; then
  800.   greenMessage "SinusBot update done."
  801. fi
  802.  
  803. if [[ "$USE_SYSTEMD" == true ]]; then
  804.  
  805.   greenMessage "Starting systemd installation"
  806.  
  807.   if [ -f /etc/systemd/system/sinusbot.service ]; then
  808.     service sinusbot stop
  809.     systemctl disable sinusbot
  810.     rm /etc/systemd/system/sinusbot.service
  811.   fi
  812.  
  813.   cd /lib/systemd/system/
  814.  
  815.   wget -q https://raw.githubusercontent.com/Sinusbot/linux-startscript/master/sinusbot.service
  816.  
  817.   if [ ! -f sinusbot.service ]; then
  818.     errorExit "Download failed! Exiting now"!
  819.   fi
  820.  
  821.   sed -i 's/User=YOUR_USER/User='$SINUSBOTUSER'/g' /lib/systemd/system/sinusbot.service
  822.   sed -i 's!ExecStart=YOURPATH_TO_THE_BOT_BINARY!ExecStart='$LOCATIONex'!g' /lib/systemd/system/sinusbot.service
  823.   sed -i 's!WorkingDirectory=YOURPATH_TO_THE_BOT_DIRECTORY!WorkingDirectory='$LOCATION'!g' /lib/systemd/system/sinusbot.service
  824.  
  825.   systemctl daemon-reload
  826.   systemctl enable sinusbot.service
  827.  
  828.   greenMessage 'Installed systemd file to start the SinusBot with "service sinusbot {start|stop|status|restart}"'
  829.  
  830. elif [[ "$USE_SYSTEMD" == false ]]; then
  831.  
  832.   greenMessage "Starting init.d installation"
  833.  
  834.   cd /etc/init.d/
  835.  
  836.   wget -q https://raw.githubusercontent.com/Sinusbot/linux-startscript/obsolete-init.d/sinusbot
  837.  
  838.   if [ ! -f sinusbot ]; then
  839.     errorExit "Download failed! Exiting now"!
  840.   fi
  841.  
  842.   sed -i 's/USER="mybotuser"/USER="'$SINUSBOTUSER'"/g' /etc/init.d/sinusbot
  843.   sed -i 's!DIR_ROOT="/opt/ts3soundboard/"!DIR_ROOT="'$LOCATION'/"!g' /etc/init.d/sinusbot
  844.  
  845.   chmod +x /etc/init.d/sinusbot
  846.  
  847.   if [ -f /etc/centos-release ]; then
  848.     chkconfig sinusbot on >/dev/null
  849.   else
  850.     update-rc.d sinusbot defaults >/dev/null
  851.   fi
  852.  
  853.   greenMessage 'Installed init.d file to start the SinusBot with "/etc/init.d/sinusbot {start|stop|status|restart|console|update|backup}"'
  854. fi
  855.  
  856. cd $LOCATION
  857.  
  858. if [ "$INSTALL" == "Inst" ]; then
  859.   if [ "$DISCORD" == "false" ]; then
  860.     if [[ ! -f $LOCATION/config.ini ]]; then
  861.       echo 'ListenPort = 8087
  862.       ListenHost = "0.0.0.0"
  863.       TS3Path = "'$LOCATION'/teamspeak3-client/ts3client_linux_amd64"
  864.       YoutubeDLPath = ""' >>$LOCATION/config.ini
  865.       greenMessage "config.ini created successfully."
  866.     else
  867.       redMessage "config.ini already exists or creation error"!
  868.     fi
  869.   else
  870.     if [[ ! -f $LOCATION/config.ini ]]; then
  871.       echo 'ListenPort = 8087
  872.       ListenHost = "0.0.0.0"
  873.       TS3Path = ""
  874.       YoutubeDLPath = ""' >>$LOCATION/config.ini
  875.       greenMessage "config.ini created successfully."
  876.     else
  877.       redMessage "config.ini already exists or creation error"!
  878.     fi
  879.   fi
  880. fi
  881.  
  882. if [[ -f /etc/cron.d/sinusbot ]]; then
  883.   redMessage "Cronjob already set for SinusBot updater"!
  884. else
  885.   greenMessage "Installing Cronjob for automatic SinusBot update..."
  886.   echo "0 0 * * * $SINUSBOTUSER $LOCATION/sinusbot -update >/dev/null" >>/etc/cron.d/sinusbot
  887.   greenMessage "Installing SinusBot update cronjob successful."
  888. fi
  889.  
  890. # Installing YT-DL.
  891.  
  892. if [ "$YT" == "Yes" ]; then
  893.   greenMessage "Installing YT-Downloader now"!
  894.   if [ -f /etc/cron.d/ytdl ] && [ "$(grep -c 'youtube' /etc/cron.d/ytdl)" -ge 1 ]; then
  895.     redMessage "Cronjob already set for YT-DL updater"!
  896.   else
  897.     greenMessage "Installing Cronjob for automatic YT-DL update..."
  898.     echo "0 0 * * * $SINUSBOTUSER youtube-dl -U --restrict-filename >/dev/null" >>/etc/cron.d/ytdl
  899.     greenMessage "Installing Cronjob successful."
  900.   fi
  901.  
  902.   sed -i 's/YoutubeDLPath = \"\"/YoutubeDLPath = \"\/usr\/local\/bin\/youtube-dl\"/g' $LOCATION/config.ini
  903.  
  904.   if [ -f /usr/local/bin/youtube-dl ]; then
  905.     rm /usr/local/bin/youtube-dl
  906.   fi
  907.  
  908.   greenMessage "Downloading YT-DL now..."
  909.   wget -q -O /usr/local/bin/youtube-dl http://yt-dl.org/downloads/latest/youtube-dl
  910.  
  911.   if [ ! -f /usr/local/bin/youtube-dl ]; then
  912.     errorExit "Download failed! Exiting now"!
  913.   else
  914.     greenMessage "Download successful"!
  915.   fi
  916.  
  917.   chmod a+rx /usr/local/bin/youtube-dl
  918.  
  919.   youtube-dl -U --restrict-filename
  920.  
  921. fi
  922.  
  923. # Creating Readme
  924.  
  925. if [ ! -a "$LOCATION/README_installer.txt" ] && [ "$USE_SYSTEMD" == true ]; then
  926.   echo '##################################################################################
  927. # #
  928. # Usage: service sinusbot {start|stop|status|restart} #
  929. # - start: start the bot #
  930. # - stop: stop the bot #
  931. # - status: display the status of the bot (down or up) #
  932. # - restart: restart the bot #
  933. # #
  934. ##################################################################################' >>$LOCATION/README_installer.txt
  935. elif [ ! -a "$LOCATION/README_installer.txt" ] && [ "$USE_SYSTEMD" == false ]; then
  936.   echo '##################################################################################
  937.   # #
  938.   # Usage: /etc/init.d/sinusbot {start|stop|status|restart|console|update|backup} #
  939.   # - start: start the bot #
  940.   # - stop: stop the bot #
  941.   # - status: display the status of the bot (down or up) #
  942.   # - restart: restart the bot #
  943.   # - console: display the bot console #
  944.   # - update: runs the bot updater (with start & stop)
  945.   # - backup: archives your bot root directory
  946.   # To exit the console without stopping the server, press CTRL + A then D. #
  947.   # #
  948.   ##################################################################################' >>$LOCATION/README_installer.txt
  949. fi
  950.  
  951. greenMessage "Generated README_installer.txt"!
  952.  
  953. # Delete files if exists
  954.  
  955. if [ -f /tmp/.sinusbot.lock ]; then
  956.   rm /tmp/.sinusbot.lock
  957.   greenMessage "Deleted /tmp/.sinusbot.lock"
  958. fi
  959.  
  960. if [ -e /tmp/.X11-unix/X40 ]; then
  961.   rm /tmp/.X11-unix/X40
  962.   greenMessage "Deleted /tmp/.X11-unix/X40"
  963. fi
  964.  
  965. # Starting SinusBot first time!
  966.  
  967. if [ "$INSTALL" != "Updt" ]; then
  968.   greenMessage 'Starting the SinusBot. For first time.'
  969.   chown -R $SINUSBOTUSER:$SINUSBOTUSER $LOCATION
  970.   cd $LOCATION
  971.  
  972.   # Password variable
  973.  
  974.   export Q=$(su $SINUSBOTUSER -c './sinusbot --initonly')
  975.   password=$(export | awk '/password/{ print $10 }' | tr -d "'")
  976.   if [ -z "$password" ]; then
  977.     errorExit "Failed to read password, try a reinstall again."
  978.   fi
  979.  
  980.   chown -R $SINUSBOTUSER:$SINUSBOTUSER $LOCATION
  981.  
  982.   # Starting bot
  983.   greenMessage "Starting SinusBot again."
  984. fi
  985.  
  986. if [[ "$USE_SYSTEMD" == true ]]; then
  987.   service sinusbot start
  988. elif [[ "$USE_SYSTEMD" == false ]]; then
  989.   /etc/init.d/sinusbot start
  990. fi
  991. yellowMessage "Please wait... This will take some seconds"!
  992. chown -R $SINUSBOTUSER:$SINUSBOTUSER $LOCATION
  993.  
  994. if [[ "$USE_SYSTEMD" == true ]]; then
  995.   sleep 5
  996. elif [[ "$USE_SYSTEMD" == false ]]; then
  997.   sleep 10
  998. fi
  999.  
  1000. if [ -f /etc/centos-release ]; then
  1001.   if [ "$FIREWALL" == "ip" ]; then
  1002.     iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 8087 -j ACCEPT
  1003.   elif [ "$FIREWALL" == "fs" ]; then
  1004.     if rpm -q --quiet firewalld; then
  1005.       zone=$(firewall-cmd --get-active-zones | awk '{print $1; exit}')
  1006.       firewall-cmd --zone=$zone --add-port=8087/tcp --permanent >/dev/null
  1007.       firewall-cmd --reload >/dev/null
  1008.     fi
  1009.   fi
  1010. fi
  1011.  
  1012. # If startup failed, the script will start normal sinusbot without screen for looking about errors. If startup successed => installation done.
  1013. IS_RUNNING=false
  1014. if [[ "$USE_SYSTEMD" == true ]]; then
  1015.   if [[ $(systemctl is-active sinusbot >/dev/null && echo UP || echo DOWN) == "UP" ]]; then
  1016.     IS_RUNNING=true
  1017.   fi
  1018. elif [[ "$USE_SYSTEMD" == false ]]; then
  1019.   if [[ $(/etc/init.d/sinusbot status | awk '{print $NF; exit}') == "UP" ]]; then
  1020.      IS_RUNNING=true
  1021.   fi
  1022. fi
  1023.  
  1024. if [[ "$IS_RUNNING" == true ]]; then
  1025.   if [[ $INSTALL == "Inst" ]]; then
  1026.     greenMessage "Install done"!
  1027.   elif [[ $INSTALL == "Updt" ]]; then
  1028.     greenMessage "Update done"!
  1029.   fi
  1030.  
  1031.   if [[ ! -f $LOCATION/README_installer.txt ]]; then
  1032.     yellowMessage "Generated a README_installer.txt in $LOCATION with all commands for the sinusbot..."
  1033.   fi
  1034.  
  1035.   if [[ $INSTALL == "Updt" ]]; then
  1036.     if [ -f /lib/systemd/system/sinusbot.service ]; then
  1037.       service sinusbot restart
  1038.       greenMessage "Restarted your bot with systemd."
  1039.     fi
  1040.     if [ -f /etc/init.d/sinusbot ]; then
  1041.       /etc/init.d/sinusbot restart
  1042.       greenMessage "Restarted your bot with initd."
  1043.     fi
  1044.     greenMessage "All right. Everything is updated successfully. SinusBot is UP on '$ipaddress:8087' :)"
  1045.   else
  1046.     greenMessage "All right. Everything is installed successfully. SinusBot is UP on '$ipaddress:8087' :) Your user = 'admin' and password = '$password'"
  1047.   fi
  1048.   if [[ "$USE_SYSTEMD" == true ]]; then
  1049.     redMessage 'Stop it with "service sinusbot stop".'
  1050.   elif [[ "$USE_SYSTEMD" == false ]]; then
  1051.     redMessage 'Stop it with "/etc/init.d/sinusbot stop".'
  1052.   fi
  1053.   magentaMessage "Don't forget to rate this script on: https://forum.sinusbot.com/resources/sinusbot-installer-script.58/"
  1054.   greenMessage "Thank you for using this script! :)"
  1055.  
  1056. else
  1057.   redMessage "SinusBot could not start! Starting it directly. Look for errors"!
  1058.   su -c "$LOCATION/sinusbot" $SINUSBOTUSER
  1059. fi
  1060.  
  1061. 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