-
Notifications
You must be signed in to change notification settings - Fork 169
/
install.sh
executable file
·159 lines (147 loc) · 5.51 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
#CraftBeerPi Installer
# Copy 2017 Manuel Fritsch
confirmAnswer () {
whiptail --title "Confirmation" --yes-button "Yes" --no-button "No" --defaultno --yesno "$1" 10 56
return $?
}
show_menu () {
# We show the host name right in the menu title so we know which Pi we are connected to
OPTION=$(whiptail --title "CraftBeerPi 3.0" --menu "Choose your option:" 15 56 7 \
"1" "Install CraftBeerPi" \
"2" "Clear Database" \
"3" "Add To Autostart" \
"4" "Remove From Autostart" \
"5" "Start CraftBeerPi" \
"6" "Stop CraftBeerPi" \
"7" "Software Update (git pull)" \
"8" "Reset File Changes (git reset --hard)" \
"9" "Clear all logs" \
"10" "Reboot Raspberry Pi" \
"11" "Stop CraftBeerPi, Clear logs, Start CraftBeerPi" 3>&1 1>&2 2>&3)
BUTTON=$?
# Exit if user pressed cancel or escape
if [[ ($BUTTON -eq 1) || ($BUTTON -eq 255) ]]; then
exit 1
fi
if [ $BUTTON -eq 0 ]; then
case $OPTION in
1)
confirmAnswer "Would you like run apt-get update & apt-get upgrade?"
if [ $? = 0 ]; then
apt-get -y update; apt-get -y upgrade;
fi
apt-get -y install python-setuptools
easy_install pip
apt-get -y install python-dev
apt-get -y install libpcre3-dev
pip install -r requirements.txt
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!"
if [ $? = 0 ]; then
#apt-get -y update; apt-get -y upgrade;
echo '# CraftBeerPi 1-wire support' >> "/boot/config.txt"
echo 'dtoverlay=w1-gpio,gpiopin=4,pullup=on' >> "/boot/config.txt"
fi
sudo mv ./config/splash.png /usr/share/plymouth/themes/pix/splash.png
sed "s@#DIR#@${PWD}@g" config/craftbeerpiboot > /etc/init.d/craftbeerpiboot
chmod 755 /etc/init.d/craftbeerpiboot;
whiptail --title "Installition Finished" --msgbox "CraftBeerPi installation finished! You must hit OK to continue." 8 78
show_menu
;;
2)
confirmAnswer "Are you sure you want to clear the CraftBeerPi. All hardware setting will be deleted"
if [ $? = 0 ]; then
sudo rm -f craftbeerpi.db
whiptail --title "Database Delted" --msgbox "The CraftBeerPi database was succesfully deleted. You must hit OK to continue." 8 78
show_menu
else
show_menu
fi
;;
3)
confirmAnswer "Are you sure you want to add CraftBeerPi to autostart"
if [ $? = 0 ]; then
sed "s@#DIR#@${PWD}@g" config/craftbeerpiboot > /etc/init.d/craftbeerpiboot
chmod 755 /etc/init.d/craftbeerpiboot;
update-rc.d craftbeerpiboot defaults;
whiptail --title "Added succesfull to autostart" --msgbox "The CraftBeerPi was added to autostart succesfully. You must hit OK to continue." 8 78
show_menu
else
show_menu
fi
;;
4)
confirmAnswer "Are you sure you want to remove CraftBeerPi from autostart"
if [ $? = 0 ]; then
update-rc.d -f craftbeerpiboot remove
show_menu
else
show_menu
fi
;;
5)
sudo /etc/init.d/craftbeerpiboot start
ipaddr=`ifconfig wlan0 2>/dev/null|awk '/inet addr:/ {print $2}'|sed 's/addr://'`
whiptail --title "CraftBeerPi started" --msgbox "Please connect via Browser: http://$ipaddr:5000" 8 78
show_menu
;;
6)
sudo /etc/init.d/craftbeerpiboot stop
whiptail --title "CraftBeerPi stoped" --msgbox "The software is stoped" 8 78
show_menu
;;
7)
confirmAnswer "Are you sure you want to pull a software update?"
if [ $? = 0 ]; then
whiptail --textbox /dev/stdin 20 50 <<<"$(git pull)"
show_menu
else
show_menu
fi
;;
8)
confirmAnswer "Are you sure you want to reset all file changes for this git respository (git reset --hard)?"
if [ $? = 0 ]; then
whiptail --textbox /dev/stdin 20 50 <<<"$(git reset --hard)"
show_menu
else
show_menu
fi
;;
9)
confirmAnswer "Are you sure you want to delete all CraftBeerPi log files"
if [ $? = 0 ]; then
sudo rm -rf logs/*.log
whiptail --title "Log files deleted" --msgbox "All CraftBeerPi Files are deleted. You must hit OK to continue." 8 78
show_menu
else
show_menu
fi
;;
10)
confirmAnswer "Are you sure you want to reboot the Raspberry Pi?"
if [ $? = 0 ]; then
sudo reboot
else
show_menu
fi
;;
11)
confirmAnswer "Are you sure you want to reboot CraftBeerPi and delete all log files?"
if [ $? = 0 ]; then
sudo /etc/init.d/craftbeerpiboot stop
sudo rm -rf logs/*.log
sudo /etc/init.d/craftbeerpiboot start
show_menu
else
show_menu
fi
;;
esac
fi
}
if [ "$EUID" -ne 0 ]
then whiptail --title "Please run as super user (sudo)" --msgbox "Please run the install file -> sudo install.sh " 8 78
exit
fi
show_menu