Advertisement
Guest User

Untitled

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