|
| 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 | +mkdir -p $MODPATH/system/vendor/etc |
| 112 | +cp -f /system/vendor/etc/mixer_paths_tavil.xml $MODPATH/system/vendor/etc/mixer_paths_tavil.xml |
| 113 | +cp -f $INSTALLER/common/.aml.sh $MODPATH/.aml.sh |
| 114 | +. $INSTALLER/common/.aml.sh |
| 115 | + |
| 116 | +# Remove placeholder |
| 117 | +rm -f $MODPATH/system/placeholder 2>/dev/null |
| 118 | + |
| 119 | +# Handle replace folders |
| 120 | +for TARGET in $REPLACE; do |
| 121 | + mktouch $MODPATH$TARGET/.replace |
| 122 | +done |
| 123 | + |
| 124 | +# Auto Mount |
| 125 | +$AUTOMOUNT && touch $MODPATH/auto_mount |
| 126 | + |
| 127 | +# prop files |
| 128 | +$PROPFILE && cp -af $INSTALLER/common/system.prop $MODPATH/system.prop |
| 129 | + |
| 130 | +# Module info |
| 131 | +cp -af $INSTALLER/module.prop $MODPATH/module.prop |
| 132 | +if $BOOTMODE; then |
| 133 | + # Update info for Magisk Manager |
| 134 | + mktouch /sbin/.core/img/$MODID/update |
| 135 | + cp -af $INSTALLER/module.prop /sbin/.core/img/$MODID/module.prop |
| 136 | +fi |
| 137 | + |
| 138 | +# post-fs-data mode scripts |
| 139 | +$POSTFSDATA && cp -af $INSTALLER/common/post-fs-data.sh $MODPATH/post-fs-data.sh |
| 140 | + |
| 141 | +# service mode scripts |
| 142 | +$LATESTARTSERVICE && cp -af $INSTALLER/common/service.sh $MODPATH/service.sh |
| 143 | + |
| 144 | +ui_print "- Setting permissions" |
| 145 | +set_permissions |
| 146 | + |
| 147 | +########################################################################################## |
| 148 | +# Finalizing |
| 149 | +########################################################################################## |
| 150 | + |
| 151 | +# Unmount magisk image and shrink if possible |
| 152 | +unmount_magisk_img |
| 153 | + |
| 154 | +$BOOTMODE || recovery_cleanup |
| 155 | +rm -rf $TMPDIR |
| 156 | + |
| 157 | +ui_print "- Done" |
| 158 | +exit 0 |
0 commit comments