Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

180 Zeilen
6.2KB

  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" \
  22. "12" "Install KairosDB" 3>&1 1>&2 2>&3)
  23. BUTTON=$?
  24. # Exit if user pressed cancel or escape
  25. if [[ ($BUTTON -eq 1) || ($BUTTON -eq 255) ]]; then
  26. exit 1
  27. fi
  28. if [ $BUTTON -eq 0 ]; then
  29. case $OPTION in
  30. 1)
  31. confirmAnswer "Would you like run apt-get update & apt-get upgrade?"
  32. if [ $? = 0 ]; then
  33. apt-get -y update; apt-get -y upgrade;
  34. fi
  35. confirmAnswer "Would you like to install wiringPI? This is required to control the GPIO"
  36. if [ $? = 0 ]; then
  37. git clone git://git.drogon.net/wiringPi;
  38. cd wiringPi;
  39. ./build; cd ..;
  40. rm -rf wiringPi;
  41. fi
  42. apt-get -y install python-setuptools
  43. easy_install pip
  44. apt-get -y install python-dev
  45. apt-get -y install libpcre3-dev
  46. pip install -r requirements.txt
  47. confirmAnswer "Would you like to add active 1-wire support at your Raspberry PI now? IMPORTANT: The 1-wire thermometer must be connected to GPIO 4!"
  48. if [ $? = 0 ]; then
  49. #apt-get -y update; apt-get -y upgrade;
  50. echo '# CraftBeerPi 1-wire support' >> "/boot/config.txt"
  51. echo 'dtoverlay=w1-gpio,gpiopin=4,pullup=on' >> "/boot/config.txt"
  52. fi
  53. sudo mv ./config/splash.png /usr/share/plymouth/themes/pix/splash.png
  54. sed "s@#DIR#@${PWD}@g" config/craftbeerpiboot > /etc/init.d/craftbeerpiboot
  55. chmod 755 /etc/init.d/craftbeerpiboot;
  56. whiptail --title "Installation Finished" --msgbox "CraftBeerPi installation finished! You must hit OK to continue." 8 78
  57. show_menu
  58. ;;
  59. 2)
  60. confirmAnswer "Are you sure you want to clear the CraftBeerPi. All hardware setting will be deleted"
  61. if [ $? = 0 ]; then
  62. sudo rm -f craftbeerpi.db
  63. whiptail --title "Database Deleted" --msgbox "The CraftBeerPi database was successfully deleted. You must hit OK to continue." 8 78
  64. show_menu
  65. else
  66. show_menu
  67. fi
  68. ;;
  69. 3)
  70. confirmAnswer "Are you sure you want to add CraftBeerPi to autostart"
  71. if [ $? = 0 ]; then
  72. sed "s@#DIR#@${PWD}@g" config/craftbeerpiboot > /etc/init.d/craftbeerpiboot
  73. chmod 755 /etc/init.d/craftbeerpiboot;
  74. update-rc.d craftbeerpiboot defaults;
  75. whiptail --title "Added successful to autostart" --msgbox "The CraftBeerPi was added to autostart successfully. You must hit OK to continue." 8 78
  76. show_menu
  77. else
  78. show_menu
  79. fi
  80. ;;
  81. 4)
  82. confirmAnswer "Are you sure you want to remove CraftBeerPi from autostart"
  83. if [ $? = 0 ]; then
  84. update-rc.d -f craftbeerpiboot remove
  85. show_menu
  86. else
  87. show_menu
  88. fi
  89. ;;
  90. 5)
  91. sudo /etc/init.d/craftbeerpiboot start
  92. ipaddr=`ifconfig wlan0 2>/dev/null|awk '/inet addr:/ {print $2}'|sed 's/addr://'`
  93. whiptail --title "CraftBeerPi started" --msgbox "Please connect via Browser: http://$ipaddr:5000" 8 78
  94. show_menu
  95. ;;
  96. 6)
  97. sudo /etc/init.d/craftbeerpiboot stop
  98. whiptail --title "CraftBeerPi stopped" --msgbox "The software is stopped" 8 78
  99. show_menu
  100. ;;
  101. 7)
  102. confirmAnswer "Are you sure you want to pull a software update?"
  103. if [ $? = 0 ]; then
  104. whiptail --textbox /dev/stdin 20 50 <<<"$(git pull)"
  105. show_menu
  106. else
  107. show_menu
  108. fi
  109. ;;
  110. 8)
  111. confirmAnswer "Are you sure you want to reset all file changes for this git repository (git reset --hard)?"
  112. if [ $? = 0 ]; then
  113. whiptail --textbox /dev/stdin 20 50 <<<"$(git reset --hard)"
  114. show_menu
  115. else
  116. show_menu
  117. fi
  118. ;;
  119. 9)
  120. confirmAnswer "Are you sure you want to delete all CraftBeerPi log files"
  121. if [ $? = 0 ]; then
  122. sudo rm -rf logs/*.log
  123. whiptail --title "Log files deleted" --msgbox "All CraftBeerPi Files are deleted. You must hit OK to continue." 8 78
  124. show_menu
  125. else
  126. show_menu
  127. fi
  128. ;;
  129. 10)
  130. confirmAnswer "Are you sure you want to reboot the Raspberry Pi?"
  131. if [ $? = 0 ]; then
  132. sudo reboot
  133. else
  134. show_menu
  135. fi
  136. ;;
  137. 11)
  138. confirmAnswer "Are you sure you want to reboot CraftBeerPi and delete all log files?"
  139. if [ $? = 0 ]; then
  140. sudo /etc/init.d/craftbeerpiboot stop
  141. sudo rm -rf logs/*.log
  142. sudo /etc/init.d/craftbeerpiboot start
  143. show_menu
  144. else
  145. show_menu
  146. fi
  147. ;;
  148. 12)
  149. confirmAnswer "Are you sure you want to install KairosDB?"
  150. if [ $? = 0 ]; then
  151. wget https://github.com/kairosdb/kairosdb/releases/download/v1.2.1/kairosdb_1.2.1-1_all.deb
  152. sudo dpkg -i kairosdb_1.2.1-1_all.deb
  153. sudo service kairosdb start
  154. show_menu
  155. else
  156. show_menu
  157. fi
  158. ;;
  159. esac
  160. fi
  161. }
  162. if [ "$EUID" -ne 0 ]
  163. then whiptail --title "Please run as super user (sudo)" --msgbox "Please run the install file -> sudo install.sh " 8 78
  164. exit
  165. fi
  166. show_menu