Advertisement
Guest User

Untitled

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