diff --git a/META-INF/com/google/android/update-binary b/META-INF/com/google/android/update-binary new file mode 100644 index 0000000..d19eeb5 --- /dev/null +++ b/META-INF/com/google/android/update-binary @@ -0,0 +1,173 @@ +#!/sbin/sh + +################# +# Initialization +################# + +umask 022 + +# Global vars +TMPDIR=/dev/tmp +PERSISTDIR=/sbin/.magisk/mirror/persist + +rm -rf $TMPDIR 2>/dev/null +mkdir -p $TMPDIR + +# echo before loading util_functions +ui_print() { echo "$1"; } + +require_new_magisk() { + ui_print "*******************************" + ui_print " Please install Magisk v19.0+! " + ui_print "*******************************" + exit 1 +} + +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 "*******************" +} + +############## +# Environment +############## + +OUTFD=$2 +ZIPFILE=$3 + +mount /data 2>/dev/null + +# Load utility functions +[ -f /data/adb/magisk/util_functions.sh ] || require_new_magisk +. /data/adb/magisk/util_functions.sh +[ $MAGISK_VER_CODE -gt 18100 ] || require_new_magisk + +# Preperation for flashable zips +setup_flashable + +# Mount partitions +mount_partitions + +# Detect version and architecture +api_level_arch_detect + +# 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 + +########## +# Install +########## + +if is_legacy_script; then + unzip -oj "$ZIPFILE" module.prop install.sh uninstall.sh 'common/*' -d $TMPDIR >&2 + + # Load install script + . $TMPDIR/install.sh + + # Callbacks + print_modname + on_install + + # Custom uninstaller + [ -f $TMPDIR/uninstall.sh ] && cp -af $TMPDIR/uninstall.sh $MODPATH/uninstall.sh + + # Skip mount + $SKIPMOUNT && touch $MODPATH/skip_mount + + # prop file + $PROPFILE && cp -af $TMPDIR/system.prop $MODPATH/system.prop + + # Module info + cp -af $TMPDIR/module.prop $MODPATH/module.prop + + # 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 + + ui_print "- Setting permissions" + set_permissions +else + print_modname + + 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 + +if $BOOTMODE; then + # Update info for Magisk Manager + mktouch $NVBASE/modules/$MODID/update + cp -af $MODPATH/module.prop $NVBASE/modules/$MODID/module.prop +fi + +# 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 + +# 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 +############## + +cd / +$BOOTMODE || recovery_cleanup +rm -rf $TMPDIR + +ui_print "- Done" +exit 0 \ No newline at end of file diff --git a/META-INF/com/google/android/updater-script b/META-INF/com/google/android/updater-script new file mode 100644 index 0000000..492be83 --- /dev/null +++ b/META-INF/com/google/android/updater-script @@ -0,0 +1 @@ +#MAGISK \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..59a744c --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +# Written by Draco (tytydraco @ GitHub) +# Modified by alanndz + +HASH := $(shell git rev-parse --short HEAD) +VERSION := $(shell cat module.prop | grep version= | sed "s/version=//") + +zip: + make clean || true + zip -x .git\* Makefile bin .gitignore *patch README* -r9 ChArch-Mod-$(VERSION)_$(HASH).zip . + +clean: + rm *.zip || true diff --git a/customize.sh b/customize.sh new file mode 100644 index 0000000..108b949 --- /dev/null +++ b/customize.sh @@ -0,0 +1,5 @@ +#!/system/bin/sh +# Written by Draco (tytydraco @ GitHub) + +ui_print "[*] Setting executable permissions..." +set_perm_recursive "$MODPATH/system/bin" root root 0777 0755 diff --git a/module.prop b/module.prop new file mode 100644 index 0000000..8a5ac94 --- /dev/null +++ b/module.prop @@ -0,0 +1,6 @@ +id=charch +name=ChArch +version=v2.0 +versionCode=2 +author=tytydraco +description=ChArch for Android. Modified by alanndz diff --git a/bin/charch b/system/bin/charch similarity index 80% rename from bin/charch rename to system/bin/charch index 9a62f5b..91b2ae7 100755 --- a/bin/charch +++ b/system/bin/charch @@ -1,5 +1,6 @@ -#!/usr/bin/env bash +#!/system/bin/sh # Written by Draco (tytydraco) @ GitHub +export PATH="/sbin/.magisk/busybox:$PATH" # Log in red and exit err() { @@ -17,7 +18,7 @@ done [[ "$(id -u)" -ne 0 ]] && err "No root permissions. Exiting." # Path containing rootfs tarball and all rootfs instances -CHROOT_DIR="$HOME/charch" +CHROOT_DIR="/data/unencrypted/charch" # The name of the current rootfs instance ROOTFS="rootfs" @@ -81,7 +82,6 @@ safe_mount_dir() { then mkdir -p "$guest_mount" mount --rbind "$1" "$guest_mount" - mount --make-rslave "$guest_mount" elif [[ -n "$2" ]] then mkdir -p "$guest_mount" @@ -102,16 +102,35 @@ safe_mount_file() { mkdir -p "${guest_mount%/*}" [[ ! -f "$guest_mount" ]] && touch "$guest_mount" mount --bind "$1" "$guest_mount" - mount --make-slave "$guest_mount" fi } +# Find the outermost mountpoint that charch is currently executing from +find_mountpoint() { + local path=`readlink -f "$1"` + until mountpoint -q "$path" &>/dev/null + do + path=${path%/*} + path=${path:-/} + + # Break if we reach the end of the filesystem + [[ "$path" == "/" ]] && ! mountpoint -q "/" &> /dev/null && break + done + echo "$path" +} + # Mount essentials and remound current mount as suid,exec setup_mounts() { safe_mount_dir /dev tmpfs + safe_mount_dir /dev/pts devpts safe_mount_dir /sys sysfs safe_mount_dir /proc proc safe_mount_file /etc/resolv.conf + + # Remount data partition with suid to allow sudo to function + local root_mount=`find_mountpoint "$CHROOT_DIR"` + mount | awk '{print $3}' | grep -q "^$root_mount\$" && + mount -o remount,suid,exec "$root_mount" &> /dev/null } # Enter the chroot with the provided command diff --git a/bin/cparch b/system/bin/cparch similarity index 89% rename from bin/cparch rename to system/bin/cparch index 6eecb8c..f318ed3 100755 --- a/bin/cparch +++ b/system/bin/cparch @@ -1,5 +1,6 @@ -#!/usr/bin/env bash +#!/system/bin/sh # Written by Draco (tytydraco) @ GitHub +export PATH="/sbin/.magisk/busybox:$PATH" # Log in red and exit err() { @@ -17,7 +18,7 @@ done [[ "$(id -u)" -ne 0 ]] && err "No root permissions. Exiting." # Path containing rootfs tarball and all rootfs instances -CHROOT_DIR="$HOME/charch" +CHROOT_DIR="/data/unencrypted/charch" usage() { echo -n "Usage: $(basename "$0") [OPTIONS] @@ -61,7 +62,7 @@ fi [[ -d "$CHROOT_DIR/$2" ]] && err "Rootfs instance with name $2 already exists. Exiting." # Unmount and exit on fail -! unarch -d "$CHROOT_DIR" "$1" && exit 1 +! unarch -d "$CHROOT_DIR" -n "$1" && exit 1 # Clone cp -Ra "$CHROOT_DIR/$1" "$CHROOT_DIR/$2" diff --git a/system/bin/fuser b/system/bin/fuser new file mode 100755 index 0000000..4a3191c Binary files /dev/null and b/system/bin/fuser differ diff --git a/bin/lsarch b/system/bin/lsarch similarity index 92% rename from bin/lsarch rename to system/bin/lsarch index 48e1626..139d27e 100755 --- a/bin/lsarch +++ b/system/bin/lsarch @@ -1,5 +1,6 @@ -#!/usr/bin/env bash +#!/system/bin/sh # Written by Draco (tytydraco) @ GitHub +export PATH="/sbin/.magisk/busybox:$PATH" # Log in red and exit err() { @@ -17,7 +18,7 @@ done [[ "$(id -u)" -ne 0 ]] && err "No root permissions. Exiting." # Path containing rootfs tarball and all rootfs instances -CHROOT_DIR="$HOME/charch" +CHROOT_DIR="/data/unencrypted/charch" usage() { echo -n "Usage: $(basename "$0") [OPTIONS] diff --git a/bin/mkarch b/system/bin/mkarch similarity index 92% rename from bin/mkarch rename to system/bin/mkarch index ad84796..1c5f458 100755 --- a/bin/mkarch +++ b/system/bin/mkarch @@ -1,5 +1,6 @@ -#!/usr/bin/env bash +#!/system/bin/sh # Written by Draco (tytydraco) @ GitHub +export PATH="/sbin/.magisk/busybox:$PATH" # Log in red and exit err() { @@ -8,7 +9,7 @@ err() { } # Check for required dependencies -for dep in find id mkdir rm sed tar wc wget +for dep in find id mkdir rm sed tar wc curl do ! command -v "$dep" &> /dev/null && err "Unable to locate dependency $dep. Exiting." done @@ -17,7 +18,7 @@ done [[ "$(id -u)" -ne 0 ]] && err "No root permissions. Exiting." # Path containing rootfs tarball and all rootfs instances -CHROOT_DIR="$HOME/charch" +CHROOT_DIR="/data/unencrypted/charch" # The name of the current rootfs instance ROOTFS="rootfs" @@ -73,7 +74,7 @@ ROOTFS_DIR="$CHROOT_DIR/$ROOTFS" fetch_rootfs() { [[ -z "$ROOTFS_URL" ]] && err "No rootfs tarball URL specified. Exiting." - ! wget -qO "$ROOTFS_TAR" "$ROOTFS_URL" && err "Failed to fetch rootfs tarball. Exiting." + ! curl -s -o "$ROOTFS_TAR" "$ROOTFS_URL" && err "Failed to fetch rootfs tarball. Exiting." } # Extract the rootfs and make it usable diff --git a/bin/rmarch b/system/bin/rmarch similarity index 95% rename from bin/rmarch rename to system/bin/rmarch index 8d110fb..25c2744 100755 --- a/bin/rmarch +++ b/system/bin/rmarch @@ -1,5 +1,6 @@ -#!/usr/bin/env bash +#!/system/bin/sh # Written by Draco (tytydraco) @ GitHub +export PATH="/sbin/.magisk/busybox:$PATH" # Log in red and exit err() { @@ -17,7 +18,7 @@ done [[ "$(id -u)" -ne 0 ]] && err "No root permissions. Exiting." # Path containing rootfs tarball and all rootfs instances -CHROOT_DIR="$HOME/charch" +CHROOT_DIR="/data/unencrypted/charch" # The name of the current rootfs instance ROOTFS="rootfs" diff --git a/bin/unarch b/system/bin/unarch similarity index 95% rename from bin/unarch rename to system/bin/unarch index 0f3eeea..0825c8a 100755 --- a/bin/unarch +++ b/system/bin/unarch @@ -1,5 +1,6 @@ -#!/usr/bin/env bash +#!/system/bin/sh # Written by Draco (tytydraco) @ GitHub +export PATH="/sbin/.magisk/busybox:$PATH" # Log in red and exit err() { @@ -17,7 +18,7 @@ done [[ "$(id -u)" -ne 0 ]] && err "No root permissions. Exiting." # Path containing rootfs tarball and rootfs instances -CHROOT_DIR="$HOME/charch" +CHROOT_DIR="/data/unencrypted/charch" # The name of the current rootfs instance ROOTFS="rootfs"