Advertisement
Guest User

sinusbot

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