Load modules by Magisk

This commit is contained in:
Howard Wu 2024-03-03 01:40:14 +08:00
parent 44df7ca8ac
commit 502e3c7ebe
8 changed files with 74 additions and 44 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
download
output
python3-env
token

BIN
bin/arm64/lspinit Normal file

Binary file not shown.

BIN
bin/x64/lspinit Normal file

Binary file not shown.

View File

@ -67,7 +67,8 @@ clean_download() {
rm -f "${MAGISK_PATH:?}"
fi
if [ "$CLEAN_DOWNLOAD_GAPPS" ]; then
rm -f "${GAPPS_PATH:?}"
rm -f "${GAPPS_IMAGE_PATH:?}"
rm -f "${GAPPS_RC_PATH:?}"
fi
if [ "$CLEAN_DOWNLOAD_KERNELSU" ]; then
rm -f "${KERNELSU_PATH:?}"
@ -300,6 +301,7 @@ fi
}
declare -A RELEASE_NAME_MAP=(["retail"]="Retail" ["RP"]="Release Preview" ["WIS"]="Insider Slow" ["WIF"]="Insider Fast")
declare -A ANDROID_API_MAP=(["30"]="11.0" ["32"]="12.1" ["33"]="13.0")
declare -A ARCH_NAME_MAP=(["x64"]="x86_64" ["arm64"]="arm64")
RELEASE_NAME=${RELEASE_NAME_MAP[$RELEASE_TYPE]} || abort
echo -e "INFO: Release Name: $RELEASE_NAME\n"
WSA_ZIP_PATH=$DOWNLOAD_DIR/wsa-$RELEASE_TYPE.zip
@ -308,6 +310,7 @@ UWPVCLibs_PATH="$DOWNLOAD_DIR/Microsoft.VCLibs.140.00.UWPDesktop_$ARCH.appx"
xaml_PATH="$DOWNLOAD_DIR/Microsoft.UI.Xaml.2.8_$ARCH.appx"
MAGISK_ZIP=magisk-$MAGISK_VER.zip
MAGISK_PATH=$DOWNLOAD_DIR/$MAGISK_ZIP
CUST_PATH="$DOWNLOAD_DIR/cust.img"
if [ "$CUSTOM_MAGISK" ]; then
if [ ! -f "$MAGISK_PATH" ]; then
echo "Custom Magisk $MAGISK_ZIP not found"
@ -320,9 +323,11 @@ if [ "$CUSTOM_MAGISK" ]; then
fi
fi
ANDROID_API=33
update_gapps_file_name() {
GAPPS_FILE_NAME=GApps-$ARCH-${ANDROID_API_MAP[$ANDROID_API]}.img
GAPPS_PATH=$DOWNLOAD_DIR/$GAPPS_FILE_NAME
update_gapps_files_name() {
GAPPS_IMAGE_NAME=gapps-${ANDROID_API_MAP[$ANDROID_API]}-${ARCH_NAME_MAP[$ARCH]}.img
GAPPS_RC_NAME=gapps-${ANDROID_API_MAP[$ANDROID_API]}.rc
GAPPS_IMAGE_PATH=$DOWNLOAD_DIR/$GAPPS_IMAGE_NAME
GAPPS_RC_PATH=$DOWNLOAD_DIR/$GAPPS_RC_NAME
}
WSA_MAJOR_VER=0
getKernelVersion() {
@ -402,8 +407,8 @@ if [ -z ${OFFLINE+x} ]; then
echo "KERNELSU_VER=$KERNELSU_VER" >"$KERNELSU_INFO"
fi
if [ "$HAS_GAPPS" ]; then
update_gapps_file_name
python3 generateGappsLink.py "$ARCH" "$DOWNLOAD_DIR" "$DOWNLOAD_CONF_NAME" "$ANDROID_API" "$GAPPS_FILE_NAME" || abort
update_gapps_files_name
python3 generateGappsLink.py "$ARCH" "$DOWNLOAD_DIR" "$DOWNLOAD_CONF_NAME" "$ANDROID_API" "$GAPPS_IMAGE_NAME" || abort
fi
if [ -f "$DOWNLOAD_DIR/$DOWNLOAD_CONF_NAME" ]; then
echo "Downloading Artifacts"
@ -416,15 +421,15 @@ if [ -z ${OFFLINE+x} ]; then
fi
declare -A FILES_CHECK_LIST=([xaml_PATH]="$xaml_PATH" [vclibs_PATH]="$vclibs_PATH" [UWPVCLibs_PATH]="$UWPVCLibs_PATH")
if [ "$HAS_GAPPS" ] || [ "$ROOT_SOL" = "magisk" ]; then
FILES_CHECK_LIST+=(["MAGISK_PATH"]="$MAGISK_PATH")
FILES_CHECK_LIST+=(["MAGISK_PATH"]="$MAGISK_PATH" ["CUST_PATH"]="$CUST_PATH")
fi
if [ "$ROOT_SOL" = "kernelsu" ]; then
update_ksu_zip_name
FILES_CHECK_LIST+=(["KERNELSU_PATH"]="$KERNELSU_PATH")
fi
if [ "$HAS_GAPPS" ]; then
update_gapps_file_name
FILES_CHECK_LIST+=(["GAPPS_PATH"]="$GAPPS_PATH")
update_gapps_files_name
FILES_CHECK_LIST+=(["GAPPS_IMAGE_PATH"]="$GAPPS_IMAGE_PATH" ["GAPPS_RC_PATH"]="$GAPPS_RC_PATH")
fi
for i in "${FILES_CHECK_LIST[@]}"; do
if [ ! -f "$i" ]; then
@ -476,6 +481,7 @@ if [ "$HAS_GAPPS" ] || [ "$ROOT_SOL" = "magisk" ]; then
"mkdir 000 .backup" \
"add 000 overlay.d/init.lsp.magisk.rc init.lsp.magisk.rc" \
"add 000 overlay.d/sbin/post-fs-data.sh post-fs-data.sh" \
"add 000 overlay.d/sbin/lsp_cust.img $CUST_PATH" \
|| abort "Unable to patch initrd"
elif [ "$ROOT_SOL" = "kernelsu" ]; then
echo "Extracting KernelSU"
@ -498,13 +504,13 @@ elif [ "$ROOT_SOL" = "kernelsu" ]; then
fi
echo -e "done\n"
if [ "$HAS_GAPPS" ]; then
update_gapps_file_name
if [ -f "$GAPPS_PATH" ]; then
update_gapps_files_name
if [ -f "$GAPPS_IMAGE_PATH" ] && [ -f "$GAPPS_RC_PATH" ]; then
echo "Integrating GApps"
"$WORK_DIR/magisk/magiskboot" cpio "$WORK_DIR/wsa/$ARCH/Tools/initrd.img" \
"add 000 overlay.d/init.lsp.cust.rc init.lsp.cust.rc" \
"add 000 /lspolicy.rule sepolicy.rule" \
"add 000 overlay.d/sbin/cust.img $GAPPS_PATH" \
"add 000 overlay.d/gapps.rc $GAPPS_RC_PATH" \
"add 000 overlay.d/sbin/lsp_gapps.img $GAPPS_IMAGE_PATH" \
|| abort "Unable to patch initrd"
echo -e "done\n"
else

View File

@ -79,6 +79,10 @@ with zipfile.ZipFile(wsa_zip_path) as zip:
if not Path(workdir / zip_name).is_file():
print(f"unzipping {zip_name} to {workdir}", flush=True)
zip_path = zip.extract(f, workdir)
with zipfile.ZipFile(zip_path) as zip:
stat = Path(zip_path).stat()
print(f"unzipping from {zip_path}", flush=True)
zip.extractall(archdir)
ver_no = zip_name.split("_")
long_ver = ver_no[1]
ver = long_ver.split(".")
@ -106,7 +110,3 @@ with zipfile.ZipFile(wsa_zip_path) as zip:
l.extract(g, xmldir)
elif re.search(u'Images/.+\.png', g.filename):
l.extract(g, archdir)
with zipfile.ZipFile(zip_path) as zip:
stat = Path(zip_path).stat()
print(f"unzipping from {zip_path}", flush=True)
zip.extractall(archdir)

View File

@ -19,6 +19,7 @@
#
from datetime import datetime
import os
import sys
import requests
@ -26,6 +27,21 @@ import json
import re
from pathlib import Path
class BearerAuth(requests.auth.AuthBase):
def __init__(self, token):
self.token = token
def __call__(self, r):
r.headers["authorization"] = "Bearer " + self.token
return r
github_auth = None
if Path.cwd().joinpath('token').exists():
with open(Path.cwd().joinpath('token'), 'r') as token_file:
github_auth = BearerAuth(token_file.read())
print("Using token file for authentication", flush=True)
arch = sys.argv[1]
arg2 = sys.argv[2]
download_dir = Path.cwd().parent / "download" if arg2 == "" else Path(arg2)
@ -36,27 +52,31 @@ print(f"Generating GApps download link: arch={arch}", flush=True)
abi_map = {"x64": "x86_64", "arm64": "arm64"}
android_api_map = {"30": "11.0", "32": "12.1", "33": "13.0"}
release = android_api_map[android_api]
res = requests.get(f"https://api.github.com/repos/LSPosed/WSA-Addon/releases/latest")
res = requests.get(f"https://api.github.com/repos/LSPosed/WSA-Addon/releases/latest", auth=github_auth)
json_data = json.loads(res.content)
headers = res.headers
x_ratelimit_remaining = headers["x-ratelimit-remaining"]
if res.status_code == 200:
download_files = {}
assets = json_data["assets"]
for asset in assets:
if re.match(f'gapps.*{release}.*{abi_map[arch]}.*\.apex$', asset["name"]):
link = asset["browser_download_url"]
if re.match(f'GApps.*{release}.*\.rc$', asset["name"]):
download_files[asset["name"]] = asset["browser_download_url"]
continue
elif re.match(f'GApps.*{release}.*{abi_map[arch]}.*\.img$', asset["name"]):
download_files[asset["name"]] = asset["browser_download_url"]
break
with open(download_dir/tempScript, 'a') as f:
for key, value in download_files.items():
print(f"download link: {value}\npath: {download_dir / key}\n", flush=True)
f.writelines(value + '\n')
f.writelines(f' dir={download_dir}\n')
f.writelines(f' out={key}\n')
elif res.status_code == 403 and x_ratelimit_remaining == '0':
message = json_data["message"]
print(f"Github API Error: {message}", flush=True)
ratelimit_reset = headers["x-ratelimit-reset"]
ratelimit_reset = datetime.fromtimestamp(int(ratelimit_reset))
print(f"The current rate limit window resets in {ratelimit_reset}", flush=True)
print(
f"The current rate limit window resets in {ratelimit_reset}", flush=True)
exit(1)
print(f"download link: {link}", flush=True)
with open(download_dir/tempScript, 'a') as f:
f.writelines(f'{link}\n')
f.writelines(f' dir={download_dir}\n')
f.writelines(f' out={file_name}\n')

View File

@ -1,12 +0,0 @@
on post-fs
mkdir /mnt/cust 0775 system system
mount erofs loop@${MAGISKTMP}/cust.img /mnt/cust noatime,ro cache_strategy=readaround
wait /system_ext
mount overlay system_ext_etc_permissions_overlay /system_ext/etc/permissions noatime lowerdir=/system_ext/etc/permissions:/mnt/cust/system_ext/etc/permissions,redirect_dir=on,xino=on
mount overlay system_ext_priv-app_overlay /system_ext/priv-app noatime lowerdir=/system_ext/priv-app:/mnt/cust/system_ext/priv-app,redirect_dir=on,xino=on
wait /product
mount overlay product_overlay /product noatime lowerdir=/product:/mnt/cust/product,redirect_dir=on,xino=on
wait /vendor
mount overlay vendor_overlay /vendor noatime lowerdir=/vendor:/mnt/cust/vendor,redirect_dir=on,xino=on
wait /system
mount overlay system_priv-app_overlay /system/priv-app noatime lowerdir=/mnt/cust/system/priv-app:/system/priv-app,redirect_dir=on,xino=on

View File

@ -1,4 +1,4 @@
#!/system/bin/sh
#!/bin/sh
MAGISKTMP=/sbin
[ -d /sbin ] || MAGISKTMP=/debug_ramdisk
MAGISKBIN=/data/adb/magisk
@ -11,17 +11,32 @@ if [ ! -d $MAGISKBIN ]; then
mkdir -p -m 755 $MAGISKBIN
chcon u:object_r:system_file:s0 $MAGISKBIN
fi
ABI=$(/system/bin/getprop ro.product.cpu.abi)
ABI=$(getprop ro.product.cpu.abi)
for file in busybox magiskpolicy magiskboot magiskinit; do
[ -x "$MAGISKBIN/$file" ] || {
/system/bin/unzip -d $MAGISKBIN -oj $MAGISKTMP/stub.apk "lib/$ABI/lib$file.so"
unzip -d $MAGISKBIN -oj $MAGISKTMP/stub.apk "lib/$ABI/lib$file.so"
mv $MAGISKBIN/lib$file.so $MAGISKBIN/$file
chmod 755 "$MAGISKBIN/$file"
}
done
for file in util_functions.sh boot_patch.sh; do
[ -x "$MAGISKBIN/$file" ] || {
/system/bin/unzip -d $MAGISKBIN -oj $MAGISKTMP/stub.apk "assets/$file"
unzip -d $MAGISKBIN -oj $MAGISKTMP/stub.apk "assets/$file"
chmod 755 "$MAGISKBIN/$file"
}
done
for file in "$MAGISKTMP"/*; do
if echo "$file" | grep -Eq "lsp_.+\.img"; then
foldername=$(basename "$file" .img)
mkdir -p "$MAGISKTMP/$foldername"
mount -t auto -o ro,loop "$file" "$MAGISKTMP/$foldername"
"$MAGISKTMP/$foldername/post-fs-data.sh" &
fi
done
wait
for file in "$MAGISKTMP"/*; do
if echo "$file" | grep -Eq "lsp_.+\.img"; then
foldername=$(basename "$file" .img)
umount "$MAGISKTMP/$foldername"
fi
done