5
5
# >>> TWRP init >>>
6
6
7
7
OUTFD=" /proc/self/fd/$2 " # e.g. "/proc/self/fd/28"
8
- ZIPFILE=" $3 " # e.g. "/sdcard/Switch-Boot-Target-SFOS-LOS.zip"
9
8
10
- # Print some text ($1) on the screen
11
- ui_print () {
12
- [ -z " $1 " ] && echo -e " ui_print \nui_print" > $OUTFD || echo -e " ui_print $@ \nui_print" > $OUTFD
13
- }
9
+ # Set progress bar percentage using a fraction ($1) in range 0.00 - 1.00
10
+ set_progress () { echo -e " set_progress $1 \n" > $OUTFD ; }
14
11
15
- # Before quitting with an exit code ($1), show a message ($2)
16
- abort () {
17
- ui_print " E$1 : $2 "
18
- exit $1
19
- }
12
+ # Print some text ($1) on the screen
13
+ ui_print () { [ -z " $1 " ] && echo -e " ui_print \nui_print" > $OUTFD || echo -e " ui_print $@ \nui_print" > $OUTFD ; }
20
14
21
- # <<< TWRP init <<<
15
+ # Log some text ($1) for script debugging
16
+ log () { echo " boot-switcher: $@ " ; }
22
17
23
- # >>> Custom functions >>>
18
+ # Remove package residue files from /tmp and unmount partitions
19
+ cleanup () { log " Cleaning up..." ; umount /vendor & > /dev/null; umount /system & > /dev/null; rm -rf $FILES /; }
24
20
25
- # Log some text ($1) for script debugging
26
- log () {
27
- echo " boot-switcher: $@ "
28
- }
21
+ # Before quitting with an exit code ($1), show a message ($2)
22
+ abort () { ui_print " E$1 : $2 " ; cleanup; exit $1 ; }
29
23
30
- # <<< Custom functions <<<
24
+ # <<< TWRP init <<<
31
25
32
26
# Constants & variables
33
27
TARGET_DEVICES=" cheeseburger dumpling"
@@ -41,9 +35,7 @@ ROOT="/data/.stowaways/sailfishos"
41
35
echo $TARGET_DEVICES | grep -q $CURRENT_DEVICE || abort 7 " This package is for '$TARGET_DEVICES ' devices; this is a '$CURRENT_DEVICE '."
42
36
43
37
# Treble
44
- if [ ! -r /dev/block/bootdevice/by-name/vendor ]; then
45
- abort 1 " A vendor partition doesn't exist; you need to do an OTA from OxygenOS 5.1.5 to 5.1.6!"
46
- fi
38
+ [ -r /dev/block/bootdevice/by-name/vendor ] || abort 1 " A vendor partition doesn't exist; you need to do an OTA from OxygenOS 5.1.5 to 5.1.6!"
47
39
48
40
# Android
49
41
umount /vendor & > /dev/null
@@ -57,14 +49,16 @@ log "Android OS installation detected"
57
49
umount /data & > /dev/null
58
50
mount /data || abort 5 " Couldn't mount /data; running e2fsck and rebooting may help."
59
51
[[ -f $ROOT /etc/os-release && -f $ROOT /boot/droid-boot.img ]] || abort 6 " Please install Sailfish OS before flashing this zip."
60
-
61
52
log " Sailfish OS installation detected"
62
53
log " Passed sanity checks (2/2)"
63
54
64
55
# <<< Sanity checks <<<
65
56
66
57
# >>> Script >>>
67
58
59
+ # Reset shown progress bar to 0%
60
+ set_progress 0
61
+
68
62
# Boot target to switch to
69
63
TARGET=" droid"
70
64
TARGET_DROID_LOS=1
@@ -124,9 +118,9 @@ offset=`expr $offset / 2` # Get left offset char count instead of
124
118
for i in ` seq 1 $offset ` ; do indent=" ${indent} " ; done
125
119
126
120
# Splash
127
- ui_print " "
121
+ ui_print
128
122
ui_print " -=============- Boot Target Switcher -=============-"
129
- ui_print " "
123
+ ui_print
130
124
if [ " $TARGET " = " hybris" ]; then
131
125
ui_print " .':oOl."
132
126
ui_print " ':c::;ol."
@@ -150,10 +144,10 @@ if [ "$TARGET" = "hybris" ]; then
150
144
ui_print " oxxo;."
151
145
else
152
146
if [ " $TARGET_DROID_LOS " = " 1" ]; then
153
- ui_print " "
154
- ui_print " "
155
- ui_print " "
156
- ui_print " "
147
+ ui_print
148
+ ui_print
149
+ ui_print
150
+ ui_print
157
151
ui_print " __"
158
152
ui_print " :clllcc:"
159
153
ui_print " :okOOOOOOOOko:"
@@ -165,11 +159,11 @@ else
165
159
ui_print " :kXx lK0l cOKkl: :lkKOc c0Ko xXk:"
166
160
ui_print " l0Kkxx0Kd: :dO0OkxddxkO0Od: :dK0xxkK0l"
167
161
ui_print " coxkkdl :ldxkkkkxdl: ldkkxoc"
168
- ui_print " "
169
- ui_print " "
170
- ui_print " "
171
- ui_print " "
172
- ui_print " "
162
+ ui_print
163
+ ui_print
164
+ ui_print
165
+ ui_print
166
+ ui_print
173
167
else
174
168
ui_print " .od. .do."
175
169
ui_print " 'kOolllllloOk'"
@@ -193,10 +187,9 @@ else
193
187
ui_print " ,k00k, ,k00k,"
194
188
fi
195
189
fi
196
- ui_print " "
190
+ ui_print
197
191
ui_print " ${indent} Switching to $TARGET_PRETTY "
198
192
ui_print " Please wait ..."
199
-
200
193
log " New boot target: '$TARGET_PRETTY '"
201
194
202
195
# Start
210
203
log " Writing new boot image..."
211
204
dd if=$ROOT /boot/$TARGET -boot.img of=/dev/block/bootdevice/by-name/boot || abort 8 " Writing new boot image failed."
212
205
213
- log " Cleaning up..."
214
- umount /vendor & > /dev/null
215
- umount /system & > /dev/null
216
-
217
206
# <<< Script <<<
218
207
219
208
# Succeeded.
220
209
log " Boot target updated successfully."
221
210
ui_print " All done, enjoy your new OS!"
222
- ui_print " "
211
+ ui_print
212
+ cleanup
223
213
exit 0
0 commit comments