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.

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