Advertisement
Guest User

sinusbot error

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