Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

180 рядки
6.4KB

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