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

155 рядки
5.3KB

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