Advertisement
Guest User

Untitled

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