/
update-binary
executable file
·160 lines (131 loc) · 5.99 KB
/
update-binary
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
#!/sbin/sh
# An extensible custom Hybris Installer script.
# https://git.io/fjMH9
# Details about this version:
# Device : %DEVICE%
# Release : %VERSION%
# Date : %DATE%
# Size : ~%IMAGE_SIZE%
# >>> TWRP init >>>
OUTFD="/proc/self/fd/$2" # e.g. "/proc/self/fd/28"
ZIPFILE="$3" # e.g. "/sdcard/%DST_PKG%.zip"
FILES="/tmp/hybris-installer"
# Set progress bar percentage using a fraction ($1) in range 0.00 - 1.00
set_progress() { echo -e "set_progress $1\n" > $OUTFD; }
# Print some text ($1) on the screen
ui_print() { [ -z "$1" ] && echo -e "ui_print \nui_print" > $OUTFD || echo -e "ui_print $@\nui_print" > $OUTFD; }
# Log some text ($1) for script debugging
log() { echo "hybris-installer: $@"; }
# Remove package residue files from /tmp and unmount partitions
cleanup() { log "Cleaning up..."; umount /system; rm -rf $FILES/; }
# Before quitting with an exit code ($1), show a message ($2)
abort() { ui_print "E$1: $2"; cleanup; exit $1; }
# <<< TWRP init <<<
# Constants & variables
VERSION="%VERSION%" # e.g. "3.2.0.12 (Torronsuo)"
TARGET_LOS_VER="%LOS_VER%" # e.g. "16.0"
TARGET_DEVICE="%DEVICE%" # e.g. "cheeseburger"
CURRENT_DEVICE=`getprop ro.product.device`
ROOT="/data/.stowaways/sailfishos"
FORCE_REINSTALL=0
# >>> Sanity checks >>>
# Device
[ "$CURRENT_DEVICE" != "$TARGET_DEVICE" ] && abort 7 "This package is for '$TARGET_DEVICE' devices; this is a '$CURRENT_DEVICE'."
# ext4 check for /cache & /data
(mount | grep -q /cache || mount /cache) || abort 1 "Couldn't mount /cache!"
mount | grep -q "/cache.*ext4" || abort 2 "Cache is NOT formatted as ext4; check out 'Wipe > Advanced' from TWRP!"
(mount | grep -q /data || mount /data) || abort 3 "Couldn't mount /data; running e2fsck and rebooting may help."
mount | grep -q "/data.*ext4" || abort 4 "Data is NOT formatted as ext4; check out 'Wipe > Advanced' from TWRP!"
# Treble
[ -r /dev/block/bootdevice/by-name/vendor ] || abort 5 "A vendor partition doesn't exist; you need to do an OTA from OxygenOS 5.1.5 to 5.1.6!"
# Android
(mount | grep -q /system || mount /system) || abort 6 "Couldn't mount /system!"
if [ `cat /system/build.prop | grep lineage.build.version= | cut -d'=' -f2` != "$TARGET_LOS_VER" ]; then
if [ ! -f /tmp/sfos_flash_confirm ]; then
touch /tmp/sfos_flash_confirm
abort 8 "If you don't know what you're doing: please factory reset & dirty flash LineageOS $TARGET_LOS_VER before this zip. Otherwise reflash again to confirm force flashing of SFOS."
fi
log "About to perform forced flash of SFOS"
fi
[ -f /system/bin/toybox ] || abort 9 "Your ROM doesn't ship with toybox; extracting of SFOS rootfs isn't possible!"
if [ -f $ROOT/etc/os-release ]; then
if [ ! -f /tmp/sfos_fresh_confirm ]; then
touch /tmp/sfos_fresh_confirm
abort 10 "This zip is NOT an OTA and should not be treated like one. Please reflash once more to confirm a full SFOS reinstall!"
fi
FORCE_REINSTALL=1
log "About to perform forced reinstall of SFOS; preserving droid-boot image..."
mv $ROOT/boot/droid-boot.img /tmp/
fi
rm -f /tmp/sfos_f{la,re}sh_confirm
# <<< Sanity checks <<<
# >>> Script >>>
# Reset shown progress bar to 0%
set_progress 0
# Calculate centering offset indent on left
offset=`echo -n $VERSION | wc -m` # Character length of the version string
offset=`expr 52 - 23 - $offset` # Remove constant string chars from offset calculation
offset=`expr $offset / 2` # Get left offset char count instead of space on both sides
# Build the left side indentation offset string
for i in `seq 1 $offset`; do indent="${indent} "; done
# Splash
ui_print
ui_print "-===============- Hybris Installer -===============-"
ui_print
ui_print " .':oOl."
ui_print " ':c::;ol."
ui_print " .:do, ,l."
ui_print " .;k0l. .ll. .."
ui_print " 'ldkc .,cdoc:'. ..,;:::;"
ui_print " ,o,;o'.;::;'. 'coxxolc:;'."
ui_print " 'o, 'ddc,. .;::::,."
ui_print " cl ,x: .;:c:,."
ui_print " ;l. .:ldoc,."
ui_print " .:c. .:ll,"
ui_print " 'c;. .;l:"
ui_print " :xc. ,o'"
ui_print " 'xxc. ;o."
ui_print " :l'c: ,lo,"
ui_print " ,o'.ooclc'"
ui_print " .:l,,x0o;."
ui_print " .;llcldl,"
ui_print " .,oOOoc:'"
ui_print " .,:lddo:'."
ui_print " oxxo;."
ui_print
ui_print "${indent}Installing Sailfish OS $VERSION"
ui_print " Please wait ..."
# Start
log "Extracting package '$ZIPFILE'..."
mkdir -p $FILES/
unzip -o "$ZIPFILE" -x META-INF/* -d $FILES/
log "Extracting SFOS rootfs..."
ARCHIVE="$FILES/sfos-rootfs.tar.bz2"
rm -rf $ROOT/
mkdir -p $ROOT/
/system/bin/toybox tar -xj -f $ARCHIVE -C $ROOT/ || abort 11 "Couldn't extract SFOS rootfs!"
rm $ARCHIVE
log "Fixing up init scripts..."
sed -e "/extraenv/s/^/#/g" -e "/import \/init.\${ro.hardware}.rc/s/^/#/" -e "/ro.zygote/s/^/#/g" -e "/start update_verifier/s/^/#/g" \
-e "s/\/cpus\ /\/cpuset.cpus /g" -e "s/\/cpus$/\/cpuset.cpus/g" -e "s/\/mems\ /\/cpuset.mems /g" -e "s/\/mems$/\/cpuset.mems/g" \
-i $ROOT/init.rc || log "Couldn't fix-up init script!"
rm $ROOT/init.extraenv.armeabi-v7a.rc
log "Disabling forced encryption in vendor fstab..."
(umount /vendor &> /dev/null; mount -o rw /vendor && sed "s/fileencryption/encryptable/" -i /vendor/etc/fstab.qcom) || log "Couldn't disable forced encryption!"
umount /vendor &
if [ "$FORCE_REINSTALL" = "0" ]; then
log "Backing up droid-boot image..."
dd if=/dev/block/bootdevice/by-name/boot of=$ROOT/boot/droid-boot.img
elif [ -f /tmp/droid-boot.img ]; then
log "Moving back droid-boot image..."
mv /tmp/droid-boot.img $ROOT/boot/
fi
log "Writing hybris-boot image..."
dd if=$ROOT/boot/hybris-boot.img of=/dev/block/bootdevice/by-name/boot || abort 12 "Couldn't write Hybris boot image!"
# <<< Script <<<
# Succeeded.
log "Sailfish OS installed successfully."
ui_print " All done, enjoy your new OS!"
ui_print
cleanup
exit 0