Skip to content

Commit 50249f6

Browse files
committed
Magisk Module Template 1500
1 parent f8c14b4 commit 50249f6

File tree

10 files changed

+294
-0
lines changed

10 files changed

+294
-0
lines changed

.gitattributes

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Declare files that will always have LF line endings on checkout.
2+
META-INF/** text eol=lf
3+
*.prop text eol=lf
4+
*.sh text eol=lf
5+
*.md text eol=lf
6+
7+
# Denote all files that are truly binary and should not be modified.
8+
system/** binary
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#!/sbin/sh
2+
##########################################################################################
3+
#
4+
# Magisk Module Template Install Script
5+
# by topjohnwu
6+
#
7+
##########################################################################################
8+
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
12+
13+
TMPDIR=/dev/tmp
14+
INSTALLER=$TMPDIR/install
15+
MAGISKBIN=/data/adb/magisk
16+
17+
# Default permissions
18+
umask 022
19+
20+
# Initial cleanup
21+
rm -rf $TMPDIR 2>/dev/null
22+
mkdir -p $INSTALLER
23+
24+
# echo before loading util_functions
25+
ui_print() { echo "$1"; }
26+
27+
require_new_magisk() {
28+
ui_print "*******************************"
29+
ui_print " Please install Magisk v15.0+! "
30+
ui_print "*******************************"
31+
exit 1
32+
}
33+
34+
##########################################################################################
35+
# Environment
36+
##########################################################################################
37+
38+
OUTFD=$2
39+
ZIP=$3
40+
41+
mount /data 2>/dev/null
42+
43+
# Utility functions must exist
44+
[ -f $MAGISKBIN/util_functions.sh ] || require_new_magisk
45+
# Load utility fuctions
46+
. $MAGISKBIN/util_functions.sh
47+
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
52+
53+
# Preperation for flashable zips
54+
get_outfd
55+
56+
# Mount partitions
57+
mount_partitions
58+
59+
# Detect version and architecture
60+
api_level_arch_detect
61+
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+
65+
# Setup busybox and binaries
66+
$BOOTMODE && boot_actions || recovery_actions
67+
68+
##########################################################################################
69+
# Preparation
70+
##########################################################################################
71+
72+
# Extract common files
73+
unzip -o "$ZIP" module.prop config.sh 'common/*' -d $INSTALLER >&2
74+
75+
[ ! -f $INSTALLER/config.sh ] && abort "! Unable to extract zip file!"
76+
# Load configurations
77+
. $INSTALLER/config.sh
78+
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
84+
85+
# Print mod name
86+
print_modname
87+
88+
# Please leave this message in your flashable zip for credits :)
89+
ui_print "******************************"
90+
ui_print "Powered by Magisk (@topjohnwu)"
91+
ui_print "******************************"
92+
93+
##########################################################################################
94+
# Install
95+
##########################################################################################
96+
97+
# Get the variable reqSizeM. Use your own method to determine reqSizeM if needed
98+
request_zip_size_check "$ZIP"
99+
100+
# This function will mount $IMG to $MOUNTPATH, and resize the image based on $reqSizeM
101+
mount_magisk_img
102+
103+
# Create mod paths
104+
rm -rf $MODPATH 2>/dev/null
105+
mkdir -p $MODPATH
106+
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
110+
111+
# Remove placeholder
112+
rm -f $MODPATH/system/placeholder 2>/dev/null
113+
114+
# Handle replace folders
115+
for TARGET in $REPLACE; do
116+
mktouch $MODPATH$TARGET/.replace
117+
done
118+
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
127+
if $BOOTMODE; then
128+
# Update info for Magisk Manager
129+
mktouch /sbin/.core/img/$MODID/update
130+
cp -af $INSTALLER/module.prop /sbin/.core/img/$MODID/module.prop
131+
fi
132+
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
138+
139+
ui_print "- Setting permissions"
140+
set_permissions
141+
142+
##########################################################################################
143+
# Finalizing
144+
##########################################################################################
145+
146+
# Unmount magisk image and shrink if possible
147+
unmount_magisk_img
148+
149+
$BOOTMODE || recovery_cleanup
150+
rm -rf $TMPDIR
151+
152+
ui_print "- Done"
153+
exit 0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#MAGISK

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
# Magisk Module Template
2+
3+
This `README.md` will be shown in Magisk Manager. Place any information / changelog / notes you like.
4+
5+
**Please update `README.md` if you want to submit your module to the online repo!**
6+
7+
Github has its own online markdown editor with a preview feature, you can use it to update your `README.md`! If you need more advanced syntax, check the [Markdown Cheat Sheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet).
8+
9+
For more information about modules and repos, please check the [official documentations](https://github.com/topjohnwu/Magisk/blob/master/docs/modules.md)

common/post-fs-data.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/system/bin/sh
2+
# Please don't hardcode /magisk/modname/... ; instead, please use $MODDIR/...
3+
# This will make your scripts compatible even if Magisk change its mount point in the future
4+
MODDIR=${0%/*}
5+
6+
# This script will be executed in post-fs-data mode
7+
# More info in the main Magisk thread

common/service.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/system/bin/sh
2+
# Please don't hardcode /magisk/modname/... ; instead, please use $MODDIR/...
3+
# This will make your scripts compatible even if Magisk change its mount point in the future
4+
MODDIR=${0%/*}
5+
6+
# This script will be executed in late_start service mode
7+
# More info in the main Magisk thread

common/system.prop

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This file will be read by resetprop
2+
# Example: Change dpi
3+
# ro.sf.lcd_density=320

config.sh

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
##########################################################################################
2+
#
3+
# Magisk Module Template Config Script
4+
# by topjohnwu
5+
#
6+
##########################################################################################
7+
##########################################################################################
8+
#
9+
# Instructions:
10+
#
11+
# 1. Place your files into system folder (delete the placeholder file)
12+
# 2. Fill in your module's info into module.prop
13+
# 3. Configure the settings in this file (config.sh)
14+
# 4. If you need boot scripts, add them into common/post-fs-data.sh or common/service.sh
15+
# 5. Add your additional or modified system properties into common/system.prop
16+
#
17+
##########################################################################################
18+
19+
##########################################################################################
20+
# Configs
21+
##########################################################################################
22+
23+
# Set to true if you need to enable Magic Mount
24+
# Most mods would like it to be enabled
25+
AUTOMOUNT=true
26+
27+
# Set to true if you need to load system.prop
28+
PROPFILE=false
29+
30+
# Set to true if you need post-fs-data script
31+
POSTFSDATA=false
32+
33+
# Set to true if you need late_start service script
34+
LATESTARTSERVICE=false
35+
36+
##########################################################################################
37+
# Installation Message
38+
##########################################################################################
39+
40+
# Set what you want to show when installing your mod
41+
42+
print_modname() {
43+
ui_print "*******************************"
44+
ui_print " Magisk Module Template "
45+
ui_print "*******************************"
46+
}
47+
48+
##########################################################################################
49+
# Replace list
50+
##########################################################################################
51+
52+
# List all directories you want to directly replace in the system
53+
# Check the documentations for more info about how Magic Mount works, and why you need this
54+
55+
# This is an example
56+
REPLACE="
57+
/system/app/Youtube
58+
/system/priv-app/SystemUI
59+
/system/priv-app/Settings
60+
/system/framework
61+
"
62+
63+
# Construct your own list here, it will override the example above
64+
# !DO NOT! remove this if you don't need to replace anything, leave it empty as it is now
65+
REPLACE="
66+
"
67+
68+
##########################################################################################
69+
# Permissions
70+
##########################################################################################
71+
72+
set_permissions() {
73+
# Only some special files require specific permissions
74+
# The default permissions should be good enough for most cases
75+
76+
# Here are some examples for the set_perm functions:
77+
78+
# set_perm_recursive <dirname> <owner> <group> <dirpermission> <filepermission> <contexts> (default: u:object_r:system_file:s0)
79+
# set_perm_recursive $MODPATH/system/lib 0 0 0755 0644
80+
81+
# set_perm <filename> <owner> <group> <permission> <contexts> (default: u:object_r:system_file:s0)
82+
# set_perm $MODPATH/system/bin/app_process32 0 2000 0755 u:object_r:zygote_exec:s0
83+
# set_perm $MODPATH/system/bin/dex2oat 0 2000 0755 u:object_r:dex2oat_exec:s0
84+
# set_perm $MODPATH/system/lib/libart.so 0 0 0644
85+
86+
# The following is default permissions, DO NOT remove
87+
set_perm_recursive $MODPATH 0 0 0755 0644
88+
}
89+
90+
##########################################################################################
91+
# Custom Functions
92+
##########################################################################################
93+
94+
# This file (config.sh) will be sourced by the main flash script after util_functions.sh
95+
# If you need custom logic, please add them here as functions, and call these functions in
96+
# update-binary. Refrain from adding code directly into update-binary, as it will make it
97+
# difficult for you to migrate your modules to newer template versions.
98+
# Make update-binary as clean as possible, try to only do function calls in it.
99+

module.prop

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
id=template
2+
name=Template Module
3+
version=v1
4+
versionCode=1
5+
author=topjohnwu
6+
description=A short description
7+
minMagisk=1500

system/placeholder

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This file will be deleted in Magisk Manager, it is only a placeholder for git

0 commit comments

Comments
 (0)