forked from buildroot/buildroot
-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathopk_update_script.sh
More file actions
executable file
·196 lines (173 loc) · 4.35 KB
/
Copy pathopk_update_script.sh
File metadata and controls
executable file
·196 lines (173 loc) · 4.35 KB
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
#!/bin/sh
cd `dirname $0`
DATE_FILE=./date.txt
export DIALOGOPTS="--colors --no-shadow"
if [ -f "$DATE_FILE" ] ; then
DATE="`cat $DATE_FILE`"
export DIALOGOPTS="$DIALOGOPTS --backtitle \"OpenDingux update $DATE\""
fi
echo "screen_color = (RED,RED,ON)" > /tmp/dialog_err.rc
# ----------
# 1. Select and confirm device
# ----------
THISDEVICE=./thisdevice
DEVICE=$($THISDEVICE --detect)
while true; do
if [ -n "$DEVICE" ]; then
eval $($THISDEVICE --device $DEVICE | grep DEVICE_NAME)
if [ -z "$DEVICE_NAME" ]; then
DEVICE=
continue
fi
DEVICE_LINE="
\Zb\Z3$DEVICE_NAME\Zn
"
if [ "$DEVICE_SELECTED" -eq 1 ]; then
TITLE="The selected device is"
else
TITLE="We detected this device as"
fi
DEVICE_CONFIRMATION="$TITLE:
$DEVICE_LINE
Flashing incorrect firmware will
likely make your device unbootable.
You can select your device from
manually from the list.
Proceed with the current device?"
dialog --yes-label 'Continue' --no-label 'Select' \
--yesno "$DEVICE_CONFIRMATION" 0 0
if [ $? -eq 0 ] ; then
break
fi
else
DEVICE_WARNING="\Zb\Z1We could not detect your device\Zn
Flashing incorrect firmware will
likely make your device unbootable.
Please CAREFULLY select your device
manually from the list."
dialog --defaultno --yes-label 'Select' --no-label 'Exit' \
--yesno "$DEVICE_WARNING" 0 0
if [ $? -ne 0 ] ; then
exit $?
fi
fi
exec 3>&1
NEW_DEVICE=$($THISDEVICE --devices $1 | while read i; do
echo $i | cut -d'-' -f1 | xargs
echo $i | cut -d'-' -f2- | xargs
done | tr \\n \\0 | xargs -0 \
dialog --menu "Select your device from the list" 0 0 3 \
2>&1 1>&3)
EXIT_STATUS=$?
exec 3>&-
if [ $EXIT_STATUS -ne 0 ] ; then
continue
fi
DEVICE=$NEW_DEVICE
DEVICE_SELECTED=1
done
# ----------
# 2. Final confirmation
# ----------
DISCLAIMER="\Zb\Z3NOTICE\Zn
While we carefully constructed this
updater, it is possible flaws in
the updater or in the updated OS
could lead to \Zb\Z3data loss\Zn.
We recommend that you \Zb\Z3backup\Zn
all valuable personal data before
you perform the update.
Do you want to update now?"
dialog --defaultno --yes-label 'Update' --no-label 'Cancel' --yesno "$DISCLAIMER" 0 0
if [ $? -ne 0 ] ; then
exit $?
fi
# ----------
# 3. Flashing
# ----------
clear
echo 'Update in progress - please be patient.'
echo
if [ "$(whoami)" = "root" -a ! -x /usr/sbin/od-update ]; then
./od-update "$1" "$DEVICE"
else
# Old firmware's od-update requires equally one argument
# and ENV variables are restricted by sudo
# so the only way to pass the device is via a tmp file
echo "$DEVICE" > /tmp/_force_thisdevice
sudo od-update $1
fi
# ----------
# 4. Checking status
# ----------
ERR=$?
if [ $ERR -ne 0 ] ; then
case $ERR in
2)
ERR_MSG="Failed to update rootfs!\nDo you have enough space available?"
;;
3)
ERR_MSG="Failed to update mininit!"
;;
4)
ERR_MSG="Failed to update kernel!"
;;
5)
ERR_MSG="Failed to update modules!"
;;
6)
ERR_MSG="Failed to update bootloader!"
;;
7)
ERR_MSG="Updated rootfs is corrupted!\nPlease report this bug!"
;;
8)
ERR_MSG="Updated mininit is corrupted!\nPlease report this bug!"
;;
9)
ERR_MSG="Updated kernel is corrupted!\nPlease report this bug!"
;;
10)
ERR_MSG="Updated devicetree is corrupted!\nPlease report this bug!"
;;
11)
ERR_MSG="Updated bootloader is corrupted!\nPlease report this bug!"
;;
12)
ERR_MSG="Can't detect the device.\nPlease ensure that you are running a stock firmware"
;;
13)
ERR_MSG="Bootloader file $BOOTLOADER is missing\nPlease report this bug!"
;;
14)
ERR_MSG="Device tree file $DEVICETREE is missing\nPlease report this bug!"
;;
*)
ERR_MSG="Unexpected return code: $ERR\nPlease report this bug!"
;;
esac
export DIALOGRC="/tmp/dialog_err.rc"
dialog --msgbox "ERROR!\n\n${ERR_MSG}" 0 0
exit $ERR
fi
# ----------
# 5. Reboot
# ----------
case $1 in
rs90)
LAST_KERNEL=START
LAST_ROOTFS=R
;;
gcw0)
LAST_KERNEL=X
LAST_ROOTFS=Y
;;
esac
dialog --msgbox 'Update complete!\nThe system will now restart.\n\n
If for some reason the system fails to boot, try to press the
following keys while powering on the device:\n
- '"$LAST_KERNEL"' to boot the backup kernel,\n
- '"$LAST_ROOTFS"' to boot the backup rootfs.\n
Pressing both keys during the power-on sequence will load the very
same Operating System (kernel + rootfs) you had before upgrading.' 0 0
reboot