Skip to content

Commit ca2ab31

Browse files
authored
Merge pull request #10 from enovella/android10
Support Android 10 with latest Magisk
2 parents f8cc7a5 + a8c4916 commit ca2ab31

File tree

5 files changed

+131
-105
lines changed

5 files changed

+131
-105
lines changed

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

Lines changed: 119 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,180 @@
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 v19.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 19000 ] && 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+
# Global vars
43+
TMPDIR=/dev/tmp
44+
PERSISTDIR=/sbin/.magisk/mirror/persist
45+
46+
rm -rf $TMPDIR 2>/dev/null
47+
mkdir -p $TMPDIR
4748

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
49+
is_legacy_script() {
50+
unzip -l "$ZIPFILE" install.sh | grep -q install.sh
51+
return $?
52+
}
53+
54+
print_modname() {
55+
local len
56+
len=`echo -n $MODNAME | wc -c`
57+
len=$((len + 2))
58+
local pounds=`printf "%${len}s" | tr ' ' '*'`
59+
ui_print "$pounds"
60+
ui_print " $MODNAME "
61+
ui_print "$pounds"
62+
ui_print "*******************"
63+
ui_print " Powered by Magisk "
64+
ui_print "*******************"
65+
}
5266

5367
# Preperation for flashable zips
54-
get_outfd
68+
setup_flashable
5569

5670
# Mount partitions
5771
mount_partitions
5872

5973
# Detect version and architecture
6074
api_level_arch_detect
6175

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-
6576
# Setup busybox and binaries
6677
$BOOTMODE && boot_actions || recovery_actions
6778

68-
##########################################################################################
79+
##############
6980
# Preparation
70-
##########################################################################################
81+
##############
82+
83+
# Extract prop file
84+
unzip -o "$ZIPFILE" module.prop -d $TMPDIR >&2
85+
[ ! -f $TMPDIR/module.prop ] && abort "! Unable to extract zip file!"
86+
87+
$BOOTMODE && MODDIRNAME=modules_update || MODDIRNAME=modules
88+
MODULEROOT=$NVBASE/$MODDIRNAME
89+
MODID=`grep_prop id $TMPDIR/module.prop`
90+
MODPATH=$MODULEROOT/$MODID
91+
MODNAME=`grep_prop name $TMPDIR/module.prop`
92+
93+
# Create mod paths
94+
rm -rf $MODPATH 2>/dev/null
95+
mkdir -p $MODPATH
7196

72-
# Extract common files
73-
unzip -o "$ZIP" module.prop config.sh 'common/*' -d $INSTALLER >&2
97+
##########
98+
# Install
99+
##########
74100

75-
[ ! -f $INSTALLER/config.sh ] && abort "! Unable to extract zip file!"
76-
# Load configurations
77-
. $INSTALLER/config.sh
101+
if is_legacy_script; then
102+
unzip -oj "$ZIPFILE" module.prop install.sh uninstall.sh 'common/*' -d $TMPDIR >&2
78103

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
104+
# Load install script
105+
. $TMPDIR/install.sh
84106

85-
# Print mod name
86-
print_modname
107+
# Callbacks
108+
print_modname
109+
on_install
87110

88-
# Please leave this message in your flashable zip for credits :)
89-
ui_print "******************************"
90-
ui_print "Powered by Magisk (@topjohnwu)"
91-
ui_print "******************************"
111+
# Custom uninstaller
112+
[ -f $TMPDIR/uninstall.sh ] && cp -af $TMPDIR/uninstall.sh $MODPATH/uninstall.sh
92113

93-
##########################################################################################
94-
# Install
95-
##########################################################################################
114+
# Skip mount
115+
$SKIPMOUNT && touch $MODPATH/skip_mount
96116

97-
# Get the variable reqSizeM. Use your own method to determine reqSizeM if needed
98-
request_zip_size_check "$ZIP"
117+
# prop file
118+
$PROPFILE && cp -af $TMPDIR/system.prop $MODPATH/system.prop
99119

100-
# This function will mount $IMG to $MOUNTPATH, and resize the image based on $reqSizeM
101-
mount_magisk_img
120+
# Module info
121+
cp -af $TMPDIR/module.prop $MODPATH/module.prop
102122

103-
# Create mod paths
104-
rm -rf $MODPATH 2>/dev/null
105-
mkdir -p $MODPATH
123+
# post-fs-data scripts
124+
$POSTFSDATA && cp -af $TMPDIR/post-fs-data.sh $MODPATH/post-fs-data.sh
125+
126+
# service scripts
127+
$LATESTARTSERVICE && cp -af $TMPDIR/service.sh $MODPATH/service.sh
106128

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
129+
ui_print "- Setting permissions"
130+
set_permissions
131+
else
132+
print_modname
110133

111-
# Remove placeholder
112-
rm -f $MODPATH/system/placeholder 2>/dev/null
134+
unzip -o "$ZIPFILE" customize.sh -d $MODPATH >&2
135+
136+
if ! grep -q '^SKIPUNZIP=1$' $MODPATH/customize.sh 2>/dev/null; then
137+
ui_print "- Extracting module files"
138+
unzip -o "$ZIPFILE" -x 'META-INF/*' -d $MODPATH >&2
139+
140+
# Default permissions
141+
set_perm_recursive $MODPATH 0 0 0755 0644
142+
fi
143+
144+
# Load customization script
145+
[ -f $MODPATH/customize.sh ] && . $MODPATH/customize.sh
146+
fi
113147

114148
# Handle replace folders
115149
for TARGET in $REPLACE; do
150+
ui_print "- Replace target: $TARGET"
116151
mktouch $MODPATH$TARGET/.replace
117152
done
118153

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
127154
if $BOOTMODE; then
128155
# Update info for Magisk Manager
129-
mktouch /sbin/.core/img/$MODID/update
130-
cp -af $INSTALLER/module.prop /sbin/.core/img/$MODID/module.prop
156+
mktouch $NVBASE/modules/$MODID/update
157+
cp -af $MODPATH/module.prop $NVBASE/modules/$MODID/module.prop
131158
fi
132159

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
160+
# Copy over custom sepolicy rules
161+
if [ -f $MODPATH/sepolicy.rule -a -e $PERSISTDIR ]; then
162+
ui_print "- Installing custom sepolicy patch"
163+
PERSISTMOD=$PERSISTDIR/magisk/$MODID
164+
mkdir -p $PERSISTMOD
165+
cp -af $MODPATH/sepolicy.rule $PERSISTMOD/sepolicy.rule
166+
fi
138167

139-
ui_print "- Setting permissions"
140-
set_permissions
168+
# Remove stuffs that don't belong to modules
169+
rm -rf \
170+
$MODPATH/system/placeholder $MODPATH/customize.sh \
171+
$MODPATH/README.md $MODPATH/.git* 2>/dev/null
141172

142-
##########################################################################################
173+
##############
143174
# Finalizing
144-
##########################################################################################
145-
146-
# Unmount magisk image and shrink if possible
147-
unmount_magisk_img
175+
##############
148176

177+
cd /
149178
$BOOTMODE || recovery_cleanup
150179
rm -rf $TMPDIR
151180

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ This module makes all installed user certificates part of the system certificate
1313
6. The installed user certificates can now be found in the system store.
1414

1515
### Changelog
16+
#### v0.4
17+
* Supports Android 10
18+
* Updated Module to be compatible with latest Magisk module template (v20.3+)
19+
1620
#### v0.3
1721
* 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.
1822

@@ -25,4 +29,4 @@ This module makes all installed user certificates part of the system certificate
2529

2630

2731

28-
Template used from [Magisk's module template](https://github.com/topjohnwu/magisk-module-template)
32+
Template partially used from [Magisk's module template](https://github.com/topjohnwu/magisk-module-template)

common/post-fs-data.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

customize.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mkdir -p $MODPATH/system/etc/security/cacerts
2+
rm -f $MODPATH/system/etc/security/cacerts/*
3+
cp -f /data/misc/user/0/cacerts-added/* $MODPATH/system/etc/security/cacerts/
4+

module.prop

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
id=trustusercerts
22
name=Always Trust User Certificates
3-
version=v0.3
3+
version=v0.4
44
versionCode=1
5-
author=Jeroen Beckers (NVISO.be)
5+
author=Jeroen Beckers (NVISO.be) & Eduardo Novella (NowSecure)
66
description=This module adds all installed user certificates to the system trust store.
7-
minMagisk=1500
7+
minMagisk=20300

0 commit comments

Comments
 (0)