Don't like ads? PRO users don't see any ads ;-)
Guest

couchpotato.sh

By: a guest on May 29th, 2012  |  syntax: Bash  |  size: 15.39 KB  |  hits: 38  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/env bash
  2.  
  3. # Author:  Mar2zz
  4. # blogs: mar2zz.tweakblogs.net
  5. # License: GNU GPL v3
  6. #
  7. # This installer is part of "Lazy admins Scripted installers (LaSi)"
  8. # Download main script @
  9. # http://dl.dropbox.com/u/18712538/LaSi/LaSi.sh
  10. #
  11. # please report bugs/issues @
  12. # https://github.com/Mar2zz/LaSi/issues
  13. #  ___________________________________________________________________________________
  14. # |
  15. # | When not using LaSi's Menuscript:
  16. # | execute this script with the command sudo chmod +x couchpotatoinstall.sh
  17. # | and run with ./couchpotatoinstall.sh
  18. # |            
  19. # | answer all questions the terminal asks,
  20. # | and couchpotato will be running in no time!
  21. # |___________________________________________________________________________________
  22. #
  23. # Tested succesful on OS's:
  24. # Ubuntu 10.4 Desktop, Ubuntu 10.4 Minimal server, XBMC Live Dharma
  25. #
  26. #######################################################################################
  27. #######################################################################################
  28.  
  29. VERSION=v0.7
  30.                          
  31. TESTOS1=Ubuntu_10.4_Desktop
  32. TESTOS2=Ubuntu_10.4_Server
  33. TESTOS3=XBMC_Live_Dharma
  34.  
  35. #######################################################################################
  36. #################### LIST OF VARIABLES USED ###########################################
  37.  
  38.  
  39. #SET SOME VARIABLES (SOME VARIABLES WILL BE SET THROUGH LIVE USERINPUT IN TERMINAL)
  40.  
  41. APP=CouchPotato;        # name of app to install
  42.                                         # APP needs to be exactly the same (caps) as on Github (App.git, without .git)
  43. APPLOW=couchpotato;     # lowercase appname
  44.  
  45. CONN1=github.com;       # to test connections needed to install apps
  46. CONN2=dropbox.com;
  47.  
  48. GITHUB=https://github.com/RuudBurger/CouchPotato.git;   #github-adres
  49. DROPBOX=http://dl.dropbox.com/u/18712538/                               #dropbox-adres
  50.  
  51. PACK1=git-core;         #needed packages to run (using apt to check and install)
  52. PACK1_EXE=git;          #EXE only needed when packagename differs from executable
  53. PACK2=python;           ##names can be changed to distrospecific in IF=statements
  54.  
  55. INSTALLDIR=/home/$USER/.$APPLOW; #directory you want to install to.
  56. DAEMONUSER=$USER;       #the user the app is started with
  57. INITD=initd;            #name of default init-script
  58.  
  59. IPADRESS=0.0.0.0;       #default ipadress to listen on
  60. PORT=5000;                      #default port to listen on
  61.  
  62.  
  63.  
  64.  
  65.  
  66. #######################################################################################
  67.  
  68.  
  69. #######################################################################################
  70.  
  71.  
  72. LaSi_Logo (){
  73. clear
  74. echo " Lazy admin Scripted installers -----------------------"
  75. echo "                    ___           ___                  "
  76. echo "                   /\  \         /\__\                 "
  77. echo "                  /::\  \       /:/ _/_       ___      "
  78. echo "                 /:/\:\  \     /:/ /\  \     /\__\     "
  79. echo "  ___     ___   /:/ /::\  \   /:/ /::\  \   /:/__/     "
  80. echo " /\  \   /\__\ /:/_/:/\:\__\ /:/_/:/\:\__\ /::\  \     "
  81. echo " \:\  \ /:/  / \:\/:/  \/__/ \:\/:/ /:/  / \/\:\  \__  "
  82. echo "  \:\  /:/  /   \::/__/       \::/ /:/  /     \:\/\__\ "
  83. echo "   \:\/:/  /     \:\  \        \/_/:/  /       \::/  / "
  84. echo "    \::/  /       \:\__\         /:/  /        /:/  /  "
  85. echo "     \/__/         \/__/         \/__/         \/__/   "
  86. echo
  87. echo "----------------------------------------------- Mar2zz "
  88. echo
  89. echo
  90. }
  91.  
  92. show_Author () {
  93. echo '-------------------------------------'
  94. echo 'COUCHPOTATO IS CREATED BY RUUD BURGER'
  95. echo '-------------- www.couchpotatoapp.com'
  96. echo
  97. echo "LaSi $VERSION"
  98. }
  99.  
  100. #######################################################################################
  101. ####################### TEST IF USER CAN COMPLETE THIS INSTALL ########################
  102.  
  103.  
  104. #### 1ST TEST IF USER CAN SUDO ####
  105.         root_Test() {
  106.         if [ "$(id -u)" = "0" ]
  107.                 then
  108.                 echo "Do not use this installer when logged in as root, it will mess things up!"
  109.                 LaSi_Menu
  110.         fi
  111.         if [ "$(sudo id -u)" != "0" ]
  112.                 then
  113.             echo "...but that's not gonna work, you need to sudo to install $APP, now exiting" &&
  114.             LaSi_Menu
  115.         fi
  116.         }
  117.        
  118. #### 2ND TEST IF USER IS ONLINE ####
  119.         conn_Test () {
  120.                
  121.                 git_test () {
  122.                 if ! ping -c 1 $CONN1 > /dev/null 2>&1
  123.                         then
  124.                         echo "Hmmm $CONN1 seems down..." &&
  125.                         echo "Need $CONN1 to install... Now exiting" &&
  126.                         LaSi_Menu
  127.                 fi
  128.                 }
  129.                
  130.                 dropbox_test () {
  131.                 if ! ping -c 1 $CONN2 > /dev/null 2>&1
  132.                         then
  133.                         echo "Hmmm $CONN2 seems down..."
  134.                         echo "Need $CONN2 to install... Now exiting"
  135.                         LaSi_Menu
  136.                 fi
  137.                 }
  138.         git_test
  139.         dropbox_test
  140.         }
  141.  
  142.  
  143. #### CONFIRM_CONTINUE ####
  144.         cf_Continue () {
  145.         echo '--------'
  146.         echo 'You can take the blue pill if you want to, just answer no on the next question or press CTRL+C'
  147.         echo '--------'
  148.         echo ' '
  149.        
  150.                 Question() {
  151.                 echo "Are you sure you want to continue and install $APP?"
  152.                 read -p "(yes/no)   :" REPLY
  153.                 case $REPLY in
  154.                 [Yy]*)
  155.                         echo "Into the rabbit hole..."
  156.                         ;;
  157.                 [Nn]*)
  158.                                 echo 'Wake up in bed and believe this all was a dream...'
  159.                                 LaSi_Menu
  160.                                 ;;
  161.                         *)
  162.                                 echo "Answer yes or no"
  163.                                 Question
  164.                                 ;;
  165.                 esac
  166.                 }
  167.         Question               
  168.         }  
  169.        
  170.        
  171. #######################################################################################
  172. #### CHECK AND INSTALL PACKAGES #######################################################
  173.  
  174. #### CHECK SOFTWARE: GIT-CORE AND PYTHON ####
  175.         check_Packs () {
  176.                
  177.                 check_Pack1 () {
  178.                 if ! which $PACK1_EXE
  179.                         then
  180.                         echo "Cannot find if $PACK1 is installed"
  181.                         echo "Trying to install..."
  182.                         echo
  183.                         INST_PACK=$PACK1
  184.                         use_PM
  185.                 else
  186.                         echo "$PACK1 installed"
  187.                 fi
  188.                 }
  189.                
  190.                 check_Pack2 () {
  191.                 if ! which $PACK2
  192.                         then
  193.                         echo
  194.                         echo "Cannot find if $PACK2 is installed"
  195.                         echo "Trying to install..."
  196.                         echo
  197.                         INST_PACK=$PACK2
  198.                         use_PM
  199.                 else
  200.                         echo "$PACK2 installed"
  201.                 fi
  202.                 }
  203.         check_Pack1
  204.         check_Pack2
  205.         }
  206.        
  207.        
  208. #### DETERMINE PACKAGEMANAGER ####
  209.         use_PM () {
  210.                        
  211.                 def_PM () {
  212.                 [ -x "$(which $1)" ]
  213.                 }
  214.  
  215.                 use_Apt () {
  216.                 sudo apt-get install $INST_PACK ||
  217.                 use_Manual
  218.                 }
  219.        
  220.                 use_Yum () {
  221.                 sudo yum install $INST_PACK ||
  222.                 use_Manual
  223.                 }
  224.                
  225.                 use_Pac () {
  226.                 sudo pacman -S $INST_PACK ||
  227.                 use_Manual
  228.                 }
  229.                
  230.                 use_Manual () {
  231.                 echo
  232.                 echo "Installing $INST_PACK failed"
  233.                 echo "Please install manually..."
  234.                 echo
  235.                 echo "Type the command to install $INST_PACK"
  236.                 echo "e.g. sudo apt-get install $INST_PACK"
  237.                 read -p "   :" MAN_INST
  238.                 if $MAN_INST
  239.                         then
  240.                         echo "Succes!"
  241.                 else
  242.                         echo "Failed! Solve this before continuing installation"
  243.                         echo "Try again or press CTRL+C to quit"
  244.                         use_Manual
  245.                 fi
  246.                 }
  247.                
  248.         if def_PM apt-get
  249.                 then
  250.                 use_Apt
  251.         elif def_PM yum
  252.                 then
  253.                 use_Yum
  254.         elif def_PM pacman
  255.                 then
  256.                 use_Pac
  257.         else
  258.             echo 'No package manager found!'
  259.             use_Manual
  260.         fi
  261.         }
  262.        
  263.        
  264. #### CHOOSE INSTALLATION DIRECTORY ####
  265.         set_Dir () {   
  266.        
  267.                 cf_Overwrite () {
  268.                 echo "1. Choose another directory"
  269.                 echo "2. Backup $INSTALLDIR to LaSi/$APP"
  270.                 echo "3. Delete $INSTALLDIR"
  271.                 echo "Q. Quit"
  272.                 read -p "Press 1, 2, 3 or Q to select an option    :" REPLY
  273.                 case $REPLY in
  274.                 1)
  275.                                 choose_Dir
  276.                         ;;
  277.                 2)
  278.                         echo "Backup $INSTALLDIR to /home/$USER/LaSi/$APP"
  279.                         if [ -d /home/$USER/LaSi ]
  280.                                 then
  281.                                 mv -f $INSTALLDIR /home/$USER/LaSi/$APP
  282.                         else
  283.                                 mkdir LaSi
  284.                                 mv -f $INSTALLDIR /home/$USER/LaSi/$APP
  285.                         fi
  286.                         ;;
  287.                 3)
  288.                     echo "Deleting $INSTALLDIR."
  289.                         rm -R -f $INSTALLDIR
  290.                         ;;
  291.                 [Qq]*)
  292.                         echo "Fini..."
  293.                         LaSi_Menu
  294.                         ;;
  295.                 *)
  296.                                 echo "Choose 1, 2, 3 or Q to quit"
  297.                                 cf_Dir
  298.                         ;;
  299.                 esac
  300.                 }
  301.        
  302.                 choose_Dir() {
  303.                 read -p 'Type the path of the directory you want to install in...   :' INSTALLDIR
  304.                 if [ -d $INSTALLDIR ]
  305.                         then
  306.                         echo
  307.                         echo "$INSTALLDIR allready exists, please choose an option:"
  308.                         cf_Overwrite
  309.                 else
  310.                         echo "Installing $APP in $INSTALLDIR."
  311.                 fi
  312.                 }
  313.                
  314.                 cf_Dir () {
  315.                 if [ -d $INSTALLDIR ]
  316.                         then
  317.                         echo
  318.                         echo "$INSTALLDIR allready exists, please choose an option:"
  319.                         cf_Overwrite
  320.                 else
  321.                         echo "By default CouchPotato will be installed in $INSTALLDIR."
  322.                         echo "Do you want to change this?"                     
  323.                         read -p "(yes/no)   :" REPLY
  324.                         case $REPLY in
  325.                         [Yy]*)
  326.                                 choose_Dir
  327.                                 ;;
  328.                         [Nn]*)
  329.                                 echo "Installing $APP in $INSTALLDIR"
  330.                                 ;;
  331.                         *)
  332.                                         echo "Answer yes or no"
  333.                                         cf_Dir
  334.                                 ;;
  335.                         esac
  336.                 fi
  337.                 }
  338.         cf_Dir
  339.         }
  340.  
  341.  
  342. #### CLONING INTO GIT ####
  343.         clone_Git () {
  344.         echo ' '
  345.         echo '-------'
  346.         echo "Download and install the most recent version of $APP from GitHub"
  347.         echo '-------'
  348.         echo ' '
  349.         command git clone $GITHUB $INSTALLDIR
  350.         echo
  351.         echo "Delete $INSTALLDIR/.git to enable webupdates"
  352.         rm -R -f $INSTALLDIR/.git
  353.         }
  354.        
  355.  
  356. #### CONFIRM DAEMON INSTALL ####       
  357.         cf_Daemon () {
  358.         echo
  359.         echo '-------'
  360.         echo "You can install $APP as a daemon, so it will start when your pc starts..."
  361.         echo '-------'
  362.         echo ' '
  363.                
  364.                 Question() {
  365.                 echo "Do you want to install $APP as a daemon?"
  366.                 read -p "(yes/no)   :" REPLY
  367.                 case $REPLY in
  368.         [Yy]*) # back to main
  369.                 echo 'As you wish, master...'
  370.                 ;;
  371.         [Nn]*)
  372.                         echo "You can start app manually by executing python $INSTALLDIR/$APP.py..."
  373.                         echo "I prefer the LaSi way though...but have fun using $APP!"
  374.                         LaSi_Menu
  375.                         ;;
  376.         *)
  377.                         echo "Answer yes or no"
  378.                         Question
  379.                 ;;
  380.                 esac
  381.                 }
  382.         Question
  383.         }
  384.        
  385.  
  386. #### TEST NECESSARY DEFAULT PATHS ####
  387.         test_Initdefs () {
  388.                
  389.                 path_Python() {
  390.                 PATH_PYTHON=$(which python)    
  391.                 sed -i "s#/usr/bin/python#$PATH_PYTHON#g" $INSTALLDIR/$INITD
  392.                 }
  393.         path_Python
  394.         }
  395.        
  396.        
  397. #### CHANGE VALUES IN INITSCRIPT ####  
  398.         adj_Initscript () {
  399.         cp -f $INSTALLDIR/$INITD $INSTALLDIR/$INITD.bak
  400.         sed -i "
  401.                 s#/usr/local/sbin/couchpotato#$INSTALLDIR#g
  402.                 s/root/$USER/g
  403.                 " $INSTALLDIR/$INITD
  404.         }
  405.        
  406.        
  407. #### COPY INITSCRIPT TO /ETC/INIT.D/ ####
  408.         cp_Initscript () {
  409.         if [ -e /etc/init.d/$APPLOW ]
  410.                 then
  411.                 echo "Making backup of /etc/init.d/$APPLOW to $APPLOW.bak"
  412.                 echo "Copying $INSTALLDIR/$INITD to /etc/init.d/$APPLOW..."
  413.                 sudo cp -f --suffix=.bak $INSTALLDIR/$INITD /etc/init.d/$APPLOW &&
  414.                 sudo chmod +x /etc/init.d/$APPLOW &&
  415.                 sudo update-rc.d $APPLOW defaults
  416.         else
  417.                 echo "Copying $INSTALLDIR/$INITD to /etc/init.d/$APPLOW..."
  418.                 sudo cp -f $INSTALLDIR/$INITD /etc/init.d/$APPLOW &&
  419.                 sudo chmod +x /etc/init.d/$APPLOW &&
  420.                 sudo update-rc.d $APPLOW defaults
  421.         fi
  422.         }
  423.        
  424.        
  425. #### LET USER CONFIRM CONFIGURATION ####
  426.         cf_Config() {
  427.         echo '-------'
  428.         echo "Now you can start $APP with a clean configuration..."
  429.         echo "By default $APP's webinterface adress is: http://$IPADRESS:$PORT."
  430.         echo "That's the same as http://localhost:$PORT or http://127.0.0.1:$PORT."
  431.         echo "It will not ask for a username and password."
  432.         echo
  433.        
  434.                 Question() {
  435.                 echo "Do you want change the defaults or import your own configuration file?"
  436.                 read -p "(yes/no)   :" REPLY
  437.                 case $REPLY in
  438.                 [Yy]*)
  439.                         echo 'As you wish, master...'
  440.                         ;;
  441.                 [Nn]*)
  442.                                 sudo /etc/init.d/$APPLOW start &&
  443.                                 echo "Point your webbrowser to http://$IPADRESS:$PORT and start configuring!"
  444.                                 LaSi_Menu
  445.                                 ;;
  446.                         *)
  447.                                 echo "Answer yes or no"
  448.                                 Question
  449.                                 ;;
  450.                 esac
  451.                 }
  452.         Question
  453.         }      
  454.  
  455. #### GET NEW CONFIGFILE ####
  456.         new_Config(){
  457.                
  458.                 get_Config () { #download new config.ini
  459.                 if [ -e $INSTALLDIR/config.ini ]
  460.                         then
  461.                         mv -f $INSTALLDIR/config.ini $INSTALLDIR/config.ini.bak &&
  462.                         wget -P $INSTALLDIR $DROPBOX/$APP/config.ini
  463.                 else
  464.                         wget -P $INSTALLDIR $DROPBOX/$APP/config.ini
  465.                 fi
  466.                 }
  467.                
  468.                 import_Config() { # import config.ini
  469.                 echo
  470.                 echo 'Type the full path and filename of the configurationfile you want to import'
  471.                 echo 'or s to skip:'
  472.                 read -p ' :' IMPORTCONFIG
  473.                 if [ $IMPORTCONFIG = S -o $IMPORTCONFIG = s ]
  474.                         then
  475.                         cf_Import              
  476.                 elif [ -e $IMPORTCONFIG ]
  477.                                 then
  478.                                 cp -f --suffix=.bak $IMPORTCONFIG $INSTALLDIR/config.ini &&
  479.                                 sudo /etc/init.d/couchpotato start &&
  480.                                 echo "Point your webbrowser to you know where and have fun using $APP!"
  481.                                 LaSi_Menu                              
  482.                         else
  483.                                 echo 'File does not exist, enter correct path as /path/to/file.ext' &&
  484.                                 import_Config
  485.                         fi
  486.                 }
  487.                
  488.                 cf_Import () { # Confirm import
  489.                 echo "Do you want to import your own configurationfile?"
  490.                 read -p "(yes/no)   :" REPLY
  491.                 case $REPLY in
  492.                 [Yy]*)
  493.                         import_Config
  494.                         ;;
  495.                 [Nn]*)
  496.                         echo "Downloading fresh config from dropbox.com"
  497.                         get_Config
  498.                 ;;
  499.                 *)
  500.                         echo "Answer yes or no"
  501.                                 cf_Import
  502.                 ;;
  503.                         esac
  504.                 }
  505.         cf_Import
  506.         }
  507.                
  508. #### CHANGE DEFAULTS IN CONFIGFILE ####        
  509.  
  510. #### CHANGE IPADRESS AND PORT ####
  511.  
  512.         set_IP () {
  513.                 read -p 'Enter new ipadress, default is 0.0.0.0 ...    :' NEW_IP
  514.                 read -p 'Enter new port, default is 5000 ...    :' NEW_PORT
  515.  
  516.                         cf_IP () {
  517.                         echo "You entered $NEW_IP:$NEW_PORT, is this correct?  :"
  518.                         read -p "(yes/no)   :" REPLY
  519.                         case $REPLY in
  520.                         [Yy]*)
  521.                                 echo "Ok, adding $NEW_IP:$NEW_PORT to config.ini..."
  522.                             sed -i "
  523.                                 s/host = 0.0.0.0/host = $NEW_IP/g
  524.                                                 s/port = 5000/port = $NEW_PORT/g
  525.                                         " $INSTALLDIR/config.ini
  526.                                 ;;
  527.                         [Nn]*)
  528.                                 set_IP
  529.                         ;;
  530.                         *)
  531.                                         echo "Answer yes or no"
  532.                                         cf_IP
  533.                         ;;
  534.                         esac
  535.                         }
  536.         cf_IP
  537.         }
  538.  
  539. #### CHANGE USERNAME AND PASSWORD ####
  540.         set_UP () {
  541.                 read -p 'Enter new username, leave blank for none ...    :' NEW_USER
  542.                 read -p 'Enter new password, leave blank for none ...    :' NEW_PASS
  543.  
  544.                         cf_UP () {
  545.                         echo "You entered username '$NEW_USER' and password '$NEW_PASS', is this correct?  :"
  546.                         read -p "(yes/no or skip)   :" REPLY
  547.                         case $REPLY in
  548.                         [Yy]*)
  549.                                 echo "Ok, adding username and password to config.ini..."
  550.                             sed -i "
  551.                                                 s/username = /username = $NEW_USER/g
  552.                                                 s/password = /password = $NEW_PASS/g
  553.                                         " $INSTALLDIR/config.ini
  554.                                 ;;
  555.                         [Nn]*)
  556.                                 set_UP
  557.                         ;;
  558.                         [Ss]*)
  559.                                 echo "Skipped that one, it stays blank"
  560.                         ;;
  561.                         *)
  562.                                         echo "Answer yes or no or skip"
  563.                                         cf_UP
  564.                         ;;
  565.                         esac
  566.                         }
  567.         cf_UP
  568.         }
  569.  
  570.  
  571. #### STARTING APP ####         
  572.         start_App() {
  573.                 echo "Now starting $APP..."
  574.                 if sudo /etc/init.d/$APPLOW start
  575.                 then
  576.                         echo "Point your webbrowser to http://$NEW_IP:$NEW_PORT and have fun!"
  577.                 else
  578.                         echo "Can't start $APP, try starting manually..."
  579.                         echo "Execute sudo /etc/init.d/$APPLOW stop | start | restart | force-reload"
  580.                         LaSi_Menu
  581.                 fi
  582.         }
  583.                        
  584.                        
  585. #### RETURN TO MENU ####
  586.         LaSi_Menu () {
  587.                
  588.         echo
  589.         read -sn 1 -p "Press a key to continue."
  590.         exit
  591.         }              
  592.                        
  593.                
  594.                        
  595. #### ALL FUNCTIONS ####                        
  596.        
  597. LaSi_Logo               #intro
  598. show_Author             #creator of the app installed
  599. conn_Test               #connection test for url's used in installation
  600. cf_Continue             #let user confirm to continue
  601. root_Test               #test user is not root but has sudo
  602. check_Packs             #check dependencys
  603. set_Dir                 #choose installation directory
  604. clone_Git               #clone the git repo and mv to $installdir
  605. cf_Daemon               #let user confirm to daemonize
  606. test_Initdefs   #test if necessary values are true and change if needed
  607. adj_Initscript  #change values to match installscripts
  608. cp_Initscript   #copy initscript to /etc/init.d/$applow
  609. cf_Config               #Let user confirm to start configuration
  610. new_Config              #import or download configurationfile
  611. set_IP                  #Set Ipadress:Port
  612. set_UP                  #Set Username:Password
  613. start_App               #Start the application and gl!
  614. LaSi_Menu               #Return to main script
  615.  
  616. #### TEST OF MAPPEN AL BESTAAN EN STEL VOOR TE VERWIJDERN