diff --git a/META-INF/com/google/android/update-binary b/META-INF/com/google/android/update-binary index faf0884..a6a2ac6 100755 --- a/META-INF/com/google/android/update-binary +++ b/META-INF/com/google/android/update-binary @@ -1,57 +1,71 @@ #!/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 @@ -59,93 +73,108 @@ 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 diff --git a/README.md b/README.md index 24d8f7a..5008626 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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) diff --git a/common/post-fs-data.sh b/common/post-fs-data.sh deleted file mode 100644 index b9bbf71..0000000 --- a/common/post-fs-data.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/system/bin/sh -# Please don't hardcode /magisk/modname/... ; instead, please use $MODDIR/... -# This will make your scripts compatible even if Magisk change its mount point in the future -MODDIR=${0%/*} - -mkdir -p $MODDIR/system/etc/security/cacerts -rm $MODDIR/system/etc/security/cacerts/* -cp -f /data/misc/user/0/cacerts-added/* $MODDIR/system/etc/security/cacerts/ - -# This script will be executed in post-fs-data mode -# More info in the main Magisk thread diff --git a/customize.sh b/customize.sh new file mode 100644 index 0000000..f3564e9 --- /dev/null +++ b/customize.sh @@ -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/ + diff --git a/module.prop b/module.prop index 27d3ef4..d881556 100644 --- a/module.prop +++ b/module.prop @@ -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