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

171 рядки
5.9KB

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