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.

150 lines
5.1KB

  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" 3>&1 1>&2 2>&3)
  21. BUTTON=$?
  22. # Exit if user pressed cancel or escape
  23. if [[ ($BUTTON -eq 1) || ($BUTTON -eq 255) ]]; then
  24. exit 1
  25. fi
  26. if [ $BUTTON -eq 0 ]; then
  27. case $OPTION in
  28. 1)
  29. confirmAnswer "Would you like run apt-get update & apt-get upgrade?"
  30. if [ $? = 0 ]; then
  31. apt-get -y update; apt-get -y upgrade;
  32. fi
  33. confirmAnswer "Would you like to install wiringPI? This is required to control the GPIO"
  34. if [ $? = 0 ]; then
  35. git clone git://git.drogon.net/wiringPi;
  36. cd wiringPi;
  37. ./build; cd ..;
  38. rm -rf wiringPi;
  39. fi
  40. apt-get -y install python-setuptools
  41. easy_install pip
  42. apt-get -y install python-dev
  43. apt-get -y install libpcre3-dev
  44. pip install -r requirements.txt
  45. 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!"
  46. if [ $? = 0 ]; then
  47. #apt-get -y update; apt-get -y upgrade;
  48. echo '# CraftBeerPi 1-wire support' >> "/boot/config.txt"
  49. echo 'dtoverlay=w1-gpio,gpiopin=4,pullup=on' >> "/boot/config.txt"
  50. fi
  51. whiptail --title "Installition Finished" --msgbox "CraftBeerPi installation finished! You must hit OK to continue." 8 78
  52. show_menu
  53. ;;
  54. 2)
  55. confirmAnswer "Are you sure you want to clear the CraftBeerPi. All hardware setting will be deleted"
  56. if [ $? = 0 ]; then
  57. sudo rm -f craftbeerpi.db
  58. whiptail --title "Database Delted" --msgbox "The CraftBeerPi database was succesfully deleted. You must hit OK to continue." 8 78
  59. show_menu
  60. else
  61. show_menu
  62. fi
  63. ;;
  64. 3)
  65. confirmAnswer "Are you sure you want to add CraftBeerPi to autostart"
  66. if [ $? = 0 ]; then
  67. sed "s@#DIR#@${PWD}@g" config/craftbeerpiboot > /etc/init.d/craftbeerpiboot
  68. chmod 755 /etc/init.d/craftbeerpiboot;
  69. update-rc.d craftbeerpiboot defaults;
  70. whiptail --title "Added succesfull to autostart" --msgbox "The CraftBeerPi was added to autostart succesfully. You must hit OK to continue." 8 78
  71. show_menu
  72. else
  73. show_menu
  74. fi
  75. ;;
  76. 4)
  77. confirmAnswer "Are you sure you want to remove CraftBeerPi from autostart"
  78. if [ $? = 0 ]; then
  79. sudo rm -f /etc/init.d/craftbeerpiboot
  80. show_menu
  81. else
  82. show_menu
  83. fi
  84. ;;
  85. 5)
  86. sudo /etc/init.d/craftbeerpiboot start
  87. whiptail --title "CraftBeerPi started" --msgbox "Please connect via Browser: http://<IP-ADDRESS>:5000" 8 78
  88. show_menu
  89. ;;
  90. 6)
  91. sudo /etc/init.d/craftbeerpiboot stop
  92. whiptail --title "CraftBeerPi stoped" --msgbox "The software is stoped" 8 78
  93. show_menu
  94. ;;
  95. 7)
  96. confirmAnswer "Are you sure you want to pull a software update?"
  97. if [ $? = 0 ]; then
  98. whiptail --textbox /dev/stdin 20 50 <<<"$(git pull)"
  99. show_menu
  100. else
  101. show_menu
  102. fi
  103. ;;
  104. 8)
  105. confirmAnswer "Are you sure you want to reset all file changes for this git respository (git reset --hard)?"
  106. if [ $? = 0 ]; then
  107. whiptail --textbox /dev/stdin 20 50 <<<"$(git reset --hard)"
  108. show_menu
  109. else
  110. show_menu
  111. fi
  112. ;;
  113. 9)
  114. confirmAnswer "Are you sure you want to delete all CraftBeerPi log files"
  115. if [ $? = 0 ]; then
  116. sudo rm -rf logs/*.log
  117. whiptail --title "Log files deleted" --msgbox "All CraftBeerPi Files are deleted. You must hit OK to continue." 8 78
  118. show_menu
  119. else
  120. show_menu
  121. fi
  122. ;;
  123. 10)
  124. confirmAnswer "Are you sure you want to reboo the Raspberry Pi?"
  125. if [ $? = 0 ]; then
  126. sudo reboot
  127. else
  128. show_menu
  129. fi
  130. ;;
  131. esac
  132. fi
  133. }
  134. if [ "$EUID" -ne 0 ]
  135. then whiptail --title "Please run as super user (sudo)" --msgbox "Please run the install file -> sudo install.sh " 8 78
  136. exit
  137. fi
  138. show_menu