Advertisement
Guest User

Untitled

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