-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathservices-installer.sh
199 lines (175 loc) · 5.19 KB
/
services-installer.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
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
#!/mnt/secure/su /bin/sh
export PATH=/sbin:/usr/sbin:$PATH
PKGVER=v8
install_log=/mnt/ext1/pbjb_install_log.txt
exec 1<&-
exec 2<&-
exec 1<>$install_log
exec 2>&1
set -x
iv2sh SetActiveTask `pidof bookshelf.app` 0
PVER=`cat /mnt/secure/.pkgver`
base=/mnt/ext1/system/config/settings
settings=$base/settings.json
rootset=$base/rootsettings.json
old=/ebrmain/config/settings/settings.json
function remove_bind() {
umount -l /usr/share/terminfo
umount -l /ebrmain/bin/netagent
umount -l /var/tmp/netagent.orig
for n in ins_usbnet rm_usbnet ins_usb_mod rm_usb_mod usb_test; do
umount -l /lib/modules/$n.sh
done
}
bk=/var/tmp/backup_etc
function backup_config() {
mkdir /var/tmp/backup_etc
cp -af /mnt/secure/etc/firewall $bk
cp -af /mnt/secure/etc/*passwd $bk
cp -af /mnt/secure/etc/*.conf $bk
}
function restore_config() {
cp -af $bk/* /mnt/secure/etc/
}
function uninstall() {
remove_bind
chattr -i /mnt/secure/runonce/*.sh
rm -rf /mnt/secure/runonce/*.sh /mnt/secure/bin /mnt/secure/etc /mnt/secure/lib /mnt/secure/.pkgver
rm -f $settings
mv -f $settings.old $settings
# if settings is missing, will be copied from system
dialog 2 "" "Services uninstalled, restart is needed." "Restart now" "Restart later"
if [ $? == 1 ]; then
sync
reboot
fi
exit 0
}
if [ "$PVER" != "" ]; then
if [ "$PVER" != "$PKGVER" ]; then
dialog 1 "" "Version $PVER already installed" "Update to $PKGVER" "Cancel" "Uninstall"
st=$?
if [ $st == 3 ]; then
uninstall
elif [ $st == 2 ]; then
exit 0
fi
else
dialog 1 "" "Version $PVER already installed." "Cancel" "Uninstall"
if [ $? == 2 ]; then
uninstall
fi
exit 0
fi
else
dialog 1 "" "Do you wish to install $PKGVER?" "Yes" "No"
if [ $? != 1 ]; then
exit 0
fi
fi
echo $PKGVER > /mnt/secure/.pkgver
mkdir -p /mnt/ext1/public_html
echo "*.html files are served from here if 'HTTP server' option is enabled. dynamic pages can be served by *.cgi scripts." > /mnt/ext1/public_html/index.html
mkdir /mnt/ext1/public
echo 'Files in here are served to public via smb:\\pocketbook\public, ftp://anonymous@pocketbook and http://pocketbook/public/' > /mnt/ext1/public/README.txt
mkdir /mnt/ext1/.ssh
mkdir -p /mnt/ext1/system/etc/init.d
mkdir -p /mnt/ext1/system/config/settings
ARCHIVE=`awk '/^__DATA/ {print NR + 1; exit 0; }' $0`
#try *very* aggressively to remove everything that could stand in our way
remove_bind
backup_config
chattr -i /mnt/secure/runonce/*.sh
chattr -i /mnt/secure/init.d
chattr -i /mnt/secure/rcS
chattr -i /mnt/secure/etc
chattr -i /mnt/secure/init.d/*
rm -rf /mnt/secure/init.d #old location
rm -f /mnt/secure/rcS #old location
rm -f /mnt/secure/.pkgver
rm -rf /mnt/secure/etc /mnt/secure/bin /mnt/secure/lib
echo "Extracting"
chmod 755 /mnt/secure
tail -n+$ARCHIVE $0 | (cd /mnt/secure && tar xvz -C /mnt/secure)
if [ $? != 0 ]; then
dialog 3 "" "Install files extraction failed. See `basename $install_log`" "OK"
exit 1
fi
restore_config
chattr +i /mnt/secure/runonce/*.sh /mnt/secure/su
if [ ! -e /mnt/secure/etc/passwd ]; then
PW=$RANDOM
echo -n password=$PW > /mnt/ext1/rootpassword.txt
fi
if [ -e $settings ] && ! grep rootsettings $settings> /dev/null; then
old=$settings.old
mv -f $settings $old
fi
if [ ! -e $settings ]; then
cat <<_EOF > $settings
[
{
"control_type" : "submenu",
"icon_id" : "ci_system",
"from_file" : "./rootsettings.json",
"title_id" : "Rooted device settings",
},
_EOF
tail -n +2 $old >> $settings
fi
cat <<_EOF > $rootset
[
{
"control_type" : "executable",
"icon_id" : "ci_softwareinfo",
"id" : "rootapply",
"storage" : [ "/mnt/secure/bin/sysstat.app" ],
"title_id" : "System status"
},
{
"control_type" : "executable",
"icon_id" : "ci_swupdate",
"id" : "rootapply",
"storage" : [ "/mnt/secure/bin/applysettings.app" ],
"title_id" : "Reboot to apply changes"
},
{
"id" : "password_set",
"title_id" : "Root password",
"icon_id" : "ci_set_password",
"control_type" : "edit",
"kind" : "text",
"default" : "(keep unchanged)",
"storage" : ["/mnt/ext1/rootpassword.txt, password"],
}
_EOF
for n in /mnt/secure/etc/init.d/*.sh; do
desc="$(head -2 $n | tail -1)"
if [ "${desc:0:2}" != "##" ]; then
continue
fi
desc=${desc:2}
n=${n##*/}
bn=${n:3}
id=${bn/.sh/}
cat <<_EOF >> $rootset
,{
"id": "root_$id",
"storage" : [ "\${SYSTEM_CONFIG_PATH}/rootsettings.cfg, $id" ],
"values" : [ ":0:@Off", ":1:@On" ],
"control_type" : "switch",
"kind": "none",
"default" : ":1:@On",
"title_id" : "$desc",
}
_EOF
done
echo "]" >> $rootset
sync
dialog 1 "" "Services installed, restart is needed to get em running." "Restart now" "Restart later"
if [ $? == 1 ]; then
sync
/sbin/reboot
fi
exit 0
__DATA