Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

179 lignes
6.3KB

  1. #!/bin/bash
  2. #CraftBeerPi Installer
  3. # Copy 2017 Manuel Fritsch
  4. confirmAnswer () {
  5. whiptail --title "Confirmation" --yes-button "Yes" --no-button "No" --defaultno --yesno "$1" 10 56
  6. return $?
  7. }
  8. show_menu () {
  9. # We show the host name right in the menu title so we know which Pi we are connected to
  10. OPTION=$(whiptail --title "CraftBeerPi 3.0" --menu "Choose your option:" 15 56 7 \
  11. "1" "Install CraftBeerPi" \
  12. "2" "Clear Database" \
  13. "3" "Add To Autostart" \
  14. "4" "Remove From Autostart" \
  15. "5" "Start CraftBeerPi" \
  16. "6" "Stop CraftBeerPi" \
  17. "7" "Software Update (git pull)" \
  18. "8" "Reset File Changes (git reset --hard)" \
  19. "9" "Clear all logs" \
  20. "10" "Reboot Raspberry Pi" \
  21. "11" "Stop CraftBeerPi, Clear logs, Start CraftBeerPi" 3>&1 1>&2 2>&3)
  22. BUTTON=$?
  23. # Exit if user pressed cancel or escape
  24. if [[ ($BUTTON -eq 1) || ($BUTTON -eq 255) ]]; then
  25. exit 1
  26. fi
  27. if [ $BUTTON -eq 0 ]; then
  28. case $OPTION in
  29. 1)
  30. confirmAnswer "Would you like run apt-get update & apt-get upgrade?"
  31. if [ $? = 0 ]; then
  32. apt-get -y update; apt-get -y upgrade;
  33. fi
  34. confirmAnswer "Would you like to install wiringPI? This is required to control the GPIO"
  35. if [ $? = 0 ]; then
  36. git clone git://git.drogon.net/wiringPi;
  37. cd wiringPi;
  38. ./build; cd ..;
  39. rm -rf wiringPi;
  40. fi
  41. # By default DietPi does not have this package installed.
  42. apt-get -y install build-essential
  43. apt-get -y install python-rpi.gpio
  44. apt-get -y install python-setuptools
  45. easy_install pip
  46. apt-get -y install python-dev
  47. apt-get -y install libpcre3-dev
  48. pip install -r requirements.txt
  49. confirmAnswer "Would you like to add active 1-wire support at your Raspberry PI now? IMPORTANT: The 1-wire thermometer must be conneted to GPIO 4!"
  50. if [ $? = 0 ]; then
  51. #apt-get -y update; apt-get -y upgrade;
  52. if [ -e /DietPi/config.txt ]; then
  53. echo '# CraftBeerPi 1-wire support' >> "/DietPi/config.txt"
  54. echo 'dtoverlay=w1-gpio,gpiopin=4,pullup=on' >> "/DietPi/config.txt"
  55. else
  56. echo '# CraftBeerPi 1-wire support' >> "/boot/config.txt"
  57. echo 'dtoverlay=w1-gpio,gpiopin=4,pullup=on' >> "/boot/config.txt"
  58. fi
  59. fi
  60. # checking for file splash.png
  61. if [ -e /usr/share/plymouth/themes/pix/splash.png ]; then
  62. sudo mv ./config/splash.png /usr/share/plymouth/themes/pix/splash.png
  63. fi
  64. sed "s@#DIR#@${PWD}@g" config/craftbeerpiboot > /etc/init.d/craftbeerpiboot
  65. chmod 755 /etc/init.d/craftbeerpiboot;
  66. whiptail --title "Installition Finished" --msgbox "CraftBeerPi installation finished! You must hit OK to continue." 8 78
  67. show_menu
  68. ;;
  69. 2)
  70. confirmAnswer "Are you sure you want to clear the CraftBeerPi. All hardware setting will be deleted"
  71. if [ $? = 0 ]; then
  72. sudo rm -f craftbeerpi.db
  73. whiptail --title "Database Delted" --msgbox "The CraftBeerPi database was succesfully deleted. You must hit OK to continue." 8 78
  74. show_menu
  75. else
  76. show_menu
  77. fi
  78. ;;
  79. 3)
  80. confirmAnswer "Are you sure you want to add CraftBeerPi to autostart"
  81. if [ $? = 0 ]; then
  82. sed "s@#DIR#@${PWD}@g" config/craftbeerpiboot > /etc/init.d/craftbeerpiboot
  83. chmod 755 /etc/init.d/craftbeerpiboot;
  84. update-rc.d craftbeerpiboot defaults;
  85. whiptail --title "Added succesfull to autostart" --msgbox "The CraftBeerPi was added to autostart succesfully. You must hit OK to continue." 8 78
  86. show_menu
  87. else
  88. show_menu
  89. fi
  90. ;;
  91. 4)
  92. confirmAnswer "Are you sure you want to remove CraftBeerPi from autostart"
  93. if [ $? = 0 ]; then
  94. update-rc.d -f craftbeerpiboot remove
  95. show_menu
  96. else
  97. show_menu
  98. fi
  99. ;;
  100. 5)
  101. sudo /etc/init.d/craftbeerpiboot start
  102. ipaddr=`ifconfig wlan0 2>/dev/null|awk '/inet addr:/ {print $2}'|sed 's/addr://'`
  103. whiptail --title "CraftBeerPi started" --msgbox "Please connect via Browser: http://$ipaddr:5000" 8 78
  104. show_menu
  105. ;;
  106. 6)
  107. sudo /etc/init.d/craftbeerpiboot stop
  108. whiptail --title "CraftBeerPi stoped" --msgbox "The software is stoped" 8 78
  109. show_menu
  110. ;;
  111. 7)
  112. confirmAnswer "Are you sure you want to pull a software update?"
  113. if [ $? = 0 ]; then
  114. whiptail --textbox /dev/stdin 20 50 <<<"$(git pull)"
  115. show_menu
  116. else
  117. show_menu
  118. fi
  119. ;;
  120. 8)
  121. confirmAnswer "Are you sure you want to reset all file changes for this git respository (git reset --hard)?"
  122. if [ $? = 0 ]; then
  123. whiptail --textbox /dev/stdin 20 50 <<<"$(git reset --hard)"
  124. show_menu
  125. else
  126. show_menu
  127. fi
  128. ;;
  129. 9)
  130. confirmAnswer "Are you sure you want to delete all CraftBeerPi log files"
  131. if [ $? = 0 ]; then
  132. sudo rm -rf logs/*.log
  133. whiptail --title "Log files deleted" --msgbox "All CraftBeerPi Files are deleted. You must hit OK to continue." 8 78
  134. show_menu
  135. else
  136. show_menu
  137. fi
  138. ;;
  139. 10)
  140. confirmAnswer "Are you sure you want to reboot the Raspberry Pi?"
  141. if [ $? = 0 ]; then
  142. sudo reboot
  143. else
  144. show_menu
  145. fi
  146. ;;
  147. 11)
  148. confirmAnswer "Are you sure you want to reboot CraftBeerPi and delete all log files?"
  149. if [ $? = 0 ]; then
  150. sudo /etc/init.d/craftbeerpiboot stop
  151. sudo rm -rf logs/*.log
  152. sudo /etc/init.d/craftbeerpiboot start
  153. show_menu
  154. else
  155. show_menu
  156. fi
  157. ;;
  158. esac
  159. fi
  160. }
  161. if [ "$EUID" -ne 0 ]
  162. then whiptail --title "Please run as super user (sudo)" --msgbox "Please run the install file -> sudo install.sh " 8 78
  163. exit
  164. fi
  165. show_menu