Skip to content

Commit

Permalink
Merge pull request #10 from enovella/android10
Browse files Browse the repository at this point in the history
Support Android 10 with latest Magisk
  • Loading branch information
TheDauntless authored Apr 29, 2020
2 parents f8cc7a5 + a8c4916 commit ca2ab31
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 105 deletions.
209 changes: 119 additions & 90 deletions META-INF/com/google/android/update-binary
Original file line number Diff line number Diff line change
@@ -1,151 +1,180 @@
#!/sbin/sh
##########################################################################################
#
# Magisk Module Template Install Script
# by topjohnwu
#
##########################################################################################

# Detect whether in boot mode
ps | grep zygote | grep -v grep >/dev/null && BOOTMODE=true || BOOTMODE=false
$BOOTMODE || ps -A 2>/dev/null | grep zygote | grep -v grep >/dev/null && BOOTMODE=true
#################
# Initialization
#################

TMPDIR=/dev/tmp
INSTALLER=$TMPDIR/install
MAGISKBIN=/data/adb/magisk

# Default permissions
umask 022

# Initial cleanup
rm -rf $TMPDIR 2>/dev/null
mkdir -p $INSTALLER

# echo before loading util_functions
ui_print() { echo "$1"; }

require_new_magisk() {
ui_print "*******************************"
ui_print " Please install Magisk v15.0+! "
ui_print " Please install Magisk v19.0+! "
ui_print "*******************************"
exit 1
}

##########################################################################################
# Environment
##########################################################################################
#########################
# Load util_functions.sh
#########################

OUTFD=$2
ZIP=$3
ZIPFILE=$3

mount /data 2>/dev/null

# Utility functions must exist
[ -f $MAGISKBIN/util_functions.sh ] || require_new_magisk
# Load utility fuctions
. $MAGISKBIN/util_functions.sh
[ -f /data/adb/magisk/util_functions.sh ] || require_new_magisk
. /data/adb/magisk/util_functions.sh
[ $MAGISK_VER_CODE -lt 19000 ] && require_new_magisk

if [ $MAGISK_VER_CODE -ge 20400 ]; then
# New Magisk have complete installation logic within util_functions.sh
install_module
exit 0
fi

#################
# Legacy Support
#################

# Global vars
TMPDIR=/dev/tmp
PERSISTDIR=/sbin/.magisk/mirror/persist

rm -rf $TMPDIR 2>/dev/null
mkdir -p $TMPDIR

# We can't alter magisk image live, use alternative image if required
$BOOTMODE && IMG=/data/adb/magisk_merge.img
# Always mount under tmp
MOUNTPATH=$TMPDIR/magisk_img
is_legacy_script() {
unzip -l "$ZIPFILE" install.sh | grep -q install.sh
return $?
}

print_modname() {
local len
len=`echo -n $MODNAME | wc -c`
len=$((len + 2))
local pounds=`printf "%${len}s" | tr ' ' '*'`
ui_print "$pounds"
ui_print " $MODNAME "
ui_print "$pounds"
ui_print "*******************"
ui_print " Powered by Magisk "
ui_print "*******************"
}

# Preperation for flashable zips
get_outfd
setup_flashable

# Mount partitions
mount_partitions

# Detect version and architecture
api_level_arch_detect

# You can get the Android API version from $API, the CPU architecture from $ARCH
# Useful if you are creating Android version / platform dependent mods

# Setup busybox and binaries
$BOOTMODE && boot_actions || recovery_actions

##########################################################################################
##############
# Preparation
##########################################################################################
##############

# Extract prop file
unzip -o "$ZIPFILE" module.prop -d $TMPDIR >&2
[ ! -f $TMPDIR/module.prop ] && abort "! Unable to extract zip file!"

$BOOTMODE && MODDIRNAME=modules_update || MODDIRNAME=modules
MODULEROOT=$NVBASE/$MODDIRNAME
MODID=`grep_prop id $TMPDIR/module.prop`
MODPATH=$MODULEROOT/$MODID
MODNAME=`grep_prop name $TMPDIR/module.prop`

# Create mod paths
rm -rf $MODPATH 2>/dev/null
mkdir -p $MODPATH

# Extract common files
unzip -o "$ZIP" module.prop config.sh 'common/*' -d $INSTALLER >&2
##########
# Install
##########

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

# Check the installed magisk version
MIN_VER=`grep_prop minMagisk $INSTALLER/module.prop`
[ ! -z $MAGISK_VER_CODE -a $MAGISK_VER_CODE -ge $MIN_VER ] || require_new_magisk
MODID=`grep_prop id $INSTALLER/module.prop`
MODPATH=$MOUNTPATH/$MODID
# Load install script
. $TMPDIR/install.sh

# Print mod name
print_modname
# Callbacks
print_modname
on_install

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

##########################################################################################
# Install
##########################################################################################
# Skip mount
$SKIPMOUNT && touch $MODPATH/skip_mount

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

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

# Create mod paths
rm -rf $MODPATH 2>/dev/null
mkdir -p $MODPATH
# post-fs-data scripts
$POSTFSDATA && cp -af $TMPDIR/post-fs-data.sh $MODPATH/post-fs-data.sh

# service scripts
$LATESTARTSERVICE && cp -af $TMPDIR/service.sh $MODPATH/service.sh

# Extract files to system. Use your own method if needed
ui_print "- Extracting module files"
unzip -o "$ZIP" 'system/*' -d $MODPATH >&2
ui_print "- Setting permissions"
set_permissions
else
print_modname

# Remove placeholder
rm -f $MODPATH/system/placeholder 2>/dev/null
unzip -o "$ZIPFILE" customize.sh -d $MODPATH >&2

if ! grep -q '^SKIPUNZIP=1$' $MODPATH/customize.sh 2>/dev/null; then
ui_print "- Extracting module files"
unzip -o "$ZIPFILE" -x 'META-INF/*' -d $MODPATH >&2

# Default permissions
set_perm_recursive $MODPATH 0 0 0755 0644
fi

# Load customization script
[ -f $MODPATH/customize.sh ] && . $MODPATH/customize.sh
fi

# Handle replace folders
for TARGET in $REPLACE; do
ui_print "- Replace target: $TARGET"
mktouch $MODPATH$TARGET/.replace
done

# Auto Mount
$AUTOMOUNT && touch $MODPATH/auto_mount

# prop files
$PROPFILE && cp -af $INSTALLER/common/system.prop $MODPATH/system.prop

# Module info
cp -af $INSTALLER/module.prop $MODPATH/module.prop
if $BOOTMODE; then
# Update info for Magisk Manager
mktouch /sbin/.core/img/$MODID/update
cp -af $INSTALLER/module.prop /sbin/.core/img/$MODID/module.prop
mktouch $NVBASE/modules/$MODID/update
cp -af $MODPATH/module.prop $NVBASE/modules/$MODID/module.prop
fi

# post-fs-data mode scripts
$POSTFSDATA && cp -af $INSTALLER/common/post-fs-data.sh $MODPATH/post-fs-data.sh

# service mode scripts
$LATESTARTSERVICE && cp -af $INSTALLER/common/service.sh $MODPATH/service.sh
# Copy over custom sepolicy rules
if [ -f $MODPATH/sepolicy.rule -a -e $PERSISTDIR ]; then
ui_print "- Installing custom sepolicy patch"
PERSISTMOD=$PERSISTDIR/magisk/$MODID
mkdir -p $PERSISTMOD
cp -af $MODPATH/sepolicy.rule $PERSISTMOD/sepolicy.rule
fi

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

##########################################################################################
##############
# Finalizing
##########################################################################################

# Unmount magisk image and shrink if possible
unmount_magisk_img
##############

cd /
$BOOTMODE || recovery_cleanup
rm -rf $TMPDIR

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ This module makes all installed user certificates part of the system certificate
6. The installed user certificates can now be found in the system store.

### Changelog
#### v0.4
* Supports Android 10
* Updated Module to be compatible with latest Magisk module template (v20.3+)

#### v0.3
* 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.

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



Template used from [Magisk's module template](https://github.com/topjohnwu/magisk-module-template)
Template partially used from [Magisk's module template](https://github.com/topjohnwu/magisk-module-template)
11 changes: 0 additions & 11 deletions common/post-fs-data.sh

This file was deleted.

4 changes: 4 additions & 0 deletions customize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mkdir -p $MODPATH/system/etc/security/cacerts
rm -f $MODPATH/system/etc/security/cacerts/*
cp -f /data/misc/user/0/cacerts-added/* $MODPATH/system/etc/security/cacerts/

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

0 comments on commit ca2ab31

Please sign in to comment.