Advertisement
Guest User

Untitled

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