Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

151 lines
5.2KB

  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. ipaddr=`ifconfig wlan0 2>/dev/null|awk '/inet addr:/ {print $2}'|sed 's/addr://'`
  88. whiptail --title "CraftBeerPi started" --msgbox "Please connect via Browser: http://$ipaddr:5000" 8 78
  89. show_menu
  90. ;;
  91. 6)
  92. sudo /etc/init.d/craftbeerpiboot stop
  93. whiptail --title "CraftBeerPi stoped" --msgbox "The software is stoped" 8 78
  94. show_menu
  95. ;;
  96. 7)
  97. confirmAnswer "Are you sure you want to pull a software update?"
  98. if [ $? = 0 ]; then
  99. whiptail --textbox /dev/stdin 20 50 <<<"$(git pull)"
  100. show_menu
  101. else
  102. show_menu
  103. fi
  104. ;;
  105. 8)
  106. confirmAnswer "Are you sure you want to reset all file changes for this git respository (git reset --hard)?"
  107. if [ $? = 0 ]; then
  108. whiptail --textbox /dev/stdin 20 50 <<<"$(git reset --hard)"
  109. show_menu
  110. else
  111. show_menu
  112. fi
  113. ;;
  114. 9)
  115. confirmAnswer "Are you sure you want to delete all CraftBeerPi log files"
  116. if [ $? = 0 ]; then
  117. sudo rm -rf logs/*.log
  118. whiptail --title "Log files deleted" --msgbox "All CraftBeerPi Files are deleted. You must hit OK to continue." 8 78
  119. show_menu
  120. else
  121. show_menu
  122. fi
  123. ;;
  124. 10)
  125. confirmAnswer "Are you sure you want to reboo the Raspberry Pi?"
  126. if [ $? = 0 ]; then
  127. sudo reboot
  128. else
  129. show_menu
  130. fi
  131. ;;
  132. esac
  133. fi
  134. }
  135. if [ "$EUID" -ne 0 ]
  136. then whiptail --title "Please run as super user (sudo)" --msgbox "Please run the install file -> sudo install.sh " 8 78
  137. exit
  138. fi
  139. show_menu