Skip to content

Commit

Permalink
Merge github.com:topjohnwu/magisk-module-template
Browse files Browse the repository at this point in the history
  • Loading branch information
simonsmh committed Dec 26, 2017
2 parents 109f43b + 827be27 commit aaa24af
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 82 deletions.
6 changes: 3 additions & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,8 +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
*.prop text eol=lf
*.sh text eol=lf
*.md text eol=lf

# Denote all files that are truly binary and should not be modified.
system/** binary
105 changes: 37 additions & 68 deletions META-INF/com/google/android/update-binary
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,9 @@
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
MAGISKBIN=/data/adb/magisk

# Default permissions
umask 022
Expand All @@ -28,67 +21,63 @@ umask 022
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 "*******************************"
exit 1
}

##########################################################################################
# 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

# 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

# Preperation for flashable zips
get_outfd

$BOOTMODE && ! is_mounted /magisk && abort "! Magisk is not activated!"
[ ! -f /system/build.prop ] && abort "! /system could not be mounted!"
# 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

# We need busybox/binaries to be setup
# Setup busybox and binaries
$BOOTMODE && boot_actions || recovery_actions

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

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

[ ! -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`
# 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
Expand All @@ -105,32 +94,22 @@ ui_print "******************************"
# Install
##########################################################################################

# Get the variable reqSizeM. Use your own method to determine reqSizeM if needed
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..."
# This function will mount $IMG to $MOUNTPATH, and resize the image based on $reqSizeM
mount_magisk_img

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

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

# Remove placeholder
rm -f $MODPATH/system/placeholder 2>/dev/null

# Handle replace folders
for TARGET in $REPLACE; do
Expand All @@ -147,8 +126,8 @@ $PROPFILE && cp -af $INSTALLER/common/system.prop $MODPATH/system.prop
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
mktouch /sbin/.core/img/$MODID/update
cp -af $INSTALLER/module.prop /sbin/.core/img/$MODID/module.prop
fi

# post-fs-data mode scripts
Expand All @@ -161,8 +140,6 @@ Cfg_Migration(){
mkdir -p $MODPATH$CFGPATH
if [ -f /sbin/.core/magisk/mirror$CFGPATH$CFG ]; then
cp -af /sbin/.core/mirror$CFGPATH$CFG $MODPATH$CFGPATH$CFG
elif [ -f /dev/magisk/mirror$CFGPATH$CFG ]; then
cp -af /dev/magisk/mirror$CFGPATH$CFG $MODPATH$CFGPATH$CFG
else
cp -af $CFGPATH$CFG $MODPATH$CFGPATH$CFG
fi
Expand Down Expand Up @@ -195,19 +172,11 @@ 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
# Unmount magisk image and shrink if possible
unmount_magisk_img

$BOOTMODE || recovery_cleanup
rm -rf $TMPDIR

ui_print "- Done"
exit 0
exit 0
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Make 40Mhz runing at 2.4Ghz/5Ghz on your Qualcomm devices!

* You should use latest Magisk Manager to install this module. If you meet any problem under installation from Magisk Manager, please try to install it from recovery.
* Recent fixes:
Fix devices with vendor separated.
Magisk v15 Template 1500 compatabilities

#### Credit & Support

Expand Down
26 changes: 17 additions & 9 deletions config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
#
# 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
# 3. Configure the settings in this file (config.sh)
# 4. If you need boot scripts, add them into common/post-fs-data.sh or common/service.sh
# 5. Add your additional or modified system properties into common/system.prop
#
##########################################################################################

Expand Down Expand Up @@ -51,10 +50,8 @@ print_modname() {
##########################################################################################

# 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
# Check the documentations for more info about how Magic Mount works, and why you need this

# 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
Expand All @@ -63,7 +60,7 @@ REPLACE="
/system/framework
"

# Construct your own list here, it will overwrite the example
# Construct your own list here, it will override the example above
# !DO NOT! remove this if you don't need to replace anything, leave it empty as it is now
REPLACE="
"
Expand All @@ -88,4 +85,15 @@ set_permissions() {

# The following is default permissions, DO NOT remove
set_perm_recursive $MODPATH 0 0 0755 0644
}
}

##########################################################################################
# Custom Functions
##########################################################################################

# This file (config.sh) will be sourced by the main flash script after util_functions.sh
# If you need custom logic, please add them here as functions, and call these functions in
# update-binary. Refrain from adding code directly into update-binary, as it will make it
# difficult for you to migrate your modules to newer template versions.
# Make update-binary as clean as possible, try to only do function calls in it.

2 changes: 1 addition & 1 deletion module.prop
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version=1.3
versionCode=4
author=simonsmh
description=Make 2.4Ghz/5Ghz WiFi runing on 40Mhz on your Qualcomm devices.
template=1400
minMagisk=1500
1 change: 1 addition & 0 deletions system/placeholder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file will be deleted in Magisk Manager, it is only a placeholder for git

0 comments on commit aaa24af

Please sign in to comment.