Skip to content

Commit f3ff686

Browse files
committed
v0.4.1
1 parent f90465f commit f3ff686

6 files changed

Lines changed: 147 additions & 195 deletions

File tree

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

Lines changed: 133 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,194 @@
11
#!/sbin/sh
2-
##########################################################################################
3-
#
4-
# Magisk Module Template Install Script
5-
# by topjohnwu
6-
#
7-
##########################################################################################
82

9-
# Detect whether in boot mode
10-
ps | grep zygote | grep -v grep >/dev/null && BOOTMODE=true || BOOTMODE=false
11-
$BOOTMODE || ps -A 2>/dev/null | grep zygote | grep -v grep >/dev/null && BOOTMODE=true
3+
#################
4+
# Initialization
5+
#################
126

13-
TMPDIR=/dev/tmp
14-
INSTALLER=$TMPDIR/install
15-
MAGISKBIN=/data/adb/magisk
16-
17-
# Default permissions
187
umask 022
198

20-
# Initial cleanup
21-
rm -rf $TMPDIR 2>/dev/null
22-
mkdir -p $INSTALLER
23-
249
# echo before loading util_functions
2510
ui_print() { echo "$1"; }
2611

2712
require_new_magisk() {
2813
ui_print "*******************************"
29-
ui_print " Please install Magisk v15.0+! "
14+
ui_print " Please install Magisk v20.0+! "
3015
ui_print "*******************************"
3116
exit 1
3217
}
3318

34-
##########################################################################################
35-
# Environment
36-
##########################################################################################
19+
#########################
20+
# Load util_functions.sh
21+
#########################
3722

3823
OUTFD=$2
39-
ZIP=$3
24+
ZIPFILE=$3
4025

4126
mount /data 2>/dev/null
4227

43-
# Utility functions must exist
44-
[ -f $MAGISKBIN/util_functions.sh ] || require_new_magisk
45-
# Load utility fuctions
46-
. $MAGISKBIN/util_functions.sh
28+
[ -f /data/adb/magisk/util_functions.sh ] || require_new_magisk
29+
. /data/adb/magisk/util_functions.sh
30+
[ $MAGISK_VER_CODE -lt 20000 ] && require_new_magisk
31+
32+
if [ $MAGISK_VER_CODE -ge 20400 ]; then
33+
# New Magisk have complete installation logic within util_functions.sh
34+
install_module
35+
exit 0
36+
fi
37+
38+
#################
39+
# Legacy Support
40+
#################
41+
42+
TMPDIR=/dev/tmp
43+
PERSISTDIR=/sbin/.magisk/mirror/persist
44+
45+
is_legacy_script() {
46+
unzip -l "$ZIPFILE" install.sh | grep -q install.sh
47+
return $?
48+
}
49+
50+
print_modname() {
51+
local authlen len namelen pounds
52+
namelen=`echo -n $MODNAME | wc -c`
53+
authlen=$((`echo -n $MODAUTH | wc -c` + 3))
54+
[ $namelen -gt $authlen ] && len=$namelen || len=$authlen
55+
len=$((len + 2))
56+
pounds=$(printf "%${len}s" | tr ' ' '*')
57+
ui_print "$pounds"
58+
ui_print " $MODNAME "
59+
ui_print " by $MODAUTH "
60+
ui_print "$pounds"
61+
ui_print "*******************"
62+
ui_print " Powered by Magisk "
63+
ui_print "*******************"
64+
}
65+
66+
# Override abort as old scripts have some issues
67+
abort() {
68+
ui_print "$1"
69+
$BOOTMODE || recovery_cleanup
70+
[ -n $MODPATH ] && rm -rf $MODPATH
71+
rm -rf $TMPDIR
72+
exit 1
73+
}
4774

48-
# We can't alter magisk image live, use alternative image if required
49-
$BOOTMODE && IMG=/data/adb/magisk_merge.img
50-
# Always mount under tmp
51-
MOUNTPATH=$TMPDIR/magisk_img
75+
rm -rf $TMPDIR 2>/dev/null
76+
mkdir -p $TMPDIR
5277

5378
# Preperation for flashable zips
54-
get_outfd
79+
setup_flashable
5580

5681
# Mount partitions
5782
mount_partitions
5883

5984
# Detect version and architecture
6085
api_level_arch_detect
6186

62-
# You can get the Android API version from $API, the CPU architecture from $ARCH
63-
# Useful if you are creating Android version / platform dependent mods
64-
6587
# Setup busybox and binaries
6688
$BOOTMODE && boot_actions || recovery_actions
6789

68-
##########################################################################################
90+
##############
6991
# Preparation
70-
##########################################################################################
92+
##############
7193

72-
# Extract common files
73-
unzip -o "$ZIP" module.prop config.sh 'common/*' -d $INSTALLER >&2
94+
# Extract prop file
95+
unzip -o "$ZIPFILE" module.prop -d $TMPDIR >&2
96+
[ ! -f $TMPDIR/module.prop ] && abort "! Unable to extract zip file!"
7497

75-
[ ! -f $INSTALLER/config.sh ] && abort "! Unable to extract zip file!"
76-
# Load configurations
77-
. $INSTALLER/config.sh
98+
$BOOTMODE && MODDIRNAME=modules_update || MODDIRNAME=modules
99+
MODULEROOT=$NVBASE/$MODDIRNAME
100+
MODID=`grep_prop id $TMPDIR/module.prop`
101+
MODNAME=`grep_prop name $TMPDIR/module.prop`
102+
MODAUTH=`grep_prop author $TMPDIR/module.prop`
103+
MODPATH=$MODULEROOT/$MODID
78104

79-
# Check the installed magisk version
80-
MIN_VER=`grep_prop minMagisk $INSTALLER/module.prop`
81-
[ ! -z $MAGISK_VER_CODE -a $MAGISK_VER_CODE -ge $MIN_VER ] || require_new_magisk
82-
MODID=`grep_prop id $INSTALLER/module.prop`
83-
MODPATH=$MOUNTPATH/$MODID
105+
# Create mod paths
106+
rm -rf $MODPATH 2>/dev/null
107+
mkdir -p $MODPATH
84108

85-
# Print mod name
86-
print_modname
109+
##########
110+
# Install
111+
##########
87112

88-
# Please leave this message in your flashable zip for credits :)
89-
ui_print "******************************"
90-
ui_print "Powered by Magisk (@topjohnwu)"
91-
ui_print "******************************"
113+
if is_legacy_script; then
114+
unzip -oj "$ZIPFILE" module.prop install.sh uninstall.sh 'common/*' -d $TMPDIR >&2
92115

93-
##########################################################################################
94-
# Install
95-
##########################################################################################
116+
# Load install script
117+
. $TMPDIR/install.sh
96118

97-
# Get the variable reqSizeM. Use your own method to determine reqSizeM if needed
98-
request_zip_size_check "$ZIP"
119+
# Callbacks
120+
print_modname
121+
on_install
99122

100-
# This function will mount $IMG to $MOUNTPATH, and resize the image based on $reqSizeM
101-
mount_magisk_img
123+
# Custom uninstaller
124+
[ -f $TMPDIR/uninstall.sh ] && cp -af $TMPDIR/uninstall.sh $MODPATH/uninstall.sh
102125

103-
# Create mod paths
104-
rm -rf $MODPATH 2>/dev/null
105-
mkdir -p $MODPATH
126+
# Skip mount
127+
$SKIPMOUNT && touch $MODPATH/skip_mount
128+
129+
# prop file
130+
$PROPFILE && cp -af $TMPDIR/system.prop $MODPATH/system.prop
131+
132+
# Module info
133+
cp -af $TMPDIR/module.prop $MODPATH/module.prop
134+
135+
# post-fs-data scripts
136+
$POSTFSDATA && cp -af $TMPDIR/post-fs-data.sh $MODPATH/post-fs-data.sh
137+
138+
# service scripts
139+
$LATESTARTSERVICE && cp -af $TMPDIR/service.sh $MODPATH/service.sh
106140

107-
# Extract files to system. Use your own method if needed
108-
ui_print "- Extracting module files"
109-
unzip -o "$ZIP" 'system/*' -d $MODPATH >&2
141+
ui_print "- Setting permissions"
142+
set_permissions
143+
else
144+
print_modname
110145

111-
# Remove placeholder
112-
rm -f $MODPATH/system/placeholder 2>/dev/null
146+
unzip -o "$ZIPFILE" customize.sh -d $MODPATH >&2
147+
148+
if ! grep -q '^SKIPUNZIP=1$' $MODPATH/customize.sh 2>/dev/null; then
149+
ui_print "- Extracting module files"
150+
unzip -o "$ZIPFILE" -x 'META-INF/*' -d $MODPATH >&2
151+
152+
# Default permissions
153+
set_perm_recursive $MODPATH 0 0 0755 0644
154+
fi
155+
156+
# Load customization script
157+
[ -f $MODPATH/customize.sh ] && . $MODPATH/customize.sh
158+
fi
113159

114160
# Handle replace folders
115161
for TARGET in $REPLACE; do
162+
ui_print "- Replace target: $TARGET"
116163
mktouch $MODPATH$TARGET/.replace
117164
done
118165

119-
# Auto Mount
120-
$AUTOMOUNT && touch $MODPATH/auto_mount
121-
122-
# prop files
123-
$PROPFILE && cp -af $INSTALLER/common/system.prop $MODPATH/system.prop
124-
125-
# Module info
126-
cp -af $INSTALLER/module.prop $MODPATH/module.prop
127166
if $BOOTMODE; then
128167
# Update info for Magisk Manager
129-
mktouch /sbin/.core/img/$MODID/update
130-
cp -af $INSTALLER/module.prop /sbin/.core/img/$MODID/module.prop
168+
mktouch $NVBASE/modules/$MODID/update
169+
cp -af $MODPATH/module.prop $NVBASE/modules/$MODID/module.prop
131170
fi
132171

133-
# post-fs-data mode scripts
134-
$POSTFSDATA && cp -af $INSTALLER/common/post-fs-data.sh $MODPATH/post-fs-data.sh
135-
136-
# service mode scripts
137-
$LATESTARTSERVICE && cp -af $INSTALLER/common/service.sh $MODPATH/service.sh
172+
# Copy over custom sepolicy rules
173+
if [ -f $MODPATH/sepolicy.rule -a -e $PERSISTDIR ]; then
174+
ui_print "- Installing custom sepolicy patch"
175+
# Remove old recovery logs (which may be filling partition) to make room
176+
rm -f $PERSISTDIR/cache/recovery/*
177+
PERSISTMOD=$PERSISTDIR/magisk/$MODID
178+
mkdir -p $PERSISTMOD
179+
cp -af $MODPATH/sepolicy.rule $PERSISTMOD/sepolicy.rule || abort "! Insufficient partition size"
180+
fi
138181

139-
ui_print "- Setting permissions"
140-
set_permissions
182+
# Remove stuffs that don't belong to modules
183+
rm -rf \
184+
$MODPATH/system/placeholder $MODPATH/customize.sh \
185+
$MODPATH/README.md $MODPATH/.git* 2>/dev/null
141186

142-
##########################################################################################
187+
#############
143188
# Finalizing
144-
##########################################################################################
145-
146-
# Unmount magisk image and shrink if possible
147-
unmount_magisk_img
189+
#############
148190

191+
cd /
149192
$BOOTMODE || recovery_cleanup
150193
rm -rf $TMPDIR
151194

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,20 @@ This module makes all installed user certificates part of the system certificate
99
2. Zip files `zip -r AlwaysTrustUserCerts.zip ./*` or download zip from releases
1010
3. Install in Magisk
1111
4. Install client certificates through [normal flow](https://support.portswigger.net/customer/portal/articles/1841102-installing-burp-s-ca-certificate-in-an-android-device)
12-
5. Reboot
13-
6. The installed user certificates can now be found in the system store.
12+
5. The installed user certificates can now be found in the system store.
13+
14+
### Adding certificates
15+
Install the certificate as a user certificate and restart the device.
16+
17+
### Removing certificates
18+
Certificates are stored in `/data/adb/modules/trustusercerts/system/etc/security/cacerts`. To remove certificates, remove them from the directory through adb and restart your device.
1419

1520
### Changelog
1621

22+
#### v0.4.1
23+
* Supports Android 10
24+
* Updated Module to be compatible with latest Magisk module template (v20.4+)
25+
1726
#### v0.3
1827
* The module now removes all user-installed certificates from the system store before copying them over, so that user certificates that were removed will no longer be kept in the system store.
1928

@@ -23,6 +32,3 @@ This module makes all installed user certificates part of the system certificate
2332

2433
#### v0.1
2534
* Initial release
26-
27-
28-
Template used from [Magisk's module template](https://github.com/topjohnwu/magisk-module-template)

0 commit comments

Comments
 (0)