Advertisement
Guest User

Untitled

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