You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 line
5.6KB

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