@@ -8,108 +8,142 @@ busybox devmem ${WTFOS_SELINUX_DISABLE} 32 0
8
8
9
9
cd /blackbox/wtfos/
10
10
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" ;
13
62
do
14
- /system/bin/umount -d -l /system
63
+ /system/xbin/busybox mount -t ext4 -o loop,rw /blackbox/wtfos/system.img /system
15
64
sleep 1
16
65
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}
25
68
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
26
74
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
+ }
32
115
33
- # doesn't work (nor matter) on gl170
34
- /system/xbin/busybox mount -o bind,ro /blackbox/wtfos/cmdline /proc/cmdline || true
35
116
36
117
# because when you build in wsl from your windows home dir permissions are bad
37
118
find . -name \* .sh -type f -exec chmod u+x {} \;
38
119
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
78
130
sleep 1
79
131
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
98
132
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
106
134
135
+ while mount | grep ' system_2 /system' -q > /dev/null;
136
+ do
137
+ /system/bin/umount -d -l /system
138
+ sleep 1
139
+ done
107
140
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
114
141
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
0 commit comments