Skip to content

Commit 89041dd

Browse files
committed
made wtfos install in both slots
1 parent f4a64b1 commit 89041dd

File tree

4 files changed

+176
-104
lines changed

4 files changed

+176
-104
lines changed

wtfos-system/control/control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: wtfos-system
2-
Version: 0.1.7
2+
Version: 0.2.0
33
Maintainer: Joonas Trussmann [email protected]
44
Description: wtfos startup patches
55
Architecture: armv7-3.2

wtfos-system/control/postinst

Lines changed: 123 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -8,108 +8,142 @@ busybox devmem ${WTFOS_SELINUX_DISABLE} 32 0
88

99
cd /blackbox/wtfos/
1010

11-
if mount | grep "/dev/loop"; then
12-
while mount | grep "/dev/loop";
11+
patch_slot () {
12+
sys_path="/system"
13+
if [[ ! -f ${sys_path}/bin/${WTFOS_TARGET_SCRIPT}.orig ]]
14+
then
15+
cp ${sys_path}/bin/${WTFOS_TARGET_SCRIPT} ${sys_path}/bin/${WTFOS_TARGET_SCRIPT}.orig
16+
fi
17+
18+
#clean any previous wtfos installation
19+
sed -i '/#wtfos/,/#\/wtfos/d' ${sys_path}/bin/${WTFOS_TARGET_SCRIPT}
20+
21+
#insert out startup patches right after #!/system/bin/sh
22+
sed -i '/^#!\/system\/bin\/sh$/r templates/startup-tpl.sh' ${sys_path}/bin/${WTFOS_TARGET_SCRIPT}
23+
24+
#restore selinux context for the target script as it's the one disabling selinux...
25+
restorecon /system/bin/${WTFOS_TARGET_SCRIPT}
26+
27+
#remove old margerine startup patch
28+
if grep -q "#margerine" ${sys_path}/bin/setup_usb_serial.sh; then
29+
sed -i '/#margerine/,/#\/margerine/d' ${sys_path}/bin/setup_usb_serial.sh
30+
restorecon ${sys_path}/bin/setup_usb_serial.sh
31+
fi
32+
33+
if grep -q '"addtranslations" value="true"' ${sys_path}/gui/etc/diskorc.xml; then
34+
#fix disk fillup caused by addtranslations=true in diskorc, even on real system just in case
35+
busybox sed -i 's/addtranslations" value="true"/addtranslations" value="false"/' ${sys_path}/gui/etc/diskorc.xml
36+
#clean up after any previous mess
37+
sed -i '/.*===$/d' ${sys_path}/gui/lang/translation.*
38+
fi
39+
sync
40+
}
41+
42+
unmount_loop () {
43+
if mount | grep "/dev/loop"; then
44+
while mount | grep "/dev/loop";
45+
do
46+
/system/bin/umount -d -l /system
47+
sleep 1
48+
done
49+
echo "wtfos: loopmount unmounted"
50+
fi
51+
}
52+
53+
prepare_new_system () {
54+
# presume we're doing an upgrade
55+
# the configurator will wipe this during an uninstall
56+
if [[ ! -f ./system.img ]]; then
57+
#copy the current active slots system image to our overlay image
58+
dd if=/dev/block/platform/soc/f0000000.ahb/f0400000.dwmmc0/mirror/system of=./system.img
59+
fi
60+
#mount our new image
61+
until mount | grep -q "/dev/loop";
1362
do
14-
/system/bin/umount -d -l /system
63+
/system/xbin/busybox mount -t ext4 -o loop,rw /blackbox/wtfos/system.img /system
1564
sleep 1
1665
done
17-
echo "wtfos: loopmount unmounted"
18-
fi
19-
#remount system so we can patch it
20-
while mount | grep '/system ext4 ro' -q > /dev/null;
21-
do
22-
/system/bin/mount -o rw,remount /system
23-
sleep 1
24-
done
66+
#just in case, make sure we're not gonna get in an infite loop
67+
sed -i '/#wtfos/,/#\/wtfos/d' /system/bin/${WTFOS_TARGET_SCRIPT}
2568

69+
#remove old margerine startup patch
70+
if grep -q "#margerine" /system/bin/setup_usb_serial.sh; then
71+
sed -i '/#margerine/,/#\/margerine/d' /system/bin/setup_usb_serial.sh
72+
restorecon /system/bin/setup_usb_serial.sh
73+
fi
2674

27-
#prepare new cmdline for *150
28-
if mount | grep -q "/proc/cmdline"; then
29-
/system/bin/umount /proc/cmdline
30-
fi
31-
cat /proc/cmdline | busybox sed -e 's/state=production/state=engineering/g' -e 's/verity=1/verity=0/g' -e 's/debug=0/debug=1/g' > ./cmdline
75+
#make sure the next scripts don't mess with /blackbox
76+
for filename in /system/bin/start_dji_system*.sh; do
77+
if [[ ! -f ${filename}.orig ]]
78+
then
79+
cp ${filename} ${filename}.orig
80+
fi
81+
sed -i '/# judge blackbox is formated/,/# judge cache partition/c\# judge cache partition is formated or not\. if not, format it\.' ${filename}
82+
restorecon ${filename}
83+
done
84+
85+
#make our mkshrc.d work
86+
if [[ ! -f /system/etc/mkshrc.orig ]]
87+
then
88+
cp /system/etc/mkshrc /system/etc/mkshrc.orig
89+
fi
90+
sed -i '/#wtfos/,/#\/wtfos/d' /system/etc/mkshrc
91+
sed -i -e "/: place customisations above this line/ {r templates/mkshrc-tpl.sh" -e 'N}' /system/etc/mkshrc
92+
93+
94+
if grep -q '"addtranslations" value="true"' /system/gui/etc/diskorc.xml; then
95+
#fix disk fillup caused by addtranslations=true in diskorc
96+
busybox sed -i 's/addtranslations" value="true"/addtranslations" value="false"/' /system/gui/etc/diskorc.xml
97+
#clean up after any previous mess
98+
sed -i '/.*===$/d' /system/gui/lang/translation.*
99+
fi
100+
101+
sync
102+
unmount_loop
103+
}
104+
105+
prepare_cmdline () {
106+
#prepare new cmdline for *150
107+
if mount | grep -q "/proc/cmdline"; then
108+
/system/bin/umount /proc/cmdline
109+
fi
110+
cat /proc/cmdline | busybox sed -e 's/state=production/state=engineering/g' -e 's/verity=1/verity=0/g' -e 's/debug=0/debug=1/g' > ./cmdline
111+
112+
#doesn't work (nor matter) on gl170
113+
/system/xbin/busybox mount -o bind,ro /blackbox/wtfos/cmdline /proc/cmdline || true
114+
}
32115

33-
#doesn't work (nor matter) on gl170
34-
/system/xbin/busybox mount -o bind,ro /blackbox/wtfos/cmdline /proc/cmdline || true
35116

36117
#because when you build in wsl from your windows home dir permissions are bad
37118
find . -name \*.sh -type f -exec chmod u+x {} \;
38119

39-
# presume we're doing an upgrade
40-
# the configurator will wipe this during an uninstall
41-
if [[ ! -f ./system.img ]]; then
42-
#copy the current active slots system image to our overlay image
43-
dd if=/dev/block/platform/soc/f0000000.ahb/f0400000.dwmmc0/mirror/system of=./system.img
44-
fi
45-
46-
if [[ ! -f /system/bin/${WTFOS_TARGET_SCRIPT}.orig ]]
47-
then
48-
cp /system/bin/${WTFOS_TARGET_SCRIPT} /system/bin/${WTFOS_TARGET_SCRIPT}.orig
49-
fi
50-
51-
#clean any previous wtfos installation
52-
sed -i '/#wtfos/,/#\/wtfos/d' /system/bin/${WTFOS_TARGET_SCRIPT}
53-
54-
#insert out startup patches right after #!/system/bin/sh
55-
sed -i '/^#!\/system\/bin\/sh$/r templates/startup-tpl.sh' /system/bin/${WTFOS_TARGET_SCRIPT}
56-
57-
#restore selinux context for the target script as it's the one disabling selinux...
58-
restorecon /system/bin/${WTFOS_TARGET_SCRIPT}
59-
60-
#remove old margerine startup patch
61-
if grep -q "#margerine" /system/bin/setup_usb_serial.sh; then
62-
sed -i '/#margerine/,/#\/margerine/d' /system/bin/setup_usb_serial.sh
63-
restorecon /system/bin/setup_usb_serial.sh
64-
fi
65-
66-
if grep -q '"addtranslations" value="true"' /system/gui/etc/diskorc.xml; then
67-
#fix disk fillup caused by addtranslations=true in diskorc, even on real system just in case
68-
busybox sed -i 's/addtranslations" value="true"/addtranslations" value="false"/' /system/gui/etc/diskorc.xml
69-
#clean up after any previous mess
70-
sed -i '/.*===$/d' /system/gui/lang/translation.*
71-
fi
72-
73-
74-
#prepare our new image
75-
until mount | grep -q "/dev/loop";
76-
do
77-
/system/xbin/busybox mount -t ext4 -o loop,rw /blackbox/wtfos/system.img /system
120+
unmount_loop
121+
122+
#prepare wtfos system.img
123+
prepare_new_system
124+
125+
# patch the inactive slot
126+
127+
until mount | grep 'system_2 /system' -q > /dev/null;
128+
do
129+
mount -t ext4 /dev/block/platform/soc/f0000000.ahb/f0400000.dwmmc0/mirror/system_2 /system
78130
sleep 1
79131
done
80-
#just in case, make sure we're not gonna get in an infite loop
81-
sed -i '/#wtfos/,/#\/wtfos/d' /system/bin/${WTFOS_TARGET_SCRIPT}
82-
83-
#remove old margerine startup patch
84-
if grep -q "#margerine" /system/bin/setup_usb_serial.sh; then
85-
sed -i '/#margerine/,/#\/margerine/d' /system/bin/setup_usb_serial.sh
86-
restorecon /system/bin/setup_usb_serial.sh
87-
fi
88-
89-
#make sure the next scripts don't mess with /blackbox
90-
for filename in /system/bin/start_dji_system*.sh; do
91-
if [[ ! -f ${filename}.orig ]]
92-
then
93-
cp ${filename} ${filename}.orig
94-
fi
95-
sed -i '/# judge blackbox is formated/,/# judge cache partition/c\# judge cache partition is formated or not\. if not, format it\.' ${filename}
96-
restorecon ${filename}
97-
done
98132

99-
#make our mkshrc.d work
100-
if [[ ! -f /system/etc/mkshrc.orig ]]
101-
then
102-
cp /system/etc/mkshrc /system/etc/mkshrc.orig
103-
fi
104-
sed -i '/#wtfos/,/#\/wtfos/d' /system/etc/mkshrc
105-
sed -i -e "/: place customisations above this line/ {r templates/mkshrc-tpl.sh" -e 'N}' /system/etc/mkshrc
133+
patch_slot
106134

135+
while mount | grep 'system_2 /system' -q > /dev/null;
136+
do
137+
/system/bin/umount -d -l /system
138+
sleep 1
139+
done
107140

108-
if grep -q '"addtranslations" value="true"' /system/gui/etc/diskorc.xml; then
109-
#fix disk fillup caused by addtranslations=true in diskorc
110-
busybox sed -i 's/addtranslations" value="true"/addtranslations" value="false"/' /system/gui/etc/diskorc.xml
111-
#clean up after any previous mess
112-
sed -i '/.*===$/d' /system/gui/lang/translation.*
113-
fi
114141

115-
sync
142+
#remount system so we can patch it
143+
while mount | grep '/system ext4 ro' -q > /dev/null;
144+
do
145+
/system/bin/mount -o rw,remount /system
146+
sleep 1
147+
done
148+
#patch the active slot
149+
patch_slot

wtfos-system/control/prerm

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@ do
1111
tries=$((tries+1))
1212
done
1313

14+
patch_slot () {
15+
sys_path="/system"
16+
#clean any wtfos installation
17+
sed -i '/#wtfos/,/#\/wtfos/d' ${sys_path}/bin/${WTFOS_TARGET_SCRIPT}
18+
#keep selinux disable and adb unlock
19+
sed -i '/^#!\/system\/bin\/sh$/r /blackbox/wtfos/templates/adb-only-tpl.sh' ${sys_path}/bin/${WTFOS_TARGET_SCRIPT}
20+
#no blackbox, so replace var
21+
busybox sed -i "s/\${WTFOS_SELINUX_DISABLE}/${WTFOS_SELINUX_DISABLE}/g" ${sys_path}/bin/${WTFOS_TARGET_SCRIPT}
22+
23+
restorecon ${sys_path}/bin/${WTFOS_TARGET_SCRIPT}
24+
25+
#drop final adb removal script
26+
cp /blackbox/wtfos/wtfos-remove-adb ${sys_path}/bin/wtfos-remove-adb
27+
chmod u+x ${sys_path}/bin/wtfos-remove-adb
28+
busybox sed -i "s/\${WTFOS_TARGET_SCRIPT}/${WTFOS_TARGET_SCRIPT}/g" ${sys_path}/bin/wtfos-remove-adb
29+
30+
sync
31+
}
1432
#remount system so we can patch it
1533
if mount | grep "/dev/loop"; then
1634
while mount | grep "/dev/loop";
@@ -21,24 +39,25 @@ if mount | grep "/dev/loop"; then
2139
echo "wtfos: loopmount unmounted"
2240
fi
2341

24-
while mount | grep '/system ext4 ro' -q > /dev/null;
42+
# patch the inactive slot
43+
until mount | grep 'system_2 /system' -q > /dev/null;
2544
do
26-
/system/bin/mount -o rw,remount /system
45+
mount -t ext4 /dev/block/platform/soc/f0000000.ahb/f0400000.dwmmc0/mirror/system_2 /system
2746
sleep 1
2847
done
2948

30-
#clean any wtfos installation
31-
sed -i '/#wtfos/,/#\/wtfos/d' /system/bin/${WTFOS_TARGET_SCRIPT}
32-
#keep selinux disable and adb unlock
33-
sed -i '/^#!\/system\/bin\/sh$/r /blackbox/wtfos/templates/adb-only-tpl.sh' /system/bin/${WTFOS_TARGET_SCRIPT}
34-
#no blackbox, so replace var
35-
busybox sed -i "s/\${WTFOS_SELINUX_DISABLE}/${WTFOS_SELINUX_DISABLE}/g" /system/bin/${WTFOS_TARGET_SCRIPT}
49+
patch_slot
3650

37-
restorecon /system/bin/${WTFOS_TARGET_SCRIPT}
51+
while mount | grep 'system_2 /system' -q > /dev/null;
52+
do
53+
/system/bin/umount -d -l /system
54+
sleep 1
55+
done
3856

39-
#drop final adb removal script
40-
cp /blackbox/wtfos/wtfos-remove-adb /system/bin/wtfos-remove-adb
41-
chmod u+x /system/bin/wtfos-remove-adb
42-
busybox sed -i "s/\${WTFOS_TARGET_SCRIPT}/${WTFOS_TARGET_SCRIPT}/g" /system/bin/wtfos-remove-adb
57+
while mount | grep '/system ext4 ro' -q > /dev/null;
58+
do
59+
/system/bin/mount -o rw,remount /system
60+
sleep 1
61+
done
4362

44-
sync
63+
patch_slot

wtfos-system/data/blackbox/wtfos/wtfos-remove-adb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,32 @@ fi
77

88
remove_adb()
99
{
10+
#inactive system
11+
until mount | grep 'system_2 /system' -q > /dev/null;
12+
do
13+
mount -t ext4 /dev/block/platform/soc/f0000000.ahb/f0400000.dwmmc0/mirror/system_2 /system
14+
sleep 1
15+
done
16+
17+
sed -i '/#wtfos/,/#\/wtfos/d' /system/bin/${WTFOS_TARGET_SCRIPT}
18+
restorecon /system/bin/${WTFOS_TARGET_SCRIPT}
19+
sync
20+
21+
while mount | grep 'system_2 /system' -q > /dev/null;
22+
do
23+
/system/bin/umount -d -l /system
24+
sleep 1
25+
done
26+
27+
#active system
1028
while mount | grep '/system ext4 ro' -q > /dev/null;
1129
do
1230
/system/bin/mount -o rw,remount /system
1331
sleep 1
1432
done
1533
sed -i '/#wtfos/,/#\/wtfos/d' /system/bin/${WTFOS_TARGET_SCRIPT}
1634
restorecon /system/bin/${WTFOS_TARGET_SCRIPT}
35+
sync
1736
}
1837

1938
if [ "$1" = "-q" ]; then

0 commit comments

Comments
 (0)