Skip to content

Commit d9073a9

Browse files
committed
Code cleanup & visual improvements
1 parent f97aef1 commit d9073a9

File tree

4 files changed

+30
-40
lines changed

4 files changed

+30
-40
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# boot-switcher
2-
A simple flashable zip to switch between LineageOS and Sailfish OS boots (cheeseburger). Feel free to fork and adapt to your device's needs!
2+
A simple flashable zip to switch between LineageOS and Sailfish OS boots specialized for cheeseburger (OnePlus 5) & dumpling (OnePlus 5T) devices by default. Feel free to fork and adapt to your device's needs!
33

44
### Screenshots
55

boot-switcher/META-INF/com/google/android/update-binary

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,23 @@
55
# >>> TWRP init >>>
66

77
OUTFD="/proc/self/fd/$2" # e.g. "/proc/self/fd/28"
8-
ZIPFILE="$3" # e.g. "/sdcard/Switch-Boot-Target-SFOS-LOS.zip"
98

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; }
1411

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; }
2014

21-
# <<< TWRP init <<<
15+
# Log some text ($1) for script debugging
16+
log() { echo "boot-switcher: $@"; }
2217

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/; }
2420

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; }
2923

30-
# <<< Custom functions <<<
24+
# <<< TWRP init <<<
3125

3226
# Constants & variables
3327
TARGET_DEVICES="cheeseburger dumpling"
@@ -41,9 +35,7 @@ ROOT="/data/.stowaways/sailfishos"
4135
echo $TARGET_DEVICES | grep -q $CURRENT_DEVICE || abort 7 "This package is for '$TARGET_DEVICES' devices; this is a '$CURRENT_DEVICE'."
4236

4337
# 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!"
4739

4840
# Android
4941
umount /vendor &> /dev/null
@@ -57,14 +49,16 @@ log "Android OS installation detected"
5749
umount /data &> /dev/null
5850
mount /data || abort 5 "Couldn't mount /data; running e2fsck and rebooting may help."
5951
[[ -f $ROOT/etc/os-release && -f $ROOT/boot/droid-boot.img ]] || abort 6 "Please install Sailfish OS before flashing this zip."
60-
6152
log "Sailfish OS installation detected"
6253
log "Passed sanity checks (2/2)"
6354

6455
# <<< Sanity checks <<<
6556

6657
# >>> Script >>>
6758

59+
# Reset shown progress bar to 0%
60+
set_progress 0
61+
6862
# Boot target to switch to
6963
TARGET="droid"
7064
TARGET_DROID_LOS=1
@@ -124,9 +118,9 @@ offset=`expr $offset / 2` # Get left offset char count instead of
124118
for i in `seq 1 $offset`; do indent="${indent} "; done
125119

126120
# Splash
127-
ui_print " "
121+
ui_print
128122
ui_print "-=============- Boot Target Switcher -=============-"
129-
ui_print " "
123+
ui_print
130124
if [ "$TARGET" = "hybris" ]; then
131125
ui_print " .':oOl."
132126
ui_print " ':c::;ol."
@@ -150,10 +144,10 @@ if [ "$TARGET" = "hybris" ]; then
150144
ui_print " oxxo;."
151145
else
152146
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
157151
ui_print " __"
158152
ui_print " :clllcc:"
159153
ui_print " :okOOOOOOOOko:"
@@ -165,11 +159,11 @@ else
165159
ui_print " :kXx lK0l cOKkl: :lkKOc c0Ko xXk:"
166160
ui_print " l0Kkxx0Kd: :dO0OkxddxkO0Od: :dK0xxkK0l"
167161
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
173167
else
174168
ui_print " .od. .do."
175169
ui_print " 'kOolllllloOk'"
@@ -193,10 +187,9 @@ else
193187
ui_print " ,k00k, ,k00k,"
194188
fi
195189
fi
196-
ui_print " "
190+
ui_print
197191
ui_print "${indent}Switching to $TARGET_PRETTY"
198192
ui_print " Please wait ..."
199-
200193
log "New boot target: '$TARGET_PRETTY'"
201194

202195
# Start
@@ -210,14 +203,11 @@ fi
210203
log "Writing new boot image..."
211204
dd if=$ROOT/boot/$TARGET-boot.img of=/dev/block/bootdevice/by-name/boot || abort 8 "Writing new boot image failed."
212205

213-
log "Cleaning up..."
214-
umount /vendor &> /dev/null
215-
umount /system &> /dev/null
216-
217206
# <<< Script <<<
218207

219208
# Succeeded.
220209
log "Boot target updated successfully."
221210
ui_print " All done, enjoy your new OS!"
222-
ui_print " "
211+
ui_print
212+
cleanup
223213
exit 0

screenshots/los.png

-22.6 KB
Loading

screenshots/sfos.png

-20.4 KB
Loading

0 commit comments

Comments
 (0)