From 0708e652f49c8007e5c450010f500ef6c1205c74 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 6 Sep 2017 22:30:36 +0800 Subject: [PATCH 1/8] Magisk Module Template 1400 --- .gitattributes | 8 + META-INF/com/google/android/update-binary | 182 +++++++++++++++++++++ META-INF/com/google/android/updater-script | 1 + README.md | 10 ++ common/post-fs-data.sh | 7 + common/service.sh | 7 + common/system.prop | 3 + config.sh | 91 +++++++++++ module.prop | 7 + system/placeholder | 1 + 10 files changed, 317 insertions(+) create mode 100644 .gitattributes create mode 100755 META-INF/com/google/android/update-binary create mode 100644 META-INF/com/google/android/updater-script create mode 100644 common/post-fs-data.sh create mode 100644 common/service.sh create mode 100644 common/system.prop create mode 100644 config.sh create mode 100644 module.prop create mode 100644 system/placeholder diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..77749cc --- /dev/null +++ b/.gitattributes @@ -0,0 +1,8 @@ +# Declare files that will always have LF line endings on checkout. +META-INF/** text eol=lf +common/** text eol=lf +module.prop text eol=lf +changelog.txt text eol=lf + +# Denote all files that are truly binary and should not be modified. +system/** binary diff --git a/META-INF/com/google/android/update-binary b/META-INF/com/google/android/update-binary new file mode 100755 index 0000000..86c2be1 --- /dev/null +++ b/META-INF/com/google/android/update-binary @@ -0,0 +1,182 @@ +#!/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 + +# This path should work in any cases +TMPDIR=/dev/tmp +MOUNTPATH=/magisk +IMG=/data/magisk.img +if $BOOTMODE; then + MOUNTPATH=/dev/magisk_merge + IMG=/data/magisk_merge.img +fi +INSTALLER=$TMPDIR/install +MAGISKBIN=/data/magisk + +# Default permissions +umask 022 + +# Initial cleanup +rm -rf $TMPDIR 2>/dev/null +mkdir -p $INSTALLER + +########################################################################################## +# Environment +########################################################################################## + +OUTFD=$2 +ZIP=$3 + +ui_print() { + if $BOOTMODE; then + echo "$1" + else + echo -n -e "ui_print $1\n" >> /proc/self/fd/$OUTFD + echo -n -e "ui_print\n" >> /proc/self/fd/$OUTFD + fi +} + +require_new_magisk() { + ui_print "***********************************" + ui_print "! $MAGISKBIN isn't setup properly!" + ui_print "! Please install Magisk v14.0+!" + ui_print "***********************************" + exit 1 +} + +ui_print "- Mounting /system, /vendor, /data, /cache" +mount -o ro /system 2>/dev/null +mount -o ro /vendor 2>/dev/null +mount /data 2>/dev/null +mount /cache 2>/dev/null + +# Utility functions must exist +[ -f $MAGISKBIN/util_functions.sh ] || require_new_magisk +# Load utility fuctions +. $MAGISKBIN/util_functions.sh +get_outfd + +$BOOTMODE && ! is_mounted /magisk && abort "! Magisk is not activated!" +[ ! -f /system/build.prop ] && abort "! /system could not be mounted!" + +# 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 + +# We need busybox/binaries to be setup +$BOOTMODE && boot_actions || recovery_actions + +########################################################################################## +# Preparation +########################################################################################## + +# Extract common files +unzip -o "$ZIP" module.prop config.sh 'common/*' -d $INSTALLER 2>/dev/null + +[ ! -f $INSTALLER/config.sh ] && abort "! Unable to extract zip file!" +# Load configurations +. $INSTALLER/config.sh + +# Check the min magisk version +MIN_VER=`grep_prop template $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 + +# Print mod name +print_modname + +# Please leave this message in your flashable zip for credits :) +ui_print "******************************" +ui_print "Powered by Magisk (@topjohnwu)" +ui_print "******************************" + +########################################################################################## +# Install +########################################################################################## + +request_zip_size_check "$ZIP" + +if [ -f "$IMG" ]; then + ui_print "- Found $IMG" + image_size_check $IMG + if [ "$reqSizeM" -gt "$curFreeM" ]; then + newSizeM=$(((reqSizeM + curUsedM) / 32 * 32 + 64)) + ui_print "- Resizing $IMG to ${newSizeM}M" + $MAGISKBIN/magisk --resizeimg $IMG $newSizeM + fi +else + newSizeM=$((reqSizeM / 32 * 32 + 64)); + ui_print "- Creating $IMG with size ${newSizeM}M" + $MAGISKBIN/magisk --createimg $IMG $newSizeM +fi + +ui_print "- Mounting $IMG to $MOUNTPATH" +MAGISKLOOP=`$MAGISKBIN/magisk --mountimg $IMG $MOUNTPATH` +is_mounted $MOUNTPATH || abort "! $IMG mount failed..." + +# Create mod paths +rm -rf $MODPATH 2>/dev/null +mkdir -p $MODPATH + +ui_print "- Extracting module files" +unzip -o "$ZIP" 'system/*' -d $MODPATH 2>/dev/null + +# Handle replace folders +for TARGET in $REPLACE; do + 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 /magisk/$MODID/update + cp -af $INSTALLER/module.prop /magisk/$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 + +ui_print "- Setting permissions" +set_permissions + +########################################################################################## +# Finalizing +########################################################################################## + +$MAGISKBIN/magisk --umountimg $MOUNTPATH $MAGISKLOOP +rmdir $MOUNTPATH + +# Shrink the image if possible +image_size_check $IMG +newSizeM=$((curUsedM / 32 * 32 + 64)) +if [ $curSizeM -gt $newSizeM ]; then + ui_print "- Shrinking $IMG to ${newSizeM}M" + $MAGISKBIN/magisk --resizeimg $IMG $newSizeM +fi + +$BOOTMODE || recovery_cleanup +rm -rf $TMPDIR + +ui_print "- Done" +exit 0 diff --git a/META-INF/com/google/android/updater-script b/META-INF/com/google/android/updater-script new file mode 100644 index 0000000..11d5c96 --- /dev/null +++ b/META-INF/com/google/android/updater-script @@ -0,0 +1 @@ +#MAGISK diff --git a/README.md b/README.md index 972b473..0b34687 100644 --- a/README.md +++ b/README.md @@ -1 +1,11 @@ # Magisk Module Template + +For more information about modules and repos, please check the [official documentations](https://github.com/topjohnwu/Magisk/blob/master/docs/module_repo.md) + +### README.md + +This `README.md` can be shown in Magisk Manager. Place any information/changelog/notes you like. + +**Please update `README.md` if you want to submit your module to the online repo!** + +You can edit your `README.md` within Github's online editor, it also has an preview button! Check the [Markdown Cheat Sheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) for markdown syntaxes, it's super easy! \ No newline at end of file diff --git a/common/post-fs-data.sh b/common/post-fs-data.sh new file mode 100644 index 0000000..426ab83 --- /dev/null +++ b/common/post-fs-data.sh @@ -0,0 +1,7 @@ +#!/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%/*} + +# This script will be executed in post-fs-data mode +# More info in the main Magisk thread diff --git a/common/service.sh b/common/service.sh new file mode 100644 index 0000000..4512417 --- /dev/null +++ b/common/service.sh @@ -0,0 +1,7 @@ +#!/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%/*} + +# This script will be executed in late_start service mode +# More info in the main Magisk thread diff --git a/common/system.prop b/common/system.prop new file mode 100644 index 0000000..3d42789 --- /dev/null +++ b/common/system.prop @@ -0,0 +1,3 @@ +# This file will be read by resetprop +# Example: Change dpi +# ro.sf.lcd_density=320 diff --git a/config.sh b/config.sh new file mode 100644 index 0000000..a83a645 --- /dev/null +++ b/config.sh @@ -0,0 +1,91 @@ +########################################################################################## +# +# Magisk Module Template Config Script +# by topjohnwu +# +########################################################################################## +########################################################################################## +# +# Instructions: +# +# 1. Place your files into system folder (delete the placeholder file) +# 2. Fill in your module's info into module.prop +# 3. Configure the settings in this file (common/config.sh) +# 4. For advanced features, add shell commands into the script files under common: +# post-fs-data.sh, service.sh +# 5. For changing props, add your additional/modified props into common/system.prop +# +########################################################################################## + +########################################################################################## +# Configs +########################################################################################## + +# Set to true if you need to enable Magic Mount +# Most mods would like it to be enabled +AUTOMOUNT=true + +# Set to true if you need to load system.prop +PROPFILE=false + +# Set to true if you need post-fs-data script +POSTFSDATA=false + +# Set to true if you need late_start service script +LATESTARTSERVICE=false + +########################################################################################## +# Installation Message +########################################################################################## + +# Set what you want to show when installing your mod + +print_modname() { + ui_print "*******************************" + ui_print " Magisk Module Template " + ui_print "*******************************" +} + +########################################################################################## +# Replace list +########################################################################################## + +# List all directories you want to directly replace in the system +# By default Magisk will merge your files with the original system +# Directories listed here however, will be directly mounted to the correspond directory in the system + +# You don't need to remove the example below, these values will be overwritten by your own list +# This is an example +REPLACE=" +/system/app/Youtube +/system/priv-app/SystemUI +/system/priv-app/Settings +/system/framework +" + +# Construct your own list here, it will overwrite the example +# !DO NOT! remove this if you don't need to replace anything, leave it empty as it is now +REPLACE=" +" + +########################################################################################## +# Permissions +########################################################################################## + +set_permissions() { + # Only some special files require specific permissions + # The default permissions should be good enough for most cases + + # Here are some examples for the set_perm functions: + + # set_perm_recursive (default: u:object_r:system_file:s0) + # set_perm_recursive $MODPATH/system/lib 0 0 0755 0644 + + # set_perm (default: u:object_r:system_file:s0) + # set_perm $MODPATH/system/bin/app_process32 0 2000 0755 u:object_r:zygote_exec:s0 + # set_perm $MODPATH/system/bin/dex2oat 0 2000 0755 u:object_r:dex2oat_exec:s0 + # set_perm $MODPATH/system/lib/libart.so 0 0 0644 + + # The following is default permissions, DO NOT remove + set_perm_recursive $MODPATH 0 0 0755 0644 +} diff --git a/module.prop b/module.prop new file mode 100644 index 0000000..8fda0a1 --- /dev/null +++ b/module.prop @@ -0,0 +1,7 @@ +id=template +name=Template Module +version=v1 +versionCode=1 +author=topjohnwu +description=A short description +template=1400 diff --git a/system/placeholder b/system/placeholder new file mode 100644 index 0000000..1a69395 --- /dev/null +++ b/system/placeholder @@ -0,0 +1 @@ +This file will be deleted in Magisk Manager, it is only a placeholder for git From 0dddd403fa6c5985d045836400adfd51aae38429 Mon Sep 17 00:00:00 2001 From: PorygonZRocks Date: Sun, 29 Oct 2017 09:52:08 -0500 Subject: [PATCH 2/8] Change filea to match module, add sudo, remove placeholder --- README.md | 13 +++---------- config.sh | 2 +- module.prop | 8 ++++---- system/placeholder | 1 - 4 files changed, 8 insertions(+), 16 deletions(-) delete mode 100644 system/placeholder diff --git a/README.md b/README.md index 0b34687..5898e2b 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,4 @@ -# Magisk Module Template +# Sudo4Droid Magisk Module -For more information about modules and repos, please check the [official documentations](https://github.com/topjohnwu/Magisk/blob/master/docs/module_repo.md) - -### README.md - -This `README.md` can be shown in Magisk Manager. Place any information/changelog/notes you like. - -**Please update `README.md` if you want to submit your module to the online repo!** - -You can edit your `README.md` within Github's online editor, it also has an preview button! Check the [Markdown Cheat Sheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) for markdown syntaxes, it's super easy! \ No newline at end of file +This is a simple module. All it does is adds the file "/system/xbin/sudo", which is a script that passes all arguments to 'su -c'. Specifically, the code is 'su -c "$@"'. +The module source is on [Gitlab](https://gitlab.com/PorygonZRocks/sudo4droid-magisk.git) \ No newline at end of file diff --git a/config.sh b/config.sh index a83a645..8608987 100644 --- a/config.sh +++ b/config.sh @@ -42,7 +42,7 @@ LATESTARTSERVICE=false print_modname() { ui_print "*******************************" - ui_print " Magisk Module Template " + ui_print " Sudo4Droid Magisk Module " ui_print "*******************************" } diff --git a/module.prop b/module.prop index 8fda0a1..6065b1d 100644 --- a/module.prop +++ b/module.prop @@ -1,7 +1,7 @@ -id=template -name=Template Module +id=sudo4droid-magisk +name=Sudo4Droid version=v1 versionCode=1 -author=topjohnwu -description=A short description +author=PorygonZRocks +description=Sudo for Android (requires MagiskSU) template=1400 diff --git a/system/placeholder b/system/placeholder deleted file mode 100644 index 1a69395..0000000 --- a/system/placeholder +++ /dev/null @@ -1 +0,0 @@ -This file will be deleted in Magisk Manager, it is only a placeholder for git From d40d6d0994f7d84b969e81533f6174f06eef8efa Mon Sep 17 00:00:00 2001 From: PorygonZRocks Date: Sun, 29 Oct 2017 10:03:47 -0500 Subject: [PATCH 3/8] Add sudo (weirdly wasn't added last commit) --- system/xbin/sudo | 1 + 1 file changed, 1 insertion(+) create mode 100644 system/xbin/sudo diff --git a/system/xbin/sudo b/system/xbin/sudo new file mode 100644 index 0000000..4b070f2 --- /dev/null +++ b/system/xbin/sudo @@ -0,0 +1 @@ +su -c "$@" From 2930d7eb90c5ecda4ee6fb207b4e8dffeb45e461 Mon Sep 17 00:00:00 2001 From: PorygonZRocks Date: Sun, 29 Oct 2017 10:09:27 -0500 Subject: [PATCH 4/8] Update README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5898e2b..b288a85 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ # Sudo4Droid Magisk Module -This is a simple module. All it does is adds the file "/system/xbin/sudo", which is a script that passes all arguments to 'su -c'. Specifically, the code is 'su -c "$@"'. -The module source is on [Gitlab](https://gitlab.com/PorygonZRocks/sudo4droid-magisk.git) \ No newline at end of file +This moduke adds the sudo command to Android. It adds the file "/system/xbin/sudo", which is a script that passes all arguments to 'su -c'. Specifically, the code is 'su -c "$@"'. +The module source is on [Gitlab](https://gitlab.com/PorygonZRocks/sudo4droid-magisk.git). \ No newline at end of file From 736f9cfdf637c324a11e4ff0fda289ce4e2b4c57 Mon Sep 17 00:00:00 2001 From: PorygonZRocks Date: Sat, 30 Jun 2018 23:05:56 -0500 Subject: [PATCH 5/8] Fix typo in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b288a85..ce03798 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ # Sudo4Droid Magisk Module -This moduke adds the sudo command to Android. It adds the file "/system/xbin/sudo", which is a script that passes all arguments to 'su -c'. Specifically, the code is 'su -c "$@"'. -The module source is on [Gitlab](https://gitlab.com/PorygonZRocks/sudo4droid-magisk.git). \ No newline at end of file +This module adds the sudo command to Android. It adds the file "/system/xbin/sudo", which is a script that passes all arguments to 'su -c'. Specifically, the code is 'su -c "$@"'. +The module source is on [Gitlab](https://gitlab.com/PorygonZRocks/sudo4droid-magisk.git). From 3457e38ce907e80ed634e6a0898bc1f0f365f106 Mon Sep 17 00:00:00 2001 From: PorygonZRocks Date: Sat, 30 Jun 2018 23:09:03 -0500 Subject: [PATCH 6/8] Update README and module.prop --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index ce03798..539d1a9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ # Sudo4Droid Magisk Module +## Description This module adds the sudo command to Android. It adds the file "/system/xbin/sudo", which is a script that passes all arguments to 'su -c'. Specifically, the code is 'su -c "$@"'. The module source is on [Gitlab](https://gitlab.com/PorygonZRocks/sudo4droid-magisk.git). + +## Changelog +v1.1: Update to template 1500 \ No newline at end of file From 59d7fdda2dcae2f748fc849157fad7d5e9daa0f5 Mon Sep 17 00:00:00 2001 From: PorygonZRocks Date: Sat, 30 Jun 2018 23:10:50 -0500 Subject: [PATCH 7/8] Remove GitLab link --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 539d1a9..bfbfe9f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ ## Description This module adds the sudo command to Android. It adds the file "/system/xbin/sudo", which is a script that passes all arguments to 'su -c'. Specifically, the code is 'su -c "$@"'. -The module source is on [Gitlab](https://gitlab.com/PorygonZRocks/sudo4droid-magisk.git). ## Changelog v1.1: Update to template 1500 \ No newline at end of file From 43c0ff052a86bd5e9a0710772ed9ec484dd2dec4 Mon Sep 17 00:00:00 2001 From: PorygonZRocks Date: Sun, 8 Jul 2018 16:20:00 -0500 Subject: [PATCH 8/8] Fix permissions --- config.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.sh b/config.sh index 8608987..24a75d8 100644 --- a/config.sh +++ b/config.sh @@ -81,11 +81,11 @@ set_permissions() { # set_perm_recursive (default: u:object_r:system_file:s0) # set_perm_recursive $MODPATH/system/lib 0 0 0755 0644 - # set_perm (default: u:object_r:system_file:s0) + # set_perm permission> (default: u:object_r:system_file:s0) # set_perm $MODPATH/system/bin/app_process32 0 2000 0755 u:object_r:zygote_exec:s0 # set_perm $MODPATH/system/bin/dex2oat 0 2000 0755 u:object_r:dex2oat_exec:s0 # set_perm $MODPATH/system/lib/libart.so 0 0 0644 # The following is default permissions, DO NOT remove - set_perm_recursive $MODPATH 0 0 0755 0644 + set_perm_recursive $MODPATH/system/xbin/sudo 0 0 0755 }