#!/bin/bash # # This file is part of MagiskOnWSALocal. # # MagiskOnWSALocal is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # MagiskOnWSALocal is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with MagiskOnWSALocal. If not, see . # # Copyright (C) 2022 LSPosed Contributors # if [ ! "$BASH_VERSION" ] ; then echo "Please do not use sh to run this script, just execute it directly" 1>&2 exit 1 fi HOST_ARCH=$(uname -m) if [ "$HOST_ARCH" != "x86_64" ] && [ "$HOST_ARCH" != "aarch64" ]; then echo "Unsupported architectures: $HOST_ARCH" exit 1 fi cd "$(dirname "$0")" || exit 1 trap umount_clean EXIT WORK_DIR=$(mktemp -d -t wsa-build-XXXXXXXXXX_) || exit 1 DOWNLOAD_DIR=../download DOWNLOAD_CONF_NAME=download.list OUTPUT_DIR=../output MOUNT_DIR="$WORK_DIR"/system CLEAN_DOWNLOAD=1 umount_clean(){ echo "Cleanup Work Directory" if [ -d "$MOUNT_DIR" ]; then if [ -d "$MOUNT_DIR/vendor" ]; then sudo umount "$MOUNT_DIR"/vendor fi if [ -d "$MOUNT_DIR/product" ]; then sudo umount "$MOUNT_DIR"/product fi if [ -d "$MOUNT_DIR/system_ext" ]; then sudo umount "$MOUNT_DIR"/system_ext fi sudo umount "$MOUNT_DIR" fi sudo rm -rf "${WORK_DIR:?}" } abort() { echo "An error has occurred, exit" if [ -d "$WORK_DIR" ]; then umount_clean fi if [ -d "$DOWNLOAD_DIR" ] && [ $CLEAN_DOWNLOAD = "1" ]; then echo "Cleanup Download Directory" sudo rm -rf "${DOWNLOAD_DIR:?}" fi if [ -d "$OUTPUT_DIR" ]; then echo "Cleanup Output Directory" sudo rm -rf "${OUTPUT_DIR:?}" fi exit 1 } trap abort INT TERM function Radiolist { declare -A o="$1" shift if ! whiptail --nocancel --radiolist "${o[title]}" 0 0 0 "$@" 3>&1 1>&2 2>&3; then echo "${o[default]}" fi } function YesNoBox { declare -A o="$1" shift whiptail --title "${o[title]}" --yesno "${o[text]}" 0 0 } function Gen_Rand_Str { tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w "$1" | head -n 1 } echo "Dependencies" sudo apt update && sudo apt -y install setools lzip wine winetricks patchelf whiptail e2fsprogs python3-pip aria2 python3 -m pip install requests cp -r ../wine/.cache/* ~/.cache winetricks msxml6 || abort ARCH=$( Radiolist '([title]="Build arch" [default]="x64")' \ \ 'x64' "X86_64" 'on' \ 'arm64' "AArch64" 'off' ) RELEASE_TYPE=$( Radiolist '([title]="WSA release type" [default]="retail")' \ \ 'retail' "Stable Channel" 'on' \ 'release preview' "Release Preview Channel" 'off' \ 'insider slow' "Beta Channel" 'off' \ 'insider fast' "Dev Channel" 'off' ) MAGISK_VER=$( Radiolist '([title]="Magisk version" [default]="stable")' \ \ 'stable' "Stable Channel" 'on' \ 'beta' "Beta Channel" 'off' \ 'canary' "Canary Channel" 'off' \ 'debug' "Canary Channel Debug Build" 'off' ) if (YesNoBox '([title]="Install GApps" [text]="Do you want to install GApps?")'); then if [ -f "$DOWNLOAD_DIR"/MindTheGapps/MindTheGapps_"$ARCH".zip ]; then GAPPS_BRAND=$( Radiolist '([title]="Which GApps do you want to install?" [default]="OpenGApps")' \ \ 'OpenGApps' "" 'on' \ 'MindTheGapps' "" 'off' ) else GAPPS_BRAND="OpenGApps" fi else GAPPS_VARIANT="none" fi if [ $GAPPS_BRAND = "OpenGApps" ]; then GAPPS_VARIANT=$( Radiolist '([title]="Variants of GApps" [default]="pico")' \ \ 'super' "" 'off' \ 'stock' "" 'off' \ 'full' "" 'off' \ 'mini' "" 'off' \ 'micro' "" 'off' \ 'nano' "" 'off' \ 'pico' "" 'on' \ 'tvstock' "" 'off' \ 'tvmini' "" 'off' ) else GAPPS_VARIANT=$GAPPS_BRAND fi if (YesNoBox '([title]="Remove Amazon AppStore" [text]="Do you want to keep Amazon AppStore?")'); then REMOVE_AMAZON="keep" else REMOVE_AMAZON="remove" fi ROOT_SOL=$( Radiolist '([title]="Root solution" [default]="magisk")' \ \ 'magisk' "" 'on' \ 'none' "" 'off' ) if (YesNoBox '([title]="Compress output" [text]="Do you want to compress the output?")'); then COMPRESS_OUTPUT="yes" else COMPRESS_OUTPUT="no" fi clear echo -e "ARCH=$ARCH\nRELEASE_TYPE=$RELEASE_TYPE\nMAGISK_VER=$MAGISK_VER\nGAPPS_VARIANT=$GAPPS_VARIANT\nREMOVE_AMAZON=$REMOVE_AMAZON\nROOT_SOL=$ROOT_SOL\nCOMPRESS_OUTPUT=$COMPRESS_OUTPUT" echo "Generate Download Links" python3 generateWSALinks.py "$ARCH" "$RELEASE_TYPE" "$DOWNLOAD_DIR" "$DOWNLOAD_CONF_NAME" || abort python3 generateMagiskLink.py "$MAGISK_VER" "$DOWNLOAD_DIR" "$DOWNLOAD_CONF_NAME" || abort if [ $GAPPS_VARIANT != 'none' ] && [ $GAPPS_VARIANT != '' ]; then if [ $GAPPS_BRAND = "OpenGApps" ]; then # TODO: Keep it pico since other variants of opengapps are unable to boot successfully python3 generateGappsLink.py "$ARCH" "pico" "$DOWNLOAD_DIR" "$DOWNLOAD_CONF_NAME" || abort # python3 generateGappsLink.py "$ARCH" "$GAPPS_VARIANT" "$DOWNLOAD_DIR" "$DOWNLOAD_CONF_NAME" || abort fi fi trap 'rm -f -- "${DOWNLOAD_DIR:?}/${DOWNLOAD_CONF_NAME}"' EXIT echo "Download Artifacts" if ! aria2c --no-conf --log-level=info --log="$DOWNLOAD_DIR/aria2_download.log" -x16 -s16 -j5 -c -R -m0 -d"$DOWNLOAD_DIR" -i"$DOWNLOAD_DIR"/"$DOWNLOAD_CONF_NAME"; then echo "We have encountered an error while downloading files." exit 1 else CLEAN_DOWNLOAD=0 fi echo "Extract WSA" WSA_WORK_ENV="${WORK_DIR:?}"/ENV if [ -f "$WSA_WORK_ENV" ]; then rm -f "${WSA_WORK_ENV:?}"; fi export WSA_WORK_ENV python3 extractWSA.py "$ARCH" "$WORK_DIR" || abort echo -e "Extract done\n" source "${WORK_DIR:?}/ENV" || abort echo "Extract Magisk" python3 extractMagisk.py "$ARCH" "$DOWNLOAD_DIR/magisk.zip" "$WORK_DIR" || abort echo -e "done\n" if [ $GAPPS_VARIANT != 'none' ] && [ $GAPPS_VARIANT != '' ]; then echo "Extract GApps" mkdir -p "$WORK_DIR"/gapps || abort if [ $GAPPS_BRAND = "OpenGApps" ]; then unzip -p "$DOWNLOAD_DIR"/gapps.zip {Core,GApps}/'*.lz' | tar --lzip -C "$WORK_DIR"/gapps -xf - -i --strip-components=2 --exclude='setupwizardtablet-x86_64' --exclude='packageinstallergoogle-all' --exclude='speech-common' --exclude='markup-lib-arm' --exclude='markup-lib-arm64' --exclude='markup-all' --exclude='setupwizarddefault-x86_64' --exclude='pixellauncher-all' --exclude='pixellauncher-common' || abort else unzip "$DOWNLOAD_DIR"/MindTheGapps/MindTheGapps_"$ARCH".zip "system/*" -x "system/addon.d/*" "system/system_ext/priv-app/SetupWizard/*" -d "$WORK_DIR"/gapps || abort mv "$WORK_DIR"/gapps/system/* "$WORK_DIR"/gapps || abort rm -rf "${WORK_DIR:?}"/gapps/system || abort fi cp -r ../"$ARCH"/gapps/* "$WORK_DIR"/gapps || abort if [ $GAPPS_BRAND = "MindTheGapps" ]; then mv "$WORK_DIR"/gapps/priv-app/* "$WORK_DIR"/gapps/system_ext/priv-app || abort rm -rf "${WORK_DIR:?}"/gapps/priv-app || abort fi echo -e "Extract done\n" fi echo "Expand images" e2fsck -yf "$WORK_DIR"/wsa/"$ARCH"/system_ext.img || abort SYSTEM_EXT_SIZE=$(($(du --apparent-size -sB512 "$WORK_DIR"/wsa/"$ARCH"/system_ext.img | cut -f1) + 20000)) if [ -d "$WORK_DIR"/gapps/system_ext ]; then SYSTEM_EXT_SIZE=$(( SYSTEM_EXT_SIZE + $(du --apparent-size -sB512 "$WORK_DIR"/gapps/system_ext | cut -f1) )) fi resize2fs "$WORK_DIR"/wsa/"$ARCH"/system_ext.img "$SYSTEM_EXT_SIZE"s || abort e2fsck -yf "$WORK_DIR"/wsa/"$ARCH"/product.img || abort PRODUCT_SIZE=$(($(du --apparent-size -sB512 "$WORK_DIR"/wsa/"$ARCH"/product.img | cut -f1) + 20000)) if [ -d "$WORK_DIR"/gapps/product ]; then PRODUCT_SIZE=$(( PRODUCT_SIZE + $(du --apparent-size -sB512 "$WORK_DIR"/gapps/product | cut -f1) )) fi resize2fs "$WORK_DIR"/wsa/"$ARCH"/product.img "$PRODUCT_SIZE"s || abort e2fsck -yf "$WORK_DIR"/wsa/"$ARCH"/system.img || abort SYSTEM_SIZE=$(($(du --apparent-size -sB512 "$WORK_DIR"/wsa/"$ARCH"/system.img | cut -f1) + 20000)) if [ -d "$WORK_DIR"/gapps ]; then SYSTEM_SIZE=$(( SYSTEM_SIZE + $(du --apparent-size -sB512 "$WORK_DIR"/gapps | cut -f1) - $(du --apparent-size -sB512 "$WORK_DIR"/gapps/product | cut -f1) )) if [ -d "$WORK_DIR"/gapps/system_ext ]; then SYSTEM_SIZE=$(( SYSTEM_SIZE - $(du --apparent-size -sB512 "$WORK_DIR"/gapps/system_ext | cut -f1) )) fi fi if [ -d "$WORK_DIR"/magisk ]; then SYSTEM_SIZE=$(( SYSTEM_SIZE + $(du --apparent-size -sB512 "$WORK_DIR"/magisk/magisk | cut -f1) )) fi if [ -f "$DOWNLOAD_DIR"/magisk.zip ]; then SYSTEM_SIZE=$(( SYSTEM_SIZE + $(du --apparent-size -sB512 "$DOWNLOAD_DIR"/magisk.zip | cut -f1) )) fi if [ -d "../$ARCH/system" ]; then SYSTEM_SIZE=$(( SYSTEM_SIZE + $(du --apparent-size -sB512 "../$ARCH/system" | cut -f1) )) fi resize2fs "$WORK_DIR"/wsa/"$ARCH"/system.img "$SYSTEM_SIZE"s || abort e2fsck -yf "$WORK_DIR"/wsa/"$ARCH"/vendor.img || abort VENDOR_SIZE=$(($(du --apparent-size -sB512 "$WORK_DIR"/wsa/"$ARCH"/vendor.img | cut -f1) + 20000)) resize2fs "$WORK_DIR"/wsa/"$ARCH"/vendor.img "$VENDOR_SIZE"s || abort echo -e "Expand images done\n" echo "Mount images" sudo mkdir "$MOUNT_DIR" || abort sudo mount -o loop "$WORK_DIR"/wsa/"$ARCH"/system.img "$MOUNT_DIR" || abort sudo mount -o loop "$WORK_DIR"/wsa/"$ARCH"/vendor.img "$MOUNT_DIR"/vendor || abort sudo mount -o loop "$WORK_DIR"/wsa/"$ARCH"/product.img "$MOUNT_DIR"/product || abort sudo mount -o loop "$WORK_DIR"/wsa/"$ARCH"/system_ext.img "$MOUNT_DIR"/system_ext || abort echo -e "done\n" if [ $REMOVE_AMAZON = 'remove' ]; then echo "Remove Amazon AppStore" find "${MOUNT_DIR:?}"/product/{etc/permissions,etc/sysconfig,framework,priv-app} | grep -e amazon -e venezia | sudo xargs rm -rf echo -e "done\n" fi if [ "$ROOT_SOL" = 'magisk' ] || [ "$ROOT_SOL" = '' ]; then echo "Integrate Magisk" sudo mkdir "$MOUNT_DIR"/sbin sudo chcon --reference "$MOUNT_DIR"/init.environ.rc "$MOUNT_DIR"/sbin sudo chown root:root "$MOUNT_DIR"/sbin sudo chmod 0700 "$MOUNT_DIR"/sbin sudo cp "$WORK_DIR"/magisk/magisk/* "$MOUNT_DIR"/sbin/ sudo cp "$DOWNLOAD_DIR"/magisk.zip "$MOUNT_DIR"/sbin/magisk.apk sudo tee -a "$MOUNT_DIR"/sbin/loadpolicy.sh < EOF wine64 ../wine/"$HOST_ARCH"/makepri.exe new /pr "$WORK_DIR"/wsa/pri /in MicrosoftCorporationII.WindowsSubsystemForAndroid /cf "$WORK_DIR"/wsa/priconfig.xml /of "$WORK_DIR"/wsa/"$ARCH"/resources.pri /o sed -i -zE "s//\n$(cat "$WORK_DIR"/wsa/xml/* | grep -Po ']*/>' | sed ':a;N;$!ba;s/\n/\\n/g' | sed 's/\$/\\$/g' | sed 's/\//\\\//g')\n<\/Resources>/g" "$WORK_DIR"/wsa/"$ARCH"/AppxManifest.xml echo -e "Merge Language Resources done\n" echo "Add extra packages" sudo cp -r ../"$ARCH"/system/* "$MOUNT_DIR" || abort find ../"$ARCH"/system/system/priv-app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I dir sudo find "$MOUNT_DIR"/system/priv-app/dir -type d -exec chmod 0755 {} \; find ../"$ARCH"/system/system/priv-app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I dir sudo find "$MOUNT_DIR"/system/priv-app/dir -type f -exec chmod 0644 {} \; find ../"$ARCH"/system/system/priv-app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I dir sudo find "$MOUNT_DIR"/system/priv-app/dir -exec chown root:root {} \; find ../"$ARCH"/system/system/priv-app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I dir sudo find "$MOUNT_DIR"/system/priv-app/dir -exec chcon --reference="$MOUNT_DIR"/system/priv-app {} \; find ../"$ARCH"/system/system/etc/permissions/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I file sudo find "$MOUNT_DIR"/system/etc/permissions/file -type f -exec chmod 0644 {} \; find ../"$ARCH"/system/system/etc/permissions/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I file sudo find "$MOUNT_DIR"/system/etc/permissions/file -exec chown root:root {} \; find ../"$ARCH"/system/system/etc/permissions/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I file sudo find "$MOUNT_DIR"/system/etc/permissions/file -type f -exec chcon --reference="$MOUNT_DIR"/system/etc/permissions/platform.xml {} \; echo -e "Add extra packages done\n" if [ $GAPPS_VARIANT != 'none' ] && [ $GAPPS_VARIANT != '' ]; then echo "Integrate GApps" find "$WORK_DIR/gapps/" -mindepth 1 -type d -exec sudo chmod 0755 {} \; find "$WORK_DIR/gapps/" -mindepth 1 -type d -exec sudo chown root:root {} \; file_list="$(find "$WORK_DIR/gapps/" -mindepth 1 -type f | cut -d/ -f5-)" for file in $file_list; do sudo chown root:root "$WORK_DIR/gapps/${file}" sudo chmod 0644 "$WORK_DIR/gapps/${file}" done if [ $GAPPS_BRAND = "OpenGApps" ]; then find "$WORK_DIR"/gapps/ -maxdepth 1 -mindepth 1 -type d -not -path '*product' -exec sudo cp --preserve=all -r {} "$MOUNT_DIR"/system \; || abort elif [ $GAPPS_BRAND = "MindTheGapps" ]; then sudo cp --preserve=all -r "$WORK_DIR"/gapps/system_ext/* "$MOUNT_DIR"/system_ext/ || abort if [ -e "$MOUNT_DIR"/system_ext/priv-app/SetupWizard ] ; then rm -rf "${MOUNT_DIR:?}/system_ext/priv-app/Provision" fi fi sudo cp --preserve=all -r "$WORK_DIR"/gapps/product/* "$MOUNT_DIR"/product || abort find "$WORK_DIR"/gapps/product/overlay -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I file sudo find "$MOUNT_DIR"/product/overlay/file -type f -exec chcon --reference="$MOUNT_DIR"/product/overlay/FontNotoSerifSource/FontNotoSerifSourceOverlay.apk {} \; if [ $GAPPS_BRAND = "OpenGApps" ]; then find "$WORK_DIR"/gapps/app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I dir sudo find "$MOUNT_DIR"/system/app/dir -type d -exec chcon --reference="$MOUNT_DIR"/system/app {} \; find "$WORK_DIR"/gapps/framework/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I dir sudo find "$MOUNT_DIR"/system/framework/dir -type d -exec chcon --reference="$MOUNT_DIR"/system/framework {} \; find "$WORK_DIR"/gapps/priv-app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I dir sudo find "$MOUNT_DIR"/system/priv-app/dir -type d -exec chcon --reference="$MOUNT_DIR"/system/priv-app {} \; find "$WORK_DIR"/gapps/app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I file sudo find "$MOUNT_DIR"/system/app/file -type f -exec chcon --reference="$MOUNT_DIR"/system/app/KeyChain/KeyChain.apk {} \; find "$WORK_DIR"/gapps/framework/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I file sudo find "$MOUNT_DIR"/system/framework/file -type f -exec chcon --reference="$MOUNT_DIR"/system/framework/ext.jar {} \; find "$WORK_DIR"/gapps/priv-app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I file sudo find "$MOUNT_DIR"/system/priv-app/file -type f -exec chcon --reference="$MOUNT_DIR"/system/priv-app/Shell/Shell.apk {} \; find "$WORK_DIR"/gapps/etc/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I dir sudo find "$MOUNT_DIR"/system/etc/dir -type d -exec chcon --reference="$MOUNT_DIR"/system/etc/permissions {} \; find "$WORK_DIR"/gapps/etc/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I dir sudo find "$MOUNT_DIR"/system/etc/dir -type f -exec chcon --reference="$MOUNT_DIR"/system/etc/permissions {} \; else find "$WORK_DIR"/gapps/product/app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I item sudo find "$MOUNT_DIR"/product/app/item -type d -exec chcon --reference="$MOUNT_DIR"/product/app {} \; find "$WORK_DIR"/gapps/product/etc/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I item sudo find "$MOUNT_DIR"/product/etc/item -type d -exec chcon --reference="$MOUNT_DIR"/product/etc {} \; find "$WORK_DIR"/gapps/product/priv-app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I item sudo find "$MOUNT_DIR"/product/priv-app/item -type d -exec chcon --reference="$MOUNT_DIR"/product/priv-app {} \; find "$WORK_DIR"/gapps/product/framework/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I item sudo find "$MOUNT_DIR"/product/framework/item -type d -exec chcon --reference="$MOUNT_DIR"/product/framework {} \; find "$WORK_DIR"/gapps/product/app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I item sudo find "$MOUNT_DIR"/product/app/item -type f -exec chcon --reference="$MOUNT_DIR"/product/app/HomeApp/HomeApp.apk {} \; find "$WORK_DIR"/gapps/product/etc/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I item sudo find "$MOUNT_DIR"/product/etc/item -type f -exec chcon --reference="$MOUNT_DIR"/product/etc/permissions/com.android.settings.intelligence.xml {} \; find "$WORK_DIR"/gapps/product/priv-app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I item sudo find "$MOUNT_DIR"/product/priv-app/item -type f -exec chcon --reference="$MOUNT_DIR"/product/priv-app/SettingsIntelligence/SettingsIntelligence.apk {} \; find "$WORK_DIR"/gapps/product/framework/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I item sudo find "$MOUNT_DIR"/product/framework/item -type f -exec chcon --reference="$MOUNT_DIR"/product/etc/permissions/com.android.settings.intelligence.xml {} \; find "$WORK_DIR"/gapps/system_ext/etc/permissions/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I file sudo find "$MOUNT_DIR"/system_ext/etc/permissions/file -type f -exec chcon --reference="$MOUNT_DIR"/system_ext/etc/permissions/com.android.systemui.xml {} \; find "$WORK_DIR"/gapps/product/lib/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I file sudo find "$MOUNT_DIR"/product/lib/file -exec chcon --reference="$MOUNT_DIR"/product/lib64/libjni_eglfence.so {} \; find "$WORK_DIR"/gapps/product/lib64/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I file sudo find "$MOUNT_DIR"/product/lib64/file -type f -exec chcon --reference="$MOUNT_DIR"/product/lib64/libjni_eglfence.so {} \; find "$WORK_DIR"/gapps/system_ext/priv-app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I dir sudo find "$MOUNT_DIR"/system_ext/priv-app/dir -type d -exec chcon --reference="$MOUNT_DIR"/system_ext/priv-app {} \; find "$WORK_DIR"/gapps/system_ext/etc/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I dir sudo find "$MOUNT_DIR"/system_ext/etc/dir -type d -exec chcon --reference="$MOUNT_DIR"/system_ext/etc {} \; find "$WORK_DIR"/gapps/system_ext/priv-app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I dir sudo find "$MOUNT_DIR"/system_ext/priv-app/dir -type f -exec chcon --reference="$MOUNT_DIR"/system_ext/priv-app/Settings/Settings.apk {} \; fi sudo patchelf --replace-needed libc.so "../linker/$HOST_ARCH/libc.so" "$WORK_DIR"/magisk/magiskpolicy || abort sudo patchelf --replace-needed libm.so "../linker/$HOST_ARCH/libm.so" "$WORK_DIR"/magisk/magiskpolicy || abort sudo patchelf --replace-needed libdl.so "../linker/$HOST_ARCH/libdl.so" "$WORK_DIR"/magisk/magiskpolicy || abort sudo patchelf --set-interpreter "../linker/$HOST_ARCH/linker64" "$WORK_DIR"/magisk/magiskpolicy || abort chmod +x "$WORK_DIR"/magisk/magiskpolicy || abort sudo "$WORK_DIR"/magisk/magiskpolicy --load "$MOUNT_DIR"/vendor/etc/selinux/precompiled_sepolicy --save "$MOUNT_DIR"/vendor/etc/selinux/precompiled_sepolicy "allow gmscore_app gmscore_app vsock_socket { create connect write read }" "allow gmscore_app device_config_runtime_native_boot_prop file read" "allow gmscore_app system_server_tmpfs dir search" "allow gmscore_app system_server_tmpfs file open" || abort echo -e "Integrate GApps done\n" fi if [ $GAPPS_VARIANT != 'none' ] && [ $GAPPS_VARIANT != '' ]; then echo "Fix GApps prop" sudo python3 fixGappsProp.py "$MOUNT_DIR" || abort echo -e "done\n" fi echo "Umount images" sudo find "$MOUNT_DIR" -exec touch -amt 200901010000.00 {} \; >/dev/null 2>&1 sudo umount "$MOUNT_DIR"/vendor sudo umount "$MOUNT_DIR"/product sudo umount "$MOUNT_DIR"/system_ext sudo umount "$MOUNT_DIR" echo -e "done\n" echo "Shrink images" e2fsck -yf "$WORK_DIR"/wsa/"$ARCH"/system.img || abort resize2fs -M "$WORK_DIR"/wsa/"$ARCH"/system.img || abort e2fsck -yf "$WORK_DIR"/wsa/"$ARCH"/vendor.img || abort resize2fs -M "$WORK_DIR"/wsa/"$ARCH"/vendor.img || abort e2fsck -yf "$WORK_DIR"/wsa/"$ARCH"/product.img || abort resize2fs -M "$WORK_DIR"/wsa/"$ARCH"/product.img || abort e2fsck -yf "$WORK_DIR"/wsa/"$ARCH"/system_ext.img || abort resize2fs -M "$WORK_DIR"/wsa/"$ARCH"/system_ext.img || abort echo -e "Shrink images done\n" echo "Remove signature and add scripts" sudo rm -rf "${WORK_DIR:?}"/wsa/"$ARCH"/\[Content_Types\].xml "$WORK_DIR"/wsa/"$ARCH"/AppxBlockMap.xml "$WORK_DIR"/wsa/"$ARCH"/AppxSignature.p7x "$WORK_DIR"/wsa/"$ARCH"/AppxMetadata || abort cp "$DOWNLOAD_DIR"/vclibs.appx "$DOWNLOAD_DIR"/xaml.appx "$WORK_DIR"/wsa/"$ARCH" || abort tee "$WORK_DIR"/wsa/"$ARCH"/Install.ps1 <