forked from vaslabs/pi-web-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_common
233 lines (205 loc) · 7.03 KB
/
setup_common
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
APPLICATION_PATH="usr/libexec/pi-web-agent"
SERVICE_PATH="etc/init.d/pi-web-agent"
DEPENDENCIES="git tightvncserver apache2 libapache2-mod-dnssd alsa-utils python gcc libprocps3-dev"
VNC_SERVICE="etc/init.d/vncboot"
ETC_PATH="etc/pi-web-agent"
LOGS=/var/log/pi-web-agent
SHARE="usr/share/pi-web-agent"
PI_UPDATE=usr/bin/pi-update
PI_UPGRADE=usr/bin/pi-upgrade
PI_FIX=usr/bin/pi-fix
APT_QUERY=usr/bin/apt-query
SUDOERS_D=etc/sudoers.d/pi-web-agent
GPIO_QUERY=usr/bin/gpio-query
CRON_JOBS=etc/cron.daily
EXECUTE_BIN=usr/bin/execute-pwa.sh
PI_APT=usr/bin/pi-package-management
htpasswd_PATH=usr/libexec/pi-web-agent/.htpasswd
UPDATE_APP_BIN=usr/bin/pi-web-agent-update
UPDATE_CHECK_PY=usr/bin/update_check.py
OTHER_BINS="usr/bin/start-stream-cam.sh usr/bin/pi-camera-stream.sh"
SYSTEM_UPDATE_CHECK=usr/bin/system_update_check.sh
STARTUP_PWA=usr/bin/startup-manager-pwa.py
CRONJOB_REBOOT=/etc/cron.d/cronpwa
this_install(){
echo -n "Installing pi web agent "
[[ ! -d "/$APPLICATION_PATH" && ! -f "/$SERVICE_PATH" && ! -d "/$ETC_PATH" ]] || {
print_error "ABORTED"
echo "The application is already installed. Run \`setup reinstall' if the installation is broken "
exit 1
}
[ -d /usr/libexec ] || mkdir /usr/libexec
print_ok
echo "checking git setup ..."
[ -z "$(command -v git)" ]&& sudo apt-get install git-core ||echo "git already installed"
#echo "checking if this is a git repository"
#git rev-parse --is-inside-work-tree||git init
#echo "initialising submodules ..."
#git submodule update --init --recursive
print_ok
echo "Updating packages"
apt-get update
echo "Installing dependencies"
apt-get install $DEPENDENCIES
print_ok
echo -n "Adding user account for appliance... "
useradd -r pi-web-agent
print_ok "DONE"
sleep 0.5
[ -f "$htpasswd_PATH" ] || {
echo -n "Creating password file with default credentials admin:admin "
htpasswd -cbd "$htpasswd_PATH" 'admin' 'admin' && print_ok "DONE"
}
/bin/cp -rv "$APPLICATION_PATH" "/$APPLICATION_PATH"
echo "Installing websocketdBro"
/bin/chmod +x ./usr/libexec/pi-web-agent/scripts/websocketdBro/raspbian_setup.sh
./usr/libexec/pi-web-agent/scripts/websocketdBro/raspbian_setup.sh
/bin/cp -av "$SHARE" "/$SHARE"
/bin/cp -v "$SERVICE_PATH" "/$SERVICE_PATH"
/bin/cp -v "$EXECUTE_BIN" "/$EXECUTE_BIN"
/bin/cp -v "$PI_APT" "/$PI_APT"
/bin/cp -v "$UPDATE_APP_BIN" "/$UPDATE_APP_BIN"
/bin/cp -v "$UPDATE_CHECK_PY" "/$UPDATE_CHECK_PY"
/bin/cp -v "$SYSTEM_UPDATE_CHECK" "/$SYSTEM_UPDATE_CHECK"
/bin/cp -v "$STARTUP_PWA" "/$STARTUP_PWA"
chmod +x "/$EXECUTE_BIN"
chmod +x "/$SERVICE_PATH"
chmod +x "/$UPDATE_APP_BIN"
chmod +x "/$UPDATE_CHECK_PY"
chmod +x "/$SYSTEM_UPDATE_CHECK"
chmod +x "/$STARTUP_PWA"
chmod +x $OTHER_BINS
/bin/cp -v $OTHER_BINS /usr/bin/
touch $CRONJOB_REBOOT
echo "@reboot root /$STARTUP_PWA" >$CRONJOB_REBOOT
/bin/cp -rv "$ETC_PATH" "/$ETC_PATH"
rm -rf "/$ETC_PATH/modules" "/$ETC_PATH/run"
ln -s "/usr/lib/apache2/modules" "/$ETC_PATH/modules"
ln -s /etc/apache2/mods-enabled "/$ETC_PATH/mods-enabled"
ln -s "/var/run/httpd" "/$ETC_PATH/run"
chown -R pi-web-agent "/$APPLICATION_PATH/etc"
chown -R pi-web-agent:pi-web-agent "/$SHARE"
echo -n "Starting the pi web agent apache instance daemon "
[ $? -eq 0 ] || {
print_error "FAILED"
echo
exit 1
}
[ -d $LOGS ] || mkdir -p $LOGS
[ -d $AND_LOGS ] || mkdir -p $AND_LOGS
cp $VNC_SERVICE /$VNC_SERVICE
chmod +x "/$VNC_SERVICE"
cp $PI_UPDATE /$PI_UPDATE
cp $PI_UPGRADE /$PI_UPGRADE
cp $PI_FIX /$PI_FIX
cp $GPIO_QUERY /$GPIO_QUERY
cp $APT_QUERY /$APT_QUERY
print_ok
echo "Post installation actions"
chown pi-web-agent:pi-web-agent /usr/libexec/pi-web-agent/.htpasswd
chown -R pi-web-agent:pi-web-agent /usr/share/pi-web-agent
chmod 644 /usr/libexec/pi-web-agent/.htpasswd
print_ok
echo "Installing wiringPi - examples excluded"
currDir=$(pwd)
temp=$(mktemp -d /tmp/wiringPi.XXX)
cd $temp
git clone --depth 1 "https://github.com/vaslabs/gordonsWiringPi"
cd gordonsWiringPi
chmod +x ./build
./build
echo "DONE"
cd $currDir
rm -rf $temp
cp $CRON_JOBS/* /$CRON_JOBS
echo "Registering pi-web-agent in sudoers"
cp $SUDOERS_D /$SUDOERS_D
chown root:root /$SUDOERS_D
chmod 0440 /$SUDOERS_D
chmod 640 "/usr/libexec/pi-web-agent/.htpasswd"
chown -R pi-web-agent:pi-web-agent /usr/libexec/pi-web-agent
chmod 770 /usr/libexec/pi-web-agent/cgi-bin/*.py
chmod 770 /usr/libexec/pi-web-agent/cgi-bin/*.pwa
chmod 770 /usr/libexec/pi-web-agent/cgi-bin/toolkit/*.py
chmod 770 /usr/libexec/pi-web-agent/cgi-bin/toolkit/*.pwa
chmod 770 /usr/libexec/pi-web-agent/html/utilities/*.html
chmod 770 /usr/libexec/pi-web-agent/html/index.html
chmod +x /usr/libexec/pi-web-agent/scripts/hostname.sh
chmod +x /usr/libexec/pi-web-agent/scripts/memory_information
chmod +x /etc/cron.daily/update-check
chmod +x /usr/bin/*
mkdir "/$SHARE/camera-media"
a2enmod authz_groupfile
chown -R pi-web-agent:pi-web-agent "/$SHARE/camera-media"
echo "Starting pi-web-agent"
"/$SERVICE_PATH" start
}
this_uninstall() {
echo -n "Stopping pi web agent apache instance daemon "
"/$SERVICE_PATH" stop
echo "Removing pi web agent"
this_safe_remove "/$APPLICATION_PATH"
this_safe_remove "/$ETC_PATH"
this_safe_remove "/$SERVICE_PATH"
this_safe_remove "/$SHARE"
/bin/rm "/$EXECUTE_BIN"
/bin/rm "/usr/bin/execute.sh"
/bin/rm "/$PI_APT"
/bin/rm "/$UPDATE_CHECK_PY"
/bin/rm "/$UPDATE_APP_BIN"
/bin/rm "/$SYSTEM_UPDATE_CHECK"
/bin/rm $CRONJOB_REBOOT
/bin/rm "/$STARTUP_PWA"
/etc/init.d/vncboot stop
rm /etc/init.d/vncboot
print_ok
echo "Deleting user account of appliance..."
rm /$SUDOERS_D
rm -r /etc/pi-web-agent
userdel -f pi-web-agent
print_ok "DONE"
}
this_safe_remove() {
echo "attempting to remove $1"
[[ -f "$1" || -d "$1" ]] && {
echo -n "Removing $1"
/bin/rm -r "$1"
[ $? -eq 0 ] || {
print_error "FAILED"
}
print_ok
}
}
this_reinstall() {
echo "Reinstalling pi web agent"
echo "Keeping the same password"
echo -e "\e[0;34m Backing up Camera Snapshots\e[0m"
cp /$htpasswd_PATH $htpasswd_PATH
if [ -d "/$SHARE/camera-media" ]; then
mv "/$SHARE/camera-media" /tmp/.
else
print_error "404 Camera snapshots not found"
fi
this_uninstall
this_install $1
echo -e "\e[0;34m Restoring Camera Snapshots\e[0m"
if [ -d "/tmp/camera-media" ]; then
cp -af /tmp/camera-media "/$SHARE/"
else
print_error "Camera snapshots backup not found"
fi
echo "Recovering your snapshots"
}
print_ok() {
msg="OK"
[ -n "$1" ] && {
msg=$1
}
echo -e "[ \e[1;32m $msg \e[0m ]"
}
print_error() {
echo -e "[ \e[1;31m $1 \e[0m ]"
}
print_warning() {
echo -e "[ \e[1;33m $1 \e[0m ]"
}