Guest User

Untitled

a guest
Jun 30th, 2016
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.26 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. USERADD=`which useradd`
  7. USERMOD=`which usermod`
  8. USERDEL=`which userdel`
  9. GROUPADD=`which groupadd`
  10. MACHINE=`uname -m`
  11. OS=`lsb_release -i 2> /dev/null | grep 'Distributor' | awk '{print tolower($3)}'`
  12. OSVERSION=`lsb_release -r 2> /dev/null | grep 'Release' | awk '{print $2}'`
  13. OSBRANCH=`lsb_release -c 2> /dev/null | grep 'Codename' | awk '{print $2}'`
  14. ipaddress=`ip route get 8.8.8.8 | awk '{print $NF; exit}'`
  15. chengedir=`echo $PWD`
  16. pwgen=`date +%s | sha256sum | base64 | head -c 6 ; echo`
  17.  
  18. # Functions
  19.  
  20. function test {
  21. "$@"
  22. local status=$?
  23. if [ $status -ne 0 ]; then
  24. redMessage "Password doesn't match. Try again, change user or exit?"
  25. OPTIONS=("Try again" "Change User" "Exit")
  26. select OPTION in "${OPTIONS[@]}"; do
  27. case "$REPLY" in
  28. 1|2 ) break;;
  29. 3 ) errorQuit;;
  30. *) errorContinue;;
  31. esac
  32. done
  33.  
  34. if [ "$OPTION" == "Try again" ]; then
  35. cyanMessage "Type new password."
  36.  
  37. test passwd $SINUSBOTUSER
  38.  
  39. elif [ "$OPTION" == "Change User" ]; then
  40. cyanMessage 'Please enter the name of the sinusbot user. Typically "sinusbot". If it does not exists, the installer will create it.'
  41.  
  42. read SINUSBOTUSER
  43.  
  44. if [ "$SINUSBOTUSER" == "" ]; then
  45. errorExit "Fatal Error: No sinusbot user specified"
  46.  
  47. fi
  48.  
  49. if [ "`id $SINUSBOTUSER 2> /dev/null`" == "" ]; then
  50. if [ -d /home/$SINUSBOTUSER ]; then
  51. $GROUPADD $SINUSBOTUSER
  52. $USERADD -d /home/$SINUSBOTUSER -s /bin/bash -g $SINUSBOTUSER $SINUSBOTUSER
  53. else
  54. $GROUPADD $SINUSBOTUSER
  55. $USERADD -m -b /home -s /bin/bash -g $SINUSBOTUSER $SINUSBOTUSER
  56.  
  57. fi
  58. else
  59. greenMessage "User \"$SINUSBOTUSER\" already exists."
  60.  
  61. fi
  62. fi
  63.  
  64. fi
  65. return $status
  66. }
  67.  
  68. function greenMessage {
  69. echo -e "\\033[32;1m${@}\033[0m"
  70. }
  71.  
  72. function magentaMessage {
  73. echo -e "\\033[35;1m${@}\033[0m"
  74. }
  75.  
  76. function cyanMessage {
  77. echo -e "\\033[36;1m${@}\033[0m"
  78. }
  79.  
  80. function redMessage {
  81. echo -e "\\033[31;1m${@}\033[0m"
  82. }
  83.  
  84. function yellowMessage {
  85. echo -e "\\033[33;1m${@}\033[0m"
  86. }
  87.  
  88. function errorQuit {
  89. errorExit "Exit now!"
  90. }
  91.  
  92. function errorExit {
  93. redMessage ${@}
  94. exit 0
  95. }
  96.  
  97. function errorContinue {
  98. redMessage "Invalid option."
  99. return
  100. }
  101.  
  102. function makeDir {
  103. if [ "$1" != "" -a ! -d $1 ]; then
  104. mkdir -p $1
  105. fi
  106. }
  107.  
  108. function checkInstall {
  109. if [ "`dpkg-query -s $1 2>/dev/null`" == "" ]; then
  110. greenMessage "Installing package $1"
  111. apt-get install -y $1
  112. fi
  113. }
  114.  
  115. # Must be root. Checking...
  116.  
  117. if [ "`id -u`" != "0" ]; then
  118. cyanMessage "Change to root account required"
  119. su root
  120.  
  121. fi
  122.  
  123. if [ "`id -u`" != "0" ]; then
  124. errorExit "Still not root, aborting"
  125.  
  126. fi
  127.  
  128. # Start installer
  129.  
  130. if [ -f /etc/debian_version -o -f /etc/centos-release ]; then
  131. greenMessage "This is the automatic installer for latest Sinusbot."
  132. sleep 1
  133. cyanMessage "You can choose between installing, upgrading and removing of the Sinusbot."
  134. sleep 1
  135. redMessage "Installer by Philipp Esswein | DAThosting.eu - Your game-/voiceserver hoster (only german)."
  136. sleep 1
  137. # yellowMessage "Using YT-DL and start/stop script by Xuxe."
  138. # sleep 1
  139. magentaMessage "Please rate this script on: https://forum.sinusbot.com/resources/sinusbot-installer-script.58/"
  140. sleep 1
  141. redMessage "$pwgen"
  142.  
  143. # What should be done?
  144.  
  145. redMessage "What should the Installer do?"
  146.  
  147. OPTIONS=("Install" "Update" "Remove" "Quit")
  148. select OPTION in "${OPTIONS[@]}"; do
  149. case "$REPLY" in
  150. 1|2|3 ) break;;
  151. 4 ) errorQuit;;
  152. *) errorContinue;;
  153. esac
  154. done
  155.  
  156. if [ "$OPTION" == "Install" ]; then
  157. INSTALL="Inst"
  158. elif [ "$OPTION" == "Update" ]; then
  159. INSTALL="Updt"
  160. elif [ "$OPTION" == "Remove" ]; then
  161. INSTALL="Rem"
  162.  
  163. fi
  164.  
  165. # Check if Sinusbot already installed and if update is possible
  166.  
  167. if [ "$INSTALL" == "Inst" ]; then
  168. if [ -f /opt/sinusbot/sinusbot ]; then
  169. redMessage "Sinusbot already installed!"
  170. errorQuit
  171.  
  172. fi
  173. fi
  174.  
  175. if [ "$INSTALL" != "Inst" ]; then
  176. if [ ! -f /opt/sinusbot/sinusbot ]; then
  177. redMessage "Sinusbot isn't installed!"
  178. errorQuit
  179.  
  180. fi
  181. fi
  182.  
  183. # Check which OS
  184.  
  185. if [ "$INSTALL" != "Rem" ]; then
  186.  
  187. if [ -f /etc/centos-release ]; then
  188. greenMessage "Installing redhat-lsb! Please wait."
  189. yum -y -q install redhat-lsb
  190. greenMessage "Done!"
  191. else
  192. greenMessage "Check if lsb-release and debconf-utils is installed..."
  193. checkInstall debconf-utils >/dev/null 2>&1
  194. checkInstall lsb-release >/dev/null 2>&1
  195. greenMessage "Done!"
  196.  
  197. fi
  198.  
  199. if [ "$OS" == "" ]; then
  200. if [ "$OS" == "" ]; then
  201. errorExit "Error: Could not detect OS. Currently only Debian and Ubuntu are supported. Aborting!"
  202. else
  203. greenMessage "Detected OS $OS"
  204.  
  205. fi
  206.  
  207. else
  208. greenMessage "Detected OS $OS"
  209.  
  210. fi
  211.  
  212. if [ "$OSBRANCH" == "" ]; then
  213. if [ "$OSBRANCH" == "" ]; then
  214. errorExit "Error: Could not detect branch of OS. Aborting"
  215. else
  216. greenMessage "Detected branch $OSBRANCH"
  217.  
  218. fi
  219.  
  220. else
  221. greenMessage "Detected branch $OSBRANCH"
  222.  
  223. fi
  224.  
  225. if [ "$MACHINE" == "x86_64" ]; then
  226. if [ "$MACHINE" == "x86_64" ]; then
  227. ARCH="amd64"
  228. else
  229. errorExit "$MACHINE is not supported!"
  230.  
  231. fi
  232.  
  233. else
  234. errorExit "$MACHINE is not supported!"
  235.  
  236. fi
  237.  
  238. fi
  239.  
  240. # Private usage only!
  241.  
  242. if [ "$INSTALL" != "Rem" ]; then
  243.  
  244. redMessage "This Sinusbot version is only for private usage! Accept?"
  245.  
  246. OPTIONS=("No" "Yes")
  247. select OPTION in "${OPTIONS[@]}"; do
  248. case "$REPLY" in
  249. 1 ) errorQuit;;
  250. 2 ) break;;
  251. *) errorContinue;;
  252. esac
  253. done
  254.  
  255. # Update packages or not
  256.  
  257. redMessage 'Update the system packages to the latest version? Recommended, as otherwise dependencies might brake! Option "No" = Exit'
  258.  
  259. OPTIONS=("Yes" "Try without" "No")
  260. select OPTION in "${OPTIONS[@]}"; do
  261. case "$REPLY" in
  262. 1|2 ) break;;
  263. 3 ) errorQuit;;
  264. *) errorContinue;;
  265. esac
  266. done
  267.  
  268. greenMessage "Start installer now!"
  269. sleep 2
  270.  
  271. if [ "$OPTION" == "Yes" ]; then
  272. greenMessage "Updating the system in a few seconds silently (no optical output)!"
  273. sleep 1
  274. redMessage "This could take a while. Please give it up to 10 minutes!"
  275. sleep 3
  276.  
  277. if [ -f /etc/centos-release ]; then
  278. yum -y -q update && yum -y -q install curl
  279. else
  280. apt-get -qq update && apt-get -qq upgrade -y && apt-get -qq install curl -y
  281. fi
  282.  
  283. elif [ "$OPTION" == "No" ]; then
  284. if [ -f /etc/centos-release ]; then
  285. yum -y -q install curl
  286. else
  287. apt-get -qq install curl -y
  288.  
  289. fi
  290. fi
  291. fi
  292.  
  293. fi
  294.  
  295. # Remove Sinusbot
  296.  
  297. if [ "$INSTALL" == "Rem" ]; then
  298.  
  299. redMessage "Sinusbot will now be removed completely from your system!"
  300. yellowMessage "Please enter first the Sinusbotuser!"
  301.  
  302. read SINUSBOTUSER
  303. if [ "$SINUSBOTUSER" == "" ]; then
  304. errorExit "Fatal Error: No sinusbot user specified"
  305.  
  306. fi
  307.  
  308. if [ "`id $SINUSBOTUSER 2> /dev/null`" == "" ]; then
  309. errorExit "User doesn't exist"
  310. else
  311. greenMessage "Your Sinusbotuser is \"$SINUSBOTUSER\"? After select Yes it could take a while."
  312. fi
  313.  
  314.  
  315. OPTIONS=("Yes" "No")
  316. select OPTION in "${OPTIONS[@]}"; do
  317. case "$REPLY" in
  318. 1 ) break;;
  319. 2 ) errorQuit;;
  320. *) errorContinue;;
  321. esac
  322. done
  323.  
  324. if [ "`ps ax | grep sinusbot | grep SCREEN`" ]; then
  325. ps ax | grep sinusbot | grep SCREEN | awk '{print $1}' | while read PID; do
  326. kill $PID
  327. done
  328.  
  329. fi
  330.  
  331. if [ "`ps ax | grep ts3bot | grep SCREEN`" ]; then
  332. ps ax | grep ts3bot | grep SCREEN | awk '{print $1}' | while read PID; do
  333. kill $PID
  334. done
  335.  
  336. fi
  337.  
  338. if [ -f /etc/init.d/sinusbot ]; then
  339. if [ "`/etc/init.d/sinusbot status | awk '{print $NF; exit}'`" == "UP" ]; then
  340. su -c "/etc/init.d/sinusbot stop" $SINUSBOTUSER
  341. su -c "screen -wipe" $SINUSBOTUSER
  342. update-rc.d -f sinusbot remove >/dev/null 2>&1
  343.  
  344. fi
  345. fi
  346.  
  347. grepsinusbotlocation=`find / -path /home -prune -o -name 'sinusbot' -print`
  348.  
  349. if [ "$grepsinusbotlocation" ]; then
  350. rm -R $grepsinusbotlocation >/dev/null 2>&1
  351. greenMessage "Files removed successfully!"
  352. else
  353. redMessage "Error while removing files."
  354.  
  355. fi
  356.  
  357. redMessage "Remove user \"$SINUSBOTUSER\"?"
  358.  
  359. OPTIONS=("Yes" "No")
  360. select OPTION in "${OPTIONS[@]}"; do
  361. case "$REPLY" in
  362. 1|2 ) break;;
  363. *) errorContinue;;
  364. esac
  365. done
  366.  
  367. if [ "$OPTION" == "Yes" ]; then
  368. pkill -9 -u `id -u $SINUSBOTUSER`
  369. if [ -f /etc/centos-release ]; then
  370. userdel -f --remove $SINUSBOTUSER >/dev/null 2>&1
  371. else
  372. deluser -f --remove-home $SINUSBOTUSER >/dev/null 2>&1
  373. fi
  374.  
  375. if [ "`id $SINUSBOTUSER 2> /dev/null`" == "" ]; then
  376. greenMessage "User removed successfully!"
  377. else
  378. redMessage "Error while removing user!"
  379.  
  380. fi
  381. fi
  382.  
  383. if [ -f /usr/local/bin/youtube-dl ]; then
  384. redMessage "Remove YoutubeDL?"
  385.  
  386. OPTIONS=("Yes" "No")
  387. select OPTION in "${OPTIONS[@]}"; do
  388. case "$REPLY" in
  389. 1|2 ) break;;
  390. *) errorContinue;;
  391. esac
  392. done
  393.  
  394. if [ "$OPTION" == "Yes" ]; then
  395. rm /usr/local/bin/youtube-dl
  396. greenMessage "Removed YT-DL successfully!"
  397.  
  398. fi
  399. fi
  400.  
  401. greenMessage "Sinusbot removed completely including all directorys."
  402.  
  403. fi
  404.  
  405. # TeamSpeak3-Client latest check
  406.  
  407. if [ "$INSTALL" != "Rem" ]; then
  408.  
  409. greenMessage "Searching latest TS3-Client build for hardware type $MACHINE with arch $ARCH."
  410.  
  411. 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
  412. DOWNLOAD_URL_VERSION="http://dl.4players.de/ts/releases/$VERSION/TeamSpeak3-Client-linux_$ARCH-$VERSION.run"
  413. STATUS=`curl -I $DOWNLOAD_URL_VERSION 2>&1 | grep "HTTP/" | awk '{print $2}'`
  414. if [ "$STATUS" == "200" ]; then
  415. DOWNLOAD_URL=$DOWNLOAD_URL_VERSION
  416. break
  417.  
  418. fi
  419. done
  420.  
  421. if [ "$STATUS" == "200" -a "$DOWNLOAD_URL" != "" ]; then
  422. greenMessage "Detected latest TS3-Client version as $VERSION with download URL $DOWNLOAD_URL"
  423. else
  424. errorExit "Could not detect latest TS3-Client version"
  425.  
  426. fi
  427.  
  428. # Install necessary aptitudes for sinusbot.
  429.  
  430. magentaMessage "Installing necessary packages! Please wait..."
  431.  
  432. if [ -f /etc/centos-release ]; then
  433. yum -y -q install screen x11vnc xvfb libxcursor1 ca-certificates bzip2 psmisc libglib2.0-0
  434. else
  435. apt-get -qq install screen x11vnc xvfb libxcursor1 ca-certificates bzip2 psmisc libglib2.0-0 less -y
  436. fi
  437. update-ca-certificates >/dev/null 2>&1
  438.  
  439.  
  440. greenMessage "Packages installed!"
  441.  
  442. # Create/check user for sinusbot.
  443.  
  444. cyanMessage 'Please enter the name of the sinusbot user. Typically "sinusbot". If it does not exists, the installer will create it.'
  445.  
  446. read SINUSBOTUSER
  447. if [ "$SINUSBOTUSER" == "" ]; then
  448. errorExit "Fatal Error: No sinusbot user specified"
  449.  
  450. fi
  451.  
  452. if [ "`id $SINUSBOTUSER 2> /dev/null`" == "" ]; then
  453. if [ -d /home/$SINUSBOTUSER ]; then
  454. $GROUPADD $SINUSBOTUSER
  455. $USERADD -d /home/$SINUSBOTUSER -s /bin/bash -g $SINUSBOTUSER $SINUSBOTUSER
  456. else
  457. $GROUPADD $SINUSBOTUSER
  458. $USERADD -m -b /home -s /bin/bash -g $SINUSBOTUSER $SINUSBOTUSER
  459.  
  460. fi
  461. else
  462. greenMessage "User \"$SINUSBOTUSER\" already exists."
  463.  
  464. fi
  465.  
  466. # Setting password. Recheck if success or not.
  467.  
  468. if [ "$INSTALL" == "Updt" ]; then
  469. if [ ! "`getent shadow $SINUSBOTUSER | grep '^[^:]*:.\?:' | cut -d: -f1 2> /dev/null`" == "$SINUSBOTUSER" ]; then
  470. magentaMessage "Should we change the password of \"$SINUSBOTUSER\"?"
  471. OPTIONS=("Yes" "No")
  472. select OPTION in "${OPTIONS[@]}"; do
  473. case "$REPLY" in
  474. 1|2 ) break;;
  475. *) errorContinue;;
  476. esac
  477. done
  478.  
  479. if [ "$OPTION" == "Yes" ]; then
  480. redMessage "Setting $SINUSBOTUSER password:"
  481. test passwd $SINUSBOTUSER
  482.  
  483. fi
  484.  
  485. if [ "$OPTION" == "No" ]; then
  486. yellowMessage "Doesn't change the password."
  487.  
  488. fi
  489. fi
  490. fi
  491.  
  492. if [ "$INSTALL" == "Inst" ]; then
  493. redMessage "Setting $SINUSBOTUSER password:"
  494. test passwd $SINUSBOTUSER
  495.  
  496. fi
  497.  
  498. # Create dirs or remove them.
  499.  
  500. ps -u $SINUSBOTUSER | grep ts3client | awk '{print $1}' | while read PID; do
  501. kill $PID
  502. done
  503. if [ -f /opt/sinusbot/ts3client_startscript.run ]; then
  504. rm -rf /opt/sinusbot/*
  505.  
  506. fi
  507.  
  508. makeDir /opt/sinusbot/teamspeak3-client
  509.  
  510. chmod 750 -R /opt/sinusbot
  511. chown -R $SINUSBOTUSER:$SINUSBOTUSER /opt/sinusbot
  512. cd /opt/sinusbot/teamspeak3-client
  513.  
  514. fi
  515.  
  516. # Downloading TS3-Client files.
  517.  
  518. if [ "$INSTALL" != "Rem" ]; then
  519.  
  520. if [ ! -f ts3client_linux_amd64 ]; then
  521. greenMessage "Downloading TS3 client files."
  522. su -c "curl -O -s $DOWNLOAD_URL" $SINUSBOTUSER
  523.  
  524. fi
  525.  
  526. if [ ! -f TeamSpeak3-Client-linux_$ARCH-$VERSION.run -a ! -f ts3client_linux_$ARCH ]; then
  527. errorExit "Download failed! Exiting now!"
  528.  
  529. fi
  530.  
  531. # Installing TS3-Client.
  532.  
  533. if [ -f TeamSpeak3-Client-linux_$ARCH-$VERSION.run ]; then
  534. greenMessage "Installing the TS3 client."
  535. redMessage "Read the eula!"
  536. sleep 1
  537. yellowMessage 'Do following: Press "ENTER" then press "q" after that press "y" and accept it with another "ENTER".'
  538. sleep 2
  539.  
  540. chmod 777 ./TeamSpeak3-Client-linux_$ARCH-$VERSION.run
  541.  
  542. su -c "./TeamSpeak3-Client-linux_$ARCH-$VERSION.run" $SINUSBOTUSER
  543.  
  544. cp -R ./TeamSpeak3-Client-linux_$ARCH/* ./
  545. sleep 2
  546. rm ./ts3client_runscript.sh
  547. rm ./TeamSpeak3-Client-linux_$ARCH-$VERSION.run
  548. rm -R ./TeamSpeak3-Client-linux_$ARCH
  549.  
  550. greenMessage "TS3 client install done."
  551. else
  552. redMessage "TS3 already installed!"
  553.  
  554. fi
  555.  
  556. fi
  557.  
  558. # Downloading latest Sinusbot.
  559.  
  560. if [ "$INSTALL" != "Rem" ]; then
  561.  
  562. cd /opt/sinusbot
  563.  
  564. greenMessage "Downloading latest Sinusbot."
  565. su -c "curl -O -s https://www.sinusbot.com/dl/sinusbot-beta.tar.bz2" $SINUSBOTUSER
  566.  
  567. if [ ! -f sinusbot-beta.tar.bz2 -a ! -f sinusbot ]; then
  568. redMessage "Error while downloading with cURL. Trying it with wget."
  569. if [ -f /etc/centos-release ]; then
  570. yum -y -q install wget
  571. fi
  572. su -c "wget -q https://www.sinusbot.com/dl/sinusbot-beta.tar.bz2" $SINUSBOTUSER
  573.  
  574. fi
  575.  
  576. if [ ! -f sinusbot-beta.tar.bz2 -a ! -f sinusbot ]; then
  577. errorExit "Download failed! Exiting now!"
  578.  
  579. fi
  580.  
  581. # Installing latest Sinusbot.
  582.  
  583. greenMessage "Extracting Sinusbot files."
  584. su -c "tar -xjf sinusbot-beta.tar.bz2" $SINUSBOTUSER
  585. rm -f sinusbot-beta.tar.bz2
  586.  
  587. chown -R $SINUSBOTUSER:$SINUSBOTUSER /opt/sinusbot
  588.  
  589. su -c "cp plugin/libsoundbot_plugin.so /opt/sinusbot/teamspeak3-client/plugins" $SINUSBOTUSER
  590.  
  591. chmod 755 sinusbot
  592.  
  593. if [ "$INSTALL" == "Inst" ]; then
  594. greenMessage "Sinusbot installation done."
  595. elif [ "$INSTALL" == "Updt" ]; then
  596. greenMessage "Sinusbot update done."
  597. fi
  598.  
  599. if [ ! -f /etc/init.d/sinusbot ]; then
  600. cd /etc/init.d
  601. curl -O -s https://raw.githubusercontent.com/Xuxe/Sinusbot-Startscript/master/sinusbot
  602. sed -i 's/USER="mybotuser"/USER="'$SINUSBOTUSER'"/g' /etc/init.d/sinusbot
  603. sed -i 's/DIR_ROOT="\/opt\/ts3soundboard\/"/DIR_ROOT="\/opt\/sinusbot\/"/g' /etc/init.d/sinusbot
  604.  
  605. chmod +x /etc/init.d/sinusbot
  606. update-rc.d sinusbot defaults >/dev/null 2>&1
  607.  
  608. greenMessage 'Installed init.d file to start the Sinusbot with "/etc/init.d/sinusbot {start|stop|status|restart|console|update|backup}"'
  609.  
  610. else
  611. redMessage "/etc/init.d/sinusbot already exists!"
  612.  
  613. if [ "`/etc/init.d/sinusbot status | awk '{print $NF; exit}'`" == "UP" ]; then
  614. redMessage "Sinusbot stopping now!"
  615. su -c "/etc/init.d/sinusbot stop" $SINUSBOTUSER
  616. su -c "screen -wipe" $SINUSBOTUSER
  617. update-rc.d -f sinusbot remove >/dev/null 2>&1
  618. else
  619. greenMessage "Sinusbot already stopped."
  620.  
  621. fi
  622.  
  623. fi
  624.  
  625. if [ "$INSTALL" == "Inst" ]; then
  626.  
  627. if [ ! -f /opt/sinusbot/config.ini ]; then
  628. echo 'ListenPort = 8087
  629. ListenHost = "0.0.0.0"
  630. TS3Path = "/opt/sinusbot/teamspeak3-client/ts3client_linux_amd64"
  631. YoutubeDLPath = ""'>>/opt/sinusbot/config.ini
  632. greenMessage "Config.ini created successfully."
  633. else
  634. redMessage "Config.ini already exists or creation error!"
  635.  
  636. fi
  637.  
  638. fi
  639.  
  640. if [ `grep -c 'youtube' /etc/crontab` -ge 1 ]; then
  641. sed -i '/\0 \0 \* \* \* youtube-dl -U >\/dev\/null 2>&1/d' /etc/crontab
  642. redMessage "Removed old YT-DL cronjob."
  643.  
  644. fi
  645.  
  646. if [ `grep -c 'sinusbot' /etc/crontab` -ge 1 ]; then
  647. sed -i '/\0 \0 \* \* \* su "$SINUSBOTUSER" sinusbot -update >\/dev\/null 2>&1/d' /etc/crontab
  648. redMessage "Removed old Sinusbot cronjob."
  649.  
  650. fi
  651.  
  652. if [ `grep -Pq 'sinusbot' /etc/cron.d/sinusbot &>/dev/null` ]; then
  653. redMessage "Cronjob already set for Sinusbot updater!"
  654. else
  655. greenMessage "Inject Cronjob for automatic Sinusbot update..."
  656. echo "0 0 * * * su $SINUSBOTUSER /opt/sinusbot/sinusbot -update >/dev/null 2>&1">/etc/cron.d/sinusbot
  657. greenMessage "Inject Sinusbot update cronjob successful."
  658.  
  659. fi
  660.  
  661. fi
  662.  
  663. # Installing YT-DL.
  664.  
  665. if [ "$INSTALL" != "Rem" ]; then
  666.  
  667. if [ ! -f /usr/local/bin/youtube-dl ]; then
  668. redMessage "Should YT-DL be installed?"
  669. OPTIONS=("Yes" "No")
  670. select OPTION in "${OPTIONS[@]}"; do
  671. case "$REPLY" in
  672. 1|2 ) break;;
  673. *) errorContinue;;
  674. esac
  675. done
  676.  
  677. if [ "$OPTION" == "Yes" ]; then
  678. greenMessage "Installing YT-Downloader now!"
  679.  
  680. if [ "`grep -c 'youtube' /etc/cron.d/sinusbot`" -ge 1 ]; then
  681. redMessage "Cronjob already set for YT-DL updater!"
  682. else
  683. greenMessage "Inject Cronjob for automatic YT-DL update..."
  684. echo "0 0 * * * youtube-dl -U >/dev/null 2>&1">>/etc/cron.d/sinusbot
  685. greenMessage "Inject successful."
  686.  
  687. fi
  688.  
  689. if [ "$INSTALL" != "Rem" ]; then
  690. sed -i 's/YoutubeDLPath = \"\"/YoutubeDLPath = \"\/usr\/local\/bin\/youtube-dl\"/g' /opt/sinusbot/config.ini
  691.  
  692. fi
  693.  
  694. curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl 2> /dev/null
  695. chmod a+rx /usr/local/bin/youtube-dl
  696.  
  697. youtube-dl -U 2> /dev/null
  698.  
  699. fi
  700. fi
  701.  
  702. # Creating Readme
  703.  
  704. if [ ! -a "/opt/sinusbot/README_installer.txt" ]; then
  705. echo '##################################################################################
  706. # #
  707. # Usage: /etc/init.d/sinusbot {start|stop|status|restart|console|update|backup} #
  708. # - start: start the bot #
  709. # - stop: stop the bot #
  710. # - status: display the status of the bot (down or up) #
  711. # - restart: restart the bot #
  712. # - console: display the bot console #
  713. # - update: runs the bot updater (with start & stop)
  714. # - backup: archives your bot root directory
  715. # To exit the console without stopping the server, press CTRL + A then D. #
  716. # #
  717. ##################################################################################'>>/opt/sinusbot/README_installer.txt
  718. fi
  719.  
  720. chown -R $SINUSBOTUSER:$SINUSBOTUSER /opt/sinusbot
  721.  
  722. # Starting Sinusbot
  723.  
  724. greenMessage 'Starting the Sinusbot.'
  725. /etc/init.d/sinusbot start
  726. yellowMessage "Please wait... This will take some seconds!"
  727. sleep 5
  728.  
  729. # If startup failed, the script will start normal sinusbot without screen for looking about errors. If startup successed => installation done.
  730.  
  731. if [ `/etc/init.d/sinusbot status | awk '{print $NF; exit}'` == "DOWN" ]; then
  732. redMessage "Sinusbot could not start! Starting it without screen. Look for errors! Stop it again in 10 seconds."
  733. su -c "/opt/sinusbot/sinusbot" $SINUSBOTUSER
  734. sleep 10
  735. killall sinusbot
  736.  
  737. else
  738.  
  739. if [ "$INSTALL" == "Inst" ]; then
  740. greenMessage "Install done!"
  741. elif [ "$INSTALL" == "Updt" ]; then
  742. greenMessage "Update done!"
  743.  
  744. fi
  745.  
  746. if [ ! -a "/opt/sinusbot/README_installer.txt" ]; then
  747. yellowMessage 'Generated a README_installer.txt in /opt/sinusbot with all commands for the sinusbot...'
  748.  
  749. fi
  750.  
  751. greenMessage 'All right. Everything is installed successfully. Sinusbot is UP on "'$ipaddress':8087" | Username: "admin" | Password: "'$pwgen'" :)'
  752. redMessage 'Stop it with "/etc/init.d/sinusbot stop".'
  753. cyanMessage 'Also you can enter "/etc/init.d/sinusbot help" for help ;)'
  754. magentaMessage "Don't forget to rate this script on: https://forum.sinusbot.com/resources/sinusbot-installer-script.58/"
  755. greenMessage "Thank you for using this script! :)"
  756.  
  757. fi
  758.  
  759. fi
  760.  
  761. # remove installer
  762.  
  763. cd $changedir
  764. rm $0
  765.  
  766. exit 0
Add Comment
Please, Sign In to add comment