Advertisement
Guest User

Untitled

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