Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error charch and cant run screen or tmux in Android 11 #1

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 173 additions & 0 deletions META-INF/com/google/android/update-binary
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions META-INF/com/google/android/updater-script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#MAGISK
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions customize.sh
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions module.prop
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
id=charch
name=ChArch
version=v2.0
versionCode=2
author=tytydraco
description=ChArch for Android. Modified by alanndz
27 changes: 23 additions & 4 deletions bin/charch → system/bin/charch
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions bin/cparch → system/bin/cparch
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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] <OLD NAME> <NEW NAME>
Expand Down Expand Up @@ -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"
Binary file added system/bin/fuser
Binary file not shown.
5 changes: 3 additions & 2 deletions bin/lsarch → system/bin/lsarch
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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]
Expand Down
5 changes: 3 additions & 2 deletions bin/mkarch → system/bin/mkarch
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions bin/rmarch → system/bin/rmarch
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions bin/unarch → system/bin/unarch
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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"
Expand Down