Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

168 wiersze
5.8KB

  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. apt-get -y install python-setuptools
  42. easy_install pip
  43. apt-get -y install python-dev
  44. apt-get -y install libpcre3-dev
  45. pip install -r requirements.txt
  46. 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!"
  47. if [ $? = 0 ]; then
  48. #apt-get -y update; apt-get -y upgrade;
  49. echo '# CraftBeerPi 1-wire support' >> "/boot/config.txt"
  50. echo 'dtoverlay=w1-gpio,gpiopin=4,pullup=on' >> "/boot/config.txt"
  51. fi
  52. sudo mv ./config/splash.png /usr/share/plymouth/themes/pix/splash.png
  53. sed "s@#DIR#@${PWD}@g" config/craftbeerpiboot > /etc/init.d/craftbeerpiboot
  54. chmod 755 /etc/init.d/craftbeerpiboot;
  55. whiptail --title "Installition Finished" --msgbox "CraftBeerPi installation finished! You must hit OK to continue." 8 78
  56. show_menu
  57. ;;
  58. 2)
  59. confirmAnswer "Are you sure you want to clear the CraftBeerPi. All hardware setting will be deleted"
  60. if [ $? = 0 ]; then
  61. sudo rm -f craftbeerpi.db
  62. whiptail --title "Database Delted" --msgbox "The CraftBeerPi database was succesfully deleted. You must hit OK to continue." 8 78
  63. show_menu
  64. else
  65. show_menu
  66. fi
  67. ;;
  68. 3)
  69. confirmAnswer "Are you sure you want to add CraftBeerPi to autostart"
  70. if [ $? = 0 ]; then
  71. sed "s@#DIR#@${PWD}@g" config/craftbeerpiboot > /etc/init.d/craftbeerpiboot
  72. chmod 755 /etc/init.d/craftbeerpiboot;
  73. update-rc.d craftbeerpiboot defaults;
  74. whiptail --title "Added succesfull to autostart" --msgbox "The CraftBeerPi was added to autostart succesfully. You must hit OK to continue." 8 78
  75. show_menu
  76. else
  77. show_menu
  78. fi
  79. ;;
  80. 4)
  81. confirmAnswer "Are you sure you want to remove CraftBeerPi from autostart"
  82. if [ $? = 0 ]; then
  83. update-rc.d -f craftbeerpiboot remove
  84. show_menu
  85. else
  86. show_menu
  87. fi
  88. ;;
  89. 5)
  90. sudo /etc/init.d/craftbeerpiboot start
  91. ipaddr=`ifconfig wlan0 2>/dev/null|awk '/inet addr:/ {print $2}'|sed 's/addr://'`
  92. whiptail --title "CraftBeerPi started" --msgbox "Please connect via Browser: http://$ipaddr:5000" 8 78
  93. show_menu
  94. ;;
  95. 6)
  96. sudo /etc/init.d/craftbeerpiboot stop
  97. whiptail --title "CraftBeerPi stoped" --msgbox "The software is stoped" 8 78
  98. show_menu
  99. ;;
  100. 7)
  101. confirmAnswer "Are you sure you want to pull a software update?"
  102. if [ $? = 0 ]; then
  103. whiptail --textbox /dev/stdin 20 50 <<<"$(git pull)"
  104. show_menu
  105. else
  106. show_menu
  107. fi
  108. ;;
  109. 8)
  110. confirmAnswer "Are you sure you want to reset all file changes for this git respository (git reset --hard)?"
  111. if [ $? = 0 ]; then
  112. whiptail --textbox /dev/stdin 20 50 <<<"$(git reset --hard)"
  113. show_menu
  114. else
  115. show_menu
  116. fi
  117. ;;
  118. 9)
  119. confirmAnswer "Are you sure you want to delete all CraftBeerPi log files"
  120. if [ $? = 0 ]; then
  121. sudo rm -rf logs/*.log
  122. whiptail --title "Log files deleted" --msgbox "All CraftBeerPi Files are deleted. You must hit OK to continue." 8 78
  123. show_menu
  124. else
  125. show_menu
  126. fi
  127. ;;
  128. 10)
  129. confirmAnswer "Are you sure you want to reboot the Raspberry Pi?"
  130. if [ $? = 0 ]; then
  131. sudo reboot
  132. else
  133. show_menu
  134. fi
  135. ;;
  136. 11)
  137. confirmAnswer "Are you sure you want to reboot CraftBeerPi and delete all log files?"
  138. if [ $? = 0 ]; then
  139. sudo /etc/init.d/craftbeerpiboot stop
  140. sudo rm -rf logs/*.log
  141. sudo /etc/init.d/craftbeerpiboot start
  142. show_menu
  143. else
  144. show_menu
  145. fi
  146. ;;
  147. esac
  148. fi
  149. }
  150. if [ "$EUID" -ne 0 ]
  151. then whiptail --title "Please run as super user (sudo)" --msgbox "Please run the install file -> sudo install.sh " 8 78
  152. exit
  153. fi
  154. show_menu