|
5 | 5 | called_from=$(pwd)
|
6 | 6 | cd $(dirname $0)
|
7 | 7 | VERSION=0.1
|
8 |
| -APPLICATION_PATH="usr/libexec/pi-web-agent" |
9 |
| -SERVICE_PATH="etc/init.d/pi-web-agent" |
10 |
| -DEPENDENCIES="git tightvncserver apache2 libapache2-mod-dnssd alsa-utils python gcc libprocps0-dev" |
11 |
| -VNC_SERVICE="etc/init.d/vncboot" |
12 |
| -ETC_PATH="etc/pi-web-agent" |
13 |
| -LOGS=/var/log/pi-web-agent |
14 |
| -SHARE="usr/share/pi-web-agent" |
15 |
| -PI_UPDATE=usr/bin/pi-update |
16 |
| -PI_UPGRADE=usr/bin/pi-upgrade |
17 |
| -PI_FIX=usr/bin/pi-fix |
18 |
| -APT_QUERY=usr/bin/apt-query |
19 |
| -SUDOERS_D=etc/sudoers.d/pi-web-agent |
20 |
| -GPIO_QUERY=usr/bin/gpio-query |
21 |
| -CRON_JOBS=etc/cron.daily |
22 |
| -EXECUTE_BIN=usr/bin/execute-pwa.sh |
23 |
| -PI_APT=usr/bin/pi-package-management |
24 |
| -htpasswd_PATH=usr/libexec/pi-web-agent/.htpasswd |
25 |
| -UPDATE_APP_BIN=usr/bin/pi-web-agent-update |
26 |
| -UPDATE_CHECK_PY=usr/bin/update_check.py |
27 |
| -OTHER_BINS="usr/bin/start-stream-cam.sh usr/bin/pi-camera-stream.sh" |
28 |
| -SYSTEM_UPDATE_CHECK=usr/bin/system_update_check.sh |
29 |
| -STARTUP_PWA=usr/bin/startup-manager-pwa.py |
30 |
| - |
31 |
| -CRONJOB_REBOOT=/etc/cron.d/cronpwa |
32 |
| - |
33 |
| -this_install(){ |
34 |
| - echo -n "Installing pi web agent " |
35 |
| - [[ ! -d "/$APPLICATION_PATH" && ! -f "/$SERVICE_PATH" && ! -d "/$ETC_PATH" ]] || { |
36 |
| - print_error "ABORTED" |
37 |
| - echo "The application is already installed. Run \`setup reinstall' if the installation is broken " |
38 |
| - exit 1 |
39 |
| - } |
40 |
| - [ -d /usr/libexec ] || mkdir /usr/libexec |
41 |
| - print_ok |
42 |
| - |
43 |
| - echo "Updating packages" |
44 |
| - apt-get update |
45 |
| - echo "Installing dependencies" |
46 |
| - apt-get install $DEPENDENCIES |
47 |
| - print_ok |
48 |
| - |
49 |
| - echo -n "Adding user account for appliance... " |
50 |
| - useradd -r pi-web-agent |
51 |
| - print_ok "DONE" |
52 |
| - sleep 0.5 |
53 |
| - |
54 |
| - [ -f "$htpasswd_PATH" ] || { |
55 |
| - echo -n "Creating password file with default credentials admin:admin " |
56 |
| - htpasswd -cbd "$htpasswd_PATH" 'admin' 'admin' && print_ok "DONE" |
57 |
| - } |
58 |
| - |
59 |
| - /bin/cp -rv "$APPLICATION_PATH" "/$APPLICATION_PATH" |
60 |
| - |
61 |
| - /bin/cp -av "$SHARE" "/$SHARE" |
62 |
| - /bin/cp -v "$SERVICE_PATH" "/$SERVICE_PATH" |
63 |
| - /bin/cp -v "$EXECUTE_BIN" "/$EXECUTE_BIN" |
64 |
| - /bin/cp -v "$PI_APT" "/$PI_APT" |
65 |
| - /bin/cp -v "$UPDATE_APP_BIN" "/$UPDATE_APP_BIN" |
66 |
| - /bin/cp -v "$UPDATE_CHECK_PY" "/$UPDATE_CHECK_PY" |
67 |
| - /bin/cp -v "$SYSTEM_UPDATE_CHECK" "/$SYSTEM_UPDATE_CHECK" |
68 |
| - /bin/cp -v "$STARTUP_PWA" "/$STARTUP_PWA" |
69 |
| - chmod +x "/$EXECUTE_BIN" |
70 |
| - chmod +x "/$SERVICE_PATH" |
71 |
| - chmod +x "/$UPDATE_APP_BIN" |
72 |
| - chmod +x "/$UPDATE_CHECK_PY" |
73 |
| - chmod +x "/$SYSTEM_UPDATE_CHECK" |
74 |
| - chmod +x "/$STARTUP_PWA" |
75 |
| - |
76 |
| - chmod +x $OTHER_BINS |
77 |
| - /bin/cp -v $OTHER_BINS /usr/bin/ |
78 |
| - |
79 |
| - touch $CRONJOB_REBOOT |
80 |
| - echo "@reboot root /$STARTUP_PWA" >$CRONJOB_REBOOT |
81 |
| - |
82 |
| - /bin/cp -rv "$ETC_PATH" "/$ETC_PATH" |
83 |
| - rm -rf "/$ETC_PATH/modules" "/$ETC_PATH/run" |
84 |
| - ln -s "/usr/lib/apache2/modules" "/$ETC_PATH/modules" |
85 |
| - ln -s "/var/run/httpd" "/$ETC_PATH/run" |
86 |
| - chown -R pi-web-agent "/$APPLICATION_PATH/etc" |
87 |
| - chown -R pi-web-agent:pi-web-agent "/$SHARE" |
88 |
| - echo -n "Starting the pi web agent apache instance daemon " |
89 |
| - [ $? -eq 0 ] || { |
90 |
| - print_error "FAILED" |
91 |
| - echo |
92 |
| - exit 1 |
93 |
| - } |
94 |
| - |
95 |
| - [ -d $LOGS ] || mkdir -p $LOGS |
96 |
| - [ -d $AND_LOGS ] || mkdir -p $AND_LOGS |
97 |
| - cp $VNC_SERVICE /$VNC_SERVICE |
98 |
| - chmod +x "/$VNC_SERVICE" |
99 |
| - cp $PI_UPDATE /$PI_UPDATE |
100 |
| - cp $PI_UPGRADE /$PI_UPGRADE |
101 |
| - cp $PI_FIX /$PI_FIX |
102 |
| - cp $GPIO_QUERY /$GPIO_QUERY |
103 |
| - cp $APT_QUERY /$APT_QUERY |
104 |
| - |
105 |
| - print_ok |
106 |
| - |
107 |
| - echo "Post installation actions" |
108 |
| - chown pi-web-agent:pi-web-agent /usr/libexec/pi-web-agent/.htpasswd |
109 |
| - chown -R pi-web-agent:pi-web-agent /usr/share/pi-web-agent |
110 |
| - chmod 644 /usr/libexec/pi-web-agent/.htpasswd |
111 |
| - print_ok |
112 |
| - echo "Installing wiringPi - examples excluded" |
113 |
| - currDir=$(pwd) |
114 |
| - temp=$(mktemp -d /tmp/wiringPi.XXX) |
115 |
| - cd $temp |
116 |
| - git clone --depth 1 "https://github.com/vaslabs/gordonsWiringPi" |
117 |
| - cd gordonsWiringPi |
118 |
| - chmod +x ./build |
119 |
| - ./build |
120 |
| - echo "DONE" |
121 |
| - cd $currDir |
122 |
| - rm -rf $temp |
123 |
| - cp $CRON_JOBS/* /$CRON_JOBS |
124 |
| - echo "Registering pi-web-agent in sudoers" |
125 |
| - cp $SUDOERS_D /$SUDOERS_D |
126 |
| - chown root:root /$SUDOERS_D |
127 |
| - chmod 0440 /$SUDOERS_D |
128 |
| - chmod 640 "/usr/libexec/pi-web-agent/.htpasswd" |
129 |
| - chown -R pi-web-agent:pi-web-agent /usr/libexec/pi-web-agent |
130 |
| - chmod 770 /usr/libexec/pi-web-agent/cgi-bin/*.py |
131 |
| - chmod 770 /usr/libexec/pi-web-agent/cgi-bin/*.pwa |
132 |
| - chmod 770 /usr/libexec/pi-web-agent/cgi-bin/toolkit/*.py |
133 |
| - chmod 770 /usr/libexec/pi-web-agent/cgi-bin/toolkit/*.pwa |
134 |
| - chmod 770 /usr/libexec/pi-web-agent/html/utilities/*.html |
135 |
| - chmod 770 /usr/libexec/pi-web-agent/html/index.html |
136 |
| - chmod +x /usr/libexec/pi-web-agent/scripts/hostname.sh |
137 |
| - chmod +x /usr/libexec/pi-web-agent/scripts/memory_information |
138 |
| - chmod +x /etc/cron.daily/update-check |
139 |
| - chmod +x /usr/bin/* |
140 |
| - mkdir "/$SHARE/camera-media" |
141 |
| - chown -R pi-web-agent:pi-web-agent "/$SHARE/camera-media" |
142 |
| - echo "Starting pi-web-agent" |
143 |
| - "/$SERVICE_PATH" start |
144 |
| -} |
145 |
| - |
146 |
| - |
147 |
| -this_uninstall() { |
148 |
| - echo -n "Stopping pi web agent apache instance daemon " |
149 |
| - "/$SERVICE_PATH" stop |
150 |
| - echo "Removing pi web agent" |
151 |
| - |
152 |
| - this_safe_remove "/$APPLICATION_PATH" |
153 |
| - |
154 |
| - this_safe_remove "/$ETC_PATH" |
155 |
| - this_safe_remove "/$SERVICE_PATH" |
156 |
| - this_safe_remove "/$SHARE" |
157 |
| - /bin/rm "/$EXECUTE_BIN" |
158 |
| - /bin/rm "/usr/bin/execute.sh" |
159 |
| - /bin/rm "/$PI_APT" |
160 |
| - |
161 |
| - /bin/rm "/$UPDATE_CHECK_PY" |
162 |
| - /bin/rm "/$UPDATE_APP_BIN" |
163 |
| - /bin/rm "/$SYSTEM_UPDATE_CHECK" |
164 |
| - /bin/rm $CRONJOB_REBOOT |
165 |
| - /bin/rm "/$STARTUP_PWA" |
166 |
| - /etc/init.d/vncboot stop |
167 |
| - rm /etc/init.d/vncboot |
168 |
| - |
169 |
| - print_ok |
170 |
| - echo "Deleting user account of appliance..." |
171 |
| - rm /$SUDOERS_D |
172 |
| - rm -r /etc/pi-web-agent |
173 |
| - userdel -f pi-web-agent |
174 |
| - print_ok "DONE" |
175 |
| -} |
176 |
| - |
177 |
| -this_safe_remove() { |
178 |
| - echo "attempting to remove $1" |
179 |
| - [[ -f "$1" || -d "$1" ]] && { |
180 |
| - echo -n "Removing $1" |
181 |
| - /bin/rm -r "$1" |
182 |
| - [ $? -eq 0 ] || { |
183 |
| - print_error "FAILED" |
184 |
| - |
185 |
| - } |
186 |
| - print_ok |
187 |
| - } |
188 |
| -} |
189 |
| - |
190 |
| -this_reinstall() { |
191 |
| - echo "Reinstalling pi web agent" |
192 |
| - echo "Keeping the same password" |
193 |
| - echo -e "\e[0;34m Backing up Camera Snapshots\e[0m" |
194 |
| - cp /$htpasswd_PATH $htpasswd_PATH |
195 |
| - if [ -d "/$SHARE/camera-media" ]; then |
196 |
| - mv "/$SHARE/camera-media" /tmp/. |
197 |
| - else |
198 |
| - print_error "404 Camera snapshots not found" |
199 |
| - fi |
200 |
| - this_uninstall |
201 |
| - this_install $1 |
202 |
| - echo -e "\e[0;34m Restoring Camera Snapshots\e[0m" |
203 |
| - if [ -d "/tmp/camera-media" ]; then |
204 |
| - cp -af /tmp/camera-media "/$SHARE/" |
205 |
| - else |
206 |
| - print_error "Camera snapshots backup not found" |
207 |
| - fi |
208 |
| - echo "Recovering your snapshots" |
209 |
| -} |
210 |
| - |
211 |
| -print_ok() { |
212 |
| -msg="OK" |
213 |
| -[ -n "$1" ] && { |
214 |
| - msg=$1 |
215 |
| -} |
216 |
| -echo -e "[ \e[1;32m $msg \e[0m ]" |
217 |
| - |
218 |
| -} |
219 |
| - |
220 |
| -print_error() { |
221 |
| - echo -e "[ \e[1;31m $1 \e[0m ]" |
222 |
| -} |
223 |
| - |
224 |
| -print_warning() { |
225 |
| - echo -e "[ \e[1;33m $1 \e[0m ]" |
226 |
| -} |
227 |
| - |
228 |
| - |
229 | 8 |
|
| 9 | +source setup_common |
230 | 10 | case $1 in
|
231 | 11 | install)
|
232 | 12 | [ $(id -u) -eq 0 ] || {
|
|
0 commit comments