From 4e0aca05bd43d0020ce29e1fabe3eb68811cce6f Mon Sep 17 00:00:00 2001
From: Howard20181 <40033067+Howard20181@users.noreply.github.com>
Date: Mon, 29 Aug 2022 16:29:54 +0800
Subject: [PATCH 01/10] Implement cli
---
scripts/build.sh | 654 +++++++++++++++++++++++++++++++++++++++++++++++
scripts/run.sh | 565 ++--------------------------------------
2 files changed, 674 insertions(+), 545 deletions(-)
create mode 100755 scripts/build.sh
diff --git a/scripts/build.sh b/scripts/build.sh
new file mode 100755
index 0000000..40ceeb9
--- /dev/null
+++ b/scripts/build.sh
@@ -0,0 +1,654 @@
+#!/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_WSA=0
+CLEAN_DOWNLOAD_MAGISK=0
+CLEAN_DOWNLOAD_GAPPS=0
+REMOVE_AMAZON="keep"
+COMPRESS_OUTPUT="no"
+OFF_LINE=0
+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:?}"
+}
+clean_download(){
+ if [ -d "$DOWNLOAD_DIR" ]; then
+ echo "Cleanup Download Directory"
+ if [ "$CLEAN_DOWNLOAD_WSA" = "1" ]; then
+ rm -f "${WSA_ZIP_PATH:?}"
+ fi
+ if [ "$CLEAN_DOWNLOAD_MAGISK" = "1" ]; then
+ rm -f "${MAGISK_PATH:?}"
+ fi
+ if [ "$CLEAN_DOWNLOAD_GAPPS" = "1" ]; then
+ rm -f "${GAPPS_PATH:?}"
+ fi
+ fi
+}
+abort() {
+ echo "Build: an error has occurred, exit"
+ if [ -d "$WORK_DIR" ]; then
+ umount_clean
+ fi
+ clean_download
+ exit 1
+}
+trap abort INT TERM
+
+function Gen_Rand_Str {
+ tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w "$1" | head -n 1
+}
+
+usage(){
+ if [ -n "$1" ]; then
+ echo "Unknown parameter: $1"
+ fi
+ echo "Usage:
+ --arch
+ --release-type
+ --magisk-ver
+ --gapps-brand
+ --gapps-variant
+ --root-sol
+ --remove-amazon
+ --compress
+ --off-line
+ --magisk-custom
+ --debug
+ "
+ exit 1
+}
+
+ARGUMENT_LIST=(
+ "arch:"
+ "release-type:"
+ "magisk-ver:"
+ "gapps-brand:"
+ "gapps-variant:"
+ "root-sol:"
+ "remove-amazon"
+ "compress"
+ "off-line"
+ "magisk-custom"
+ "debug"
+)
+
+opts=$(getopt \
+ --longoptions "$(printf "%s," "${ARGUMENT_LIST[@]}")" \
+ --name "$(basename "$0")" \
+ --options "" \
+ -- "$@"
+)
+
+eval set --"$opts"
+while [[ $# -gt 0 ]]; do
+ case "$1" in
+ --arch ) ARCH="$2"; shift 2 ;;
+ --release-type ) RELEASE_TYPE="$2"; shift 2 ;;
+ --magisk-ver ) MAGISK_VER="$2"; shift 2 ;;
+ --gapps-brand ) GAPPS_BRAND="$2"; shift 2 ;;
+ --gapps-variant ) GAPPS_VARIANT="$2"; shift 2 ;;
+ --remove-amazon ) REMOVE_AMAZON="remove"; shift ;;
+ --root-sol ) ROOT_SOL="$2"; shift 2 ;;
+ --compress ) COMPRESS_OUTPUT="yes"; shift ;;
+ --off-line ) OFF_LINE="1"; shift ;;
+ --debug ) DEBUG="1"; shift ;;
+ --magisk-custom ) CUSTOM_MAGISK="1"; shift ;;
+ -- ) shift; break;;
+ ? ) usage "$2"; shift ;;
+ * ) break ;;
+ esac
+done
+
+declare -A PARA_CHECK_LIST=([ARCH]="$ARCH" [RELEASE_TYPE]="$RELEASE_TYPE" [MAGISK_VER]="$MAGISK_VER" [GAPPS_VARIANT]="$GAPPS_VARIANT" [REMOVE_AMAZON]="$REMOVE_AMAZON" [ROOT_SOL]="$ROOT_SOL")
+for i in "${PARA_CHECK_LIST[@]}";
+do
+ if [ -z "$i" ]; then
+ usage
+ fi
+done
+
+echo -e "build: 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"
+
+declare -A RELEASE_TYPE_MAP=(["retail"]="Retail" ["release preview"]="RP" ["insider slow"]="WIS" ["insider fast"]="WIF")
+
+WSA_ZIP_PATH=$DOWNLOAD_DIR/wsa-$ARCH-${RELEASE_TYPE_MAP[$RELEASE_TYPE]}.zip
+MAGISK_PATH=$DOWNLOAD_DIR/magisk-$MAGISK_VER.zip
+if [ "$GAPPS_BRAND" = "OpenGApps" ]; then
+ GAPPS_PATH="$DOWNLOAD_DIR"/OpenGApps-$ARCH-$GAPPS_VARIANT.zip
+else
+ GAPPS_PATH="$DOWNLOAD_DIR"/MindTheGapps-"$ARCH".zip
+fi
+
+if [ "$OFF_LINE" != "1" ]; then
+ trap 'rm -f -- "${DOWNLOAD_DIR:?}/${DOWNLOAD_CONF_NAME}"' EXIT
+ echo "Generate Download Links"
+ python3 generateWSALinks.py "$ARCH" "$RELEASE_TYPE" "$DOWNLOAD_DIR" "$DOWNLOAD_CONF_NAME" || abort
+ if [ "$CUSTOM_MAGISK" != "1" ]; then
+ python3 generateMagiskLink.py "$MAGISK_VER" "$DOWNLOAD_DIR" "$DOWNLOAD_CONF_NAME" || abort
+ fi
+ if [ "$GAPPS_VARIANT" != 'none' ] && [ "$GAPPS_VARIANT" != '' ]; then
+ if [ "$GAPPS_BRAND" = "OpenGApps" ]; then
+ python3 generateGappsLink.py "$ARCH" "$GAPPS_VARIANT" "$DOWNLOAD_DIR" "$DOWNLOAD_CONF_NAME" || abort
+ fi
+ fi
+
+ echo "Download Artifacts"
+ if ! aria2c --no-conf --log-level=info --log="$DOWNLOAD_DIR/aria2_download.log" -x16 -s16 -j5 -c -R -m0 --allow-overwrite=true --conditional-get=true -d"$DOWNLOAD_DIR" -i"$DOWNLOAD_DIR"/"$DOWNLOAD_CONF_NAME"; then
+ echo "We have encountered an error while downloading files."
+ exit 1
+ fi
+else
+ if [ ! -f "$WSA_ZIP_PATH" ] || [ ! -f "$MAGISK_PATH" ] || [ ! -f "$GAPPS_PATH" ]; then
+ echo "Off line: Some of the file missing, please use online mode."
+ exit 1
+ fi
+fi
+
+echo "Extract WSA"
+if [ -f "$WSA_ZIP_PATH" ]; then
+ WSA_WORK_ENV="${WORK_DIR:?}"/ENV
+ if [ -f "$WSA_WORK_ENV" ]; then rm -f "${WSA_WORK_ENV:?}"; fi
+ export WSA_WORK_ENV
+ if ! python3 extractWSA.py "$ARCH" "$WSA_ZIP_PATH" "$WORK_DIR"; then
+ echo "Unzip WSA failed, is the download incomplete?"
+ CLEAN_DOWNLOAD_WSA=1
+ abort
+ fi
+ echo -e "Extract done\n"
+ # shellcheck disable=SC1091
+ source "${WORK_DIR:?}/ENV" || abort
+else
+ echo "The WSA zip package does not exist, is the download incomplete?"
+ exit 1
+fi
+echo "Extract Magisk"
+
+if [ -f "$MAGISK_PATH" ]; then
+ if ! python3 extractMagisk.py "$ARCH" "$MAGISK_PATH" "$WORK_DIR"; then
+ echo "Unzip Magisk failed, is the download incomplete?"
+ CLEAN_DOWNLOAD_MAGISK=1
+ abort
+ fi
+elif [ "$CUSTOM_MAGISK" != "1" ]; then
+ echo "The Magisk zip package does not exist, is the download incomplete?"
+ exit 1
+else
+ echo "The Magisk zip package does not exist, rename it to magisk-debug.zip and put it in the download folder."
+ exit 1
+fi
+echo -e "done\n"
+
+if [ "$GAPPS_VARIANT" != 'none' ] && [ "$GAPPS_VARIANT" != '' ]; then
+ echo "Extract GApps"
+ mkdir -p "$WORK_DIR"/gapps || abort
+ if [ -f "$GAPPS_PATH" ]; then
+ if [ "$GAPPS_BRAND" = "OpenGApps" ]; then
+ if ! unzip -p "$GAPPS_PATH" {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'; then
+ echo "Unzip OpenGApps failed, is the download incomplete?"
+ CLEAN_DOWNLOAD_GAPPS=1
+ abort
+ fi
+ else
+ if ! unzip "$GAPPS_PATH" "system/*" -x "system/addon.d/*" "system/system_ext/priv-app/SetupWizard/*" -d "$WORK_DIR"/gapps; then
+ echo "Unzip MindTheGapps failed, package is corrupted?"
+ abort
+ fi
+ 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
+ else
+ echo "The $GAPPS_BRAND zip package does not exist."
+ exit 1
+ 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 "$MAGISK_PATH" ]; then
+ SYSTEM_SIZE=$(( SYSTEM_SIZE + $(du --apparent-size -sB512 "$MAGISK_PATH" | 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 "$MAGISK_PATH" "$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 {} \;
+
+ sudo chcon --reference="$MOUNT_DIR"/product/lib64/libjni_eglfence.so "$MOUNT_DIR"/product/lib
+ 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-"$ARCH".appx "$DOWNLOAD_DIR"/xaml-"$ARCH".appx "$WORK_DIR"/wsa/"$ARCH" || abort
+tee "$WORK_DIR"/wsa/"$ARCH"/Install.ps1 <&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_WSA=0
-CLEAN_DOWNLOAD_MAGISK=0
-CLEAN_DOWNLOAD_GAPPS=0
-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:?}"
-}
-clean_download(){
- if [ -d "$DOWNLOAD_DIR" ]; then
- echo "Cleanup Download Directory"
- if [ "$CLEAN_DOWNLOAD_WSA" = "1" ]; then
- rm -f "${WSA_ZIP_PATH:?}"
- fi
- if [ "$CLEAN_DOWNLOAD_MAGISK" = "1" ]; then
- rm -f "${MAGISK_PATH:?}"
- fi
- if [ "$CLEAN_DOWNLOAD_GAPPS" = "1" ]; then
- rm -f "${GAPPS_PATH:?}"
- fi
- fi
-}
-abort() {
- echo "An error has occurred, exit"
- if [ -d "$WORK_DIR" ]; then
- umount_clean
- fi
- clean_download
+
+abort(){
+ echo "Dependencies: an error has occurred, exit"
exit 1
}
-trap abort INT TERM
function Radiolist {
declare -A o="$1"
@@ -92,10 +45,6 @@ function YesNoBox {
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
@@ -173,9 +122,9 @@ else
fi
if (YesNoBox '([title]="Remove Amazon AppStore" [text]="Do you want to keep Amazon AppStore?")'); then
- REMOVE_AMAZON="keep"
+ REMOVE_AMAZON=""
else
- REMOVE_AMAZON="remove"
+ REMOVE_AMAZON="--remove-amazon"
fi
ROOT_SOL=$(
@@ -187,493 +136,19 @@ ROOT_SOL=$(
)
if (YesNoBox '([title]="Compress output" [text]="Do you want to compress the output?")'); then
- COMPRESS_OUTPUT="yes"
+ COMPRESS_OUTPUT="--compress"
else
- COMPRESS_OUTPUT="no"
+ COMPRESS_OUTPUT=""
fi
+# if ! (YesNoBox '([title]="Off line mode" [text]="Do you want to enable off line mode?")'); then
+# OFF_LINE="--OFF-LINE"
+# else
+# OFF_LINE=""
+# fi
+OFF_LINE="--off-line"
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"
-declare -A RELEASE_TYPE_MAP=(["retail"]="Retail" ["release preview"]="RP" ["insider slow"]="WIS" ["insider fast"]="WIF")
-trap 'rm -f -- "${DOWNLOAD_DIR:?}/${DOWNLOAD_CONF_NAME}"' EXIT
-echo "Generate Download Links"
-python3 generateWSALinks.py "$ARCH" "$RELEASE_TYPE" "$DOWNLOAD_DIR" "$DOWNLOAD_CONF_NAME" || abort
-if [ "$CUSTOM_MAGISK" != "1" ]; then
- python3 generateMagiskLink.py "$MAGISK_VER" "$DOWNLOAD_DIR" "$DOWNLOAD_CONF_NAME" || abort
-fi
-if [ $GAPPS_VARIANT != 'none' ] && [ $GAPPS_VARIANT != '' ]; then
- if [ $GAPPS_BRAND = "OpenGApps" ]; then
- python3 generateGappsLink.py "$ARCH" "$GAPPS_VARIANT" "$DOWNLOAD_DIR" "$DOWNLOAD_CONF_NAME" || abort
- fi
-fi
-echo "Download Artifacts"
-if ! aria2c --no-conf --log-level=info --log="$DOWNLOAD_DIR/aria2_download.log" -x16 -s16 -j5 -c -R -m0 --allow-overwrite=true --conditional-get=true -d"$DOWNLOAD_DIR" -i"$DOWNLOAD_DIR"/"$DOWNLOAD_CONF_NAME"; then
- echo "We have encountered an error while downloading files."
- exit 1
-fi
-WSA_ZIP_PATH=$DOWNLOAD_DIR/wsa-$ARCH-${RELEASE_TYPE_MAP[$RELEASE_TYPE]}.zip
-MAGISK_PATH=$DOWNLOAD_DIR/magisk-$MAGISK_VER.zip
-GAPPS_PATH="$DOWNLOAD_DIR"/OpenGApps-$ARCH-$GAPPS_VARIANT.zip
-
-echo "Extract WSA"
-if [ -f "$WSA_ZIP_PATH" ]; then
- WSA_WORK_ENV="${WORK_DIR:?}"/ENV
- if [ -f "$WSA_WORK_ENV" ]; then rm -f "${WSA_WORK_ENV:?}"; fi
- export WSA_WORK_ENV
- if ! python3 extractWSA.py "$ARCH" "$WSA_ZIP_PATH" "$WORK_DIR"; then
- echo "Unzip WSA failed, is the download incomplete?"
- CLEAN_DOWNLOAD_WSA=1
- abort
- fi
- echo -e "Extract done\n"
- source "${WORK_DIR:?}/ENV" || abort
-else
- echo "The WSA zip package does not exist, is the download incomplete?"
- exit 1
-fi
-echo "Extract Magisk"
-
-if [ -f "$MAGISK_PATH" ]; then
- if ! python3 extractMagisk.py "$ARCH" "$MAGISK_PATH" "$WORK_DIR"; then
- echo "Unzip Magisk failed, is the download incomplete?"
- CLEAN_DOWNLOAD_MAGISK=1
- abort
- fi
-elif [ "$CUSTOM_MAGISK" != "1" ]; then
- echo "The Magisk zip package does not exist, is the download incomplete?"
- exit 1
-else
- echo "The Magisk zip package does not exist, rename it to magisk-debug.zip and put it in the download folder."
- exit 1
-fi
-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
- if [ -f "$GAPPS_PATH" ]; then
- if ! unzip -p "$GAPPS_PATH" {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'; then
- echo "Unzip OpenGApps failed, is the download incomplete?"
- CLEAN_DOWNLOAD_GAPPS=1
- abort
- fi
- else
- echo "The OpenGApps zip package does not exist, is the download incomplete?"
- exit 1
- fi
- else
- if ! unzip "$DOWNLOAD_DIR"/MindTheGapps-"$ARCH".zip "system/*" -x "system/addon.d/*" "system/system_ext/priv-app/SetupWizard/*" -d "$WORK_DIR"/gapps; then
- echo "Unzip MindTheGapps failed, package is corrupted?"
- abort
- fi
- 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 "$MAGISK_PATH" ]; then
- SYSTEM_SIZE=$(( SYSTEM_SIZE + $(du --apparent-size -sB512 "$MAGISK_PATH" | 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 "$MAGISK_PATH" "$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 {} \;
-
- sudo chcon --reference="$MOUNT_DIR"/product/lib64/libjni_eglfence.so "$MOUNT_DIR"/product/lib
- 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-"$ARCH".appx "$DOWNLOAD_DIR"/xaml-"$ARCH".appx "$WORK_DIR"/wsa/"$ARCH" || abort
-tee "$WORK_DIR"/wsa/"$ARCH"/Install.ps1 <
Date: Mon, 29 Aug 2022 16:39:35 +0800
Subject: [PATCH 02/10] Disable offline mode by default
---
scripts/run.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/run.sh b/scripts/run.sh
index 1c0a7b6..d10371e 100755
--- a/scripts/run.sh
+++ b/scripts/run.sh
@@ -146,7 +146,7 @@ fi
# else
# OFF_LINE=""
# fi
-OFF_LINE="--off-line"
+# OFF_LINE="--off-line"
clear
COMMAND_LINE=(--arch "$ARCH" --release-type "$RELEASE_TYPE" --magisk-ver "$MAGISK_VER" --gapps-brand "$GAPPS_BRAND" --gapps-variant "$GAPPS_VARIANT" "$REMOVE_AMAZON" --root-sol "$ROOT_SOL" "$COMPRESS_OUTPUT" "$OFF_LINE" "$DEBUG" "$CUSTOM_MAGISK")
From 741c7fe6110c071e3104ea21f3a14c1c244cfbf2 Mon Sep 17 00:00:00 2001
From: Howard Wu <40033067+Howard20181@users.noreply.github.com>
Date: Mon, 29 Aug 2022 16:47:59 +0800
Subject: [PATCH 03/10] off-line -> offline
---
scripts/build.sh | 12 ++++++------
scripts/run.sh | 8 ++++----
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/scripts/build.sh b/scripts/build.sh
index 40ceeb9..ddaf6e0 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -39,7 +39,7 @@ CLEAN_DOWNLOAD_MAGISK=0
CLEAN_DOWNLOAD_GAPPS=0
REMOVE_AMAZON="keep"
COMPRESS_OUTPUT="no"
-OFF_LINE=0
+OFFLINE=0
umount_clean(){
echo "Cleanup Work Directory"
if [ -d "$MOUNT_DIR" ]; then
@@ -97,7 +97,7 @@ usage(){
--root-sol
--remove-amazon
--compress
- --off-line
+ --offline
--magisk-custom
--debug
"
@@ -113,7 +113,7 @@ ARGUMENT_LIST=(
"root-sol:"
"remove-amazon"
"compress"
- "off-line"
+ "offline"
"magisk-custom"
"debug"
)
@@ -136,7 +136,7 @@ while [[ $# -gt 0 ]]; do
--remove-amazon ) REMOVE_AMAZON="remove"; shift ;;
--root-sol ) ROOT_SOL="$2"; shift 2 ;;
--compress ) COMPRESS_OUTPUT="yes"; shift ;;
- --off-line ) OFF_LINE="1"; shift ;;
+ --offline ) OFFLINE="1"; shift ;;
--debug ) DEBUG="1"; shift ;;
--magisk-custom ) CUSTOM_MAGISK="1"; shift ;;
-- ) shift; break;;
@@ -165,7 +165,7 @@ else
GAPPS_PATH="$DOWNLOAD_DIR"/MindTheGapps-"$ARCH".zip
fi
-if [ "$OFF_LINE" != "1" ]; then
+if [ "$OFFLINE" != "1" ]; then
trap 'rm -f -- "${DOWNLOAD_DIR:?}/${DOWNLOAD_CONF_NAME}"' EXIT
echo "Generate Download Links"
python3 generateWSALinks.py "$ARCH" "$RELEASE_TYPE" "$DOWNLOAD_DIR" "$DOWNLOAD_CONF_NAME" || abort
@@ -185,7 +185,7 @@ if [ "$OFF_LINE" != "1" ]; then
fi
else
if [ ! -f "$WSA_ZIP_PATH" ] || [ ! -f "$MAGISK_PATH" ] || [ ! -f "$GAPPS_PATH" ]; then
- echo "Off line: Some of the file missing, please use online mode."
+ echo "Off line: Some of the file missing, please disable offline mode."
exit 1
fi
fi
diff --git a/scripts/run.sh b/scripts/run.sh
index d10371e..bb884e5 100755
--- a/scripts/run.sh
+++ b/scripts/run.sh
@@ -142,13 +142,13 @@ else
fi
# if ! (YesNoBox '([title]="Off line mode" [text]="Do you want to enable off line mode?")'); then
-# OFF_LINE="--OFF-LINE"
+# OFFLINE="--offline"
# else
-# OFF_LINE=""
+# OFFLINE=""
# fi
-# OFF_LINE="--off-line"
+# OFFLINE="--offline"
clear
-COMMAND_LINE=(--arch "$ARCH" --release-type "$RELEASE_TYPE" --magisk-ver "$MAGISK_VER" --gapps-brand "$GAPPS_BRAND" --gapps-variant "$GAPPS_VARIANT" "$REMOVE_AMAZON" --root-sol "$ROOT_SOL" "$COMPRESS_OUTPUT" "$OFF_LINE" "$DEBUG" "$CUSTOM_MAGISK")
+COMMAND_LINE=(--arch "$ARCH" --release-type "$RELEASE_TYPE" --magisk-ver "$MAGISK_VER" --gapps-brand "$GAPPS_BRAND" --gapps-variant "$GAPPS_VARIANT" "$REMOVE_AMAZON" --root-sol "$ROOT_SOL" "$COMPRESS_OUTPUT" "$OFFLINE" "$DEBUG" "$CUSTOM_MAGISK")
echo "COMMAND_LINE=${COMMAND_LINE[*]}"
./build.sh "${COMMAND_LINE[@]}"
From d30124de601c2d3ae081a8f8197772823a0cb658 Mon Sep 17 00:00:00 2001
From: Howard Wu <40033067+Howard20181@users.noreply.github.com>
Date: Mon, 29 Aug 2022 18:51:16 +0800
Subject: [PATCH 04/10] Offline mode: more detailed error reporting
---
scripts/build.sh | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/scripts/build.sh b/scripts/build.sh
index ddaf6e0..d5dbe8f 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -136,7 +136,7 @@ while [[ $# -gt 0 ]]; do
--remove-amazon ) REMOVE_AMAZON="remove"; shift ;;
--root-sol ) ROOT_SOL="$2"; shift 2 ;;
--compress ) COMPRESS_OUTPUT="yes"; shift ;;
- --offline ) OFFLINE="1"; shift ;;
+ --offline ) OFFLINE="1"; shift ;;
--debug ) DEBUG="1"; shift ;;
--magisk-custom ) CUSTOM_MAGISK="1"; shift ;;
-- ) shift; break;;
@@ -158,6 +158,8 @@ echo -e "build: ARCH=$ARCH\nRELEASE_TYPE=$RELEASE_TYPE\nMAGISK_VER=$MAGISK_VER\n
declare -A RELEASE_TYPE_MAP=(["retail"]="Retail" ["release preview"]="RP" ["insider slow"]="WIS" ["insider fast"]="WIF")
WSA_ZIP_PATH=$DOWNLOAD_DIR/wsa-$ARCH-${RELEASE_TYPE_MAP[$RELEASE_TYPE]}.zip
+vclibs_PATH=vclibs-"$ARCH".appx
+xaml_PATH=xaml-"$ARCH".appx
MAGISK_PATH=$DOWNLOAD_DIR/magisk-$MAGISK_VER.zip
if [ "$GAPPS_BRAND" = "OpenGApps" ]; then
GAPPS_PATH="$DOWNLOAD_DIR"/OpenGApps-$ARCH-$GAPPS_VARIANT.zip
@@ -184,8 +186,22 @@ if [ "$OFFLINE" != "1" ]; then
exit 1
fi
else
- if [ ! -f "$WSA_ZIP_PATH" ] || [ ! -f "$MAGISK_PATH" ] || [ ! -f "$GAPPS_PATH" ]; then
- echo "Off line: Some of the file missing, please disable offline mode."
+ if [ ! -f "$WSA_ZIP_PATH" ] || [ ! -f "$xaml_PATH" ] || [ ! -f "$vclibs_PATH" ]; then
+ echo "Offline mode: missing WSA files."
+ OFFLINE_ERR="1"
+ fi
+ if [ ! -f "$MAGISK_PATH" ]; then
+ echo "Offline mode: missing Magisk $MAGISK_VER file."
+ OFFLINE_ERR="1"
+ fi
+ if [ "$GAPPS_VARIANT" != 'none' ] && [ "$GAPPS_VARIANT" != '' ]; then
+ if [ ! -f "$GAPPS_PATH" ]; then
+ echo "Offline mode: missing $GAPPS_BRAND file."
+ OFFLINE_ERR="1"
+ fi
+ fi
+ if [ -n "$OFFLINE_ERR" ]; then
+ echo "Offline mode: Some files are missing, please disable offline mode."
exit 1
fi
fi
@@ -515,7 +531,7 @@ 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-"$ARCH".appx "$DOWNLOAD_DIR"/xaml-"$ARCH".appx "$WORK_DIR"/wsa/"$ARCH" || abort
+cp "$DOWNLOAD_DIR"/"$vclibs_PATH" "$DOWNLOAD_DIR"/"$xaml_PATH" "$WORK_DIR"/wsa/"$ARCH" || abort
tee "$WORK_DIR"/wsa/"$ARCH"/Install.ps1 <
Date: Tue, 30 Aug 2022 21:59:26 +0800
Subject: [PATCH 05/10] Fix offline mode
---
scripts/build.sh | 126 +++++++++++++++++++++++++----------------------
scripts/run.sh | 4 +-
2 files changed, 69 insertions(+), 61 deletions(-)
diff --git a/scripts/build.sh b/scripts/build.sh
index d5dbe8f..04780d6 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -34,12 +34,6 @@ DOWNLOAD_DIR=../download
DOWNLOAD_CONF_NAME=download.list
OUTPUT_DIR=../output
MOUNT_DIR="$WORK_DIR"/system
-CLEAN_DOWNLOAD_WSA=0
-CLEAN_DOWNLOAD_MAGISK=0
-CLEAN_DOWNLOAD_GAPPS=0
-REMOVE_AMAZON="keep"
-COMPRESS_OUTPUT="no"
-OFFLINE=0
umount_clean(){
echo "Cleanup Work Directory"
if [ -d "$MOUNT_DIR" ]; then
@@ -59,13 +53,13 @@ umount_clean(){
clean_download(){
if [ -d "$DOWNLOAD_DIR" ]; then
echo "Cleanup Download Directory"
- if [ "$CLEAN_DOWNLOAD_WSA" = "1" ]; then
+ if [ "$CLEAN_DOWNLOAD_WSA" ]; then
rm -f "${WSA_ZIP_PATH:?}"
fi
- if [ "$CLEAN_DOWNLOAD_MAGISK" = "1" ]; then
+ if [ "$CLEAN_DOWNLOAD_MAGISK" ]; then
rm -f "${MAGISK_PATH:?}"
fi
- if [ "$CLEAN_DOWNLOAD_GAPPS" = "1" ]; then
+ if [ "$CLEAN_DOWNLOAD_GAPPS" ]; then
rm -f "${GAPPS_PATH:?}"
fi
fi
@@ -84,22 +78,33 @@ function Gen_Rand_Str {
tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w "$1" | head -n 1
}
+
+default(){
+ ARCH=x64
+ RELEASE_TYPE=retail
+ MAGISK_VER=stable
+ GAPPS_BRAND=OpenGApps
+ GAPPS_VARIANT=pico
+ ROOT_SOL=magisk
+}
+
usage(){
- if [ -n "$1" ]; then
+ default
+ if [ "$1" ]; then
echo "Unknown parameter: $1"
fi
echo "Usage:
- --arch
- --release-type
- --magisk-ver
- --gapps-brand
- --gapps-variant
- --root-sol
- --remove-amazon
- --compress
- --offline
- --magisk-custom
- --debug
+ --arch Architecture of WSA, x64 or arm64, default: $ARCH
+ --release-type Release type of WSA, retail or debug, default: $RELEASE_TYPE
+ --magisk-ver Magisk version, stable or canary, default: $MAGISK_VER
+ --gapps-brand GApps brand, OpenGApps or MindTheGApps, default: $GAPPS_BRAND
+ --gapps-variant GApps variant, pico or full, etc...., default: $GAPPS_VARIANT
+ --root-sol Root solution, magisk or null, default: $ROOT_SOL
+ --remove-amazon Remove Amazon from the system, default: false
+ --compress Compress the WSA, default: false
+ --offline Build WSA offline, default: false
+ --magisk-custom Install custom Magisk, default: false
+ --debug Debug build mode, default: false
"
exit 1
}
@@ -116,8 +121,11 @@ ARGUMENT_LIST=(
"offline"
"magisk-custom"
"debug"
+ "help"
)
+default
+
opts=$(getopt \
--longoptions "$(printf "%s," "${ARGUMENT_LIST[@]}")" \
--name "$(basename "$0")" \
@@ -128,38 +136,37 @@ opts=$(getopt \
eval set --"$opts"
while [[ $# -gt 0 ]]; do
case "$1" in
- --arch ) ARCH="$2"; shift 2 ;;
- --release-type ) RELEASE_TYPE="$2"; shift 2 ;;
- --magisk-ver ) MAGISK_VER="$2"; shift 2 ;;
- --gapps-brand ) GAPPS_BRAND="$2"; shift 2 ;;
- --gapps-variant ) GAPPS_VARIANT="$2"; shift 2 ;;
- --remove-amazon ) REMOVE_AMAZON="remove"; shift ;;
- --root-sol ) ROOT_SOL="$2"; shift 2 ;;
- --compress ) COMPRESS_OUTPUT="yes"; shift ;;
- --offline ) OFFLINE="1"; shift ;;
- --debug ) DEBUG="1"; shift ;;
- --magisk-custom ) CUSTOM_MAGISK="1"; shift ;;
- -- ) shift; break;;
- ? ) usage "$2"; shift ;;
- * ) break ;;
+ --arch ) ARCH="$2"; shift 2 ;;
+ --release-type ) RELEASE_TYPE="$2"; shift 2 ;;
+ --magisk-ver ) MAGISK_VER="$2"; shift 2 ;;
+ --gapps-brand ) GAPPS_BRAND="$2"; shift 2 ;;
+ --gapps-variant ) GAPPS_VARIANT="$2"; shift 2 ;;
+ --root-sol ) ROOT_SOL="$2"; shift 2 ;;
+ --remove-amazon ) REMOVE_AMAZON="remove"; shift ;;
+ --compress ) COMPRESS_OUTPUT="yes"; shift ;;
+ --offline ) OFFLINE="on"; shift ;;
+ --magisk-custom ) CUSTOM_MAGISK="debug"; MAGISK_VER=$CUSTOM_MAGISK shift ;;
+ --debug ) DEBUG="on"; shift ;;
+ --help ) usage; shift ;;
+ -- ) shift; break;;
+ ? ) usage "$2"; break ;;
esac
done
-declare -A PARA_CHECK_LIST=([ARCH]="$ARCH" [RELEASE_TYPE]="$RELEASE_TYPE" [MAGISK_VER]="$MAGISK_VER" [GAPPS_VARIANT]="$GAPPS_VARIANT" [REMOVE_AMAZON]="$REMOVE_AMAZON" [ROOT_SOL]="$ROOT_SOL")
-for i in "${PARA_CHECK_LIST[@]}";
-do
- if [ -z "$i" ]; then
+declare -A PARA_CHECK_LIST=([ARCH]="$ARCH" [RELEASE_TYPE]="$RELEASE_TYPE" [MAGISK_VER]="$MAGISK_VER" [GAPPS_VARIANT]="$GAPPS_VARIANT" [ROOT_SOL]="$ROOT_SOL")
+for i in "${PARA_CHECK_LIST[@]}"; do
+ if [ -z "${i+x}" ]; then
usage
fi
done
-echo -e "build: 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 -e "build: ARCH=$ARCH\nRELEASE_TYPE=$RELEASE_TYPE\nMAGISK_VER=$MAGISK_VER\nGAPPS_VARIANT=$GAPPS_VARIANT\nROOT_SOL=$ROOT_SOL"
declare -A RELEASE_TYPE_MAP=(["retail"]="Retail" ["release preview"]="RP" ["insider slow"]="WIS" ["insider fast"]="WIF")
WSA_ZIP_PATH=$DOWNLOAD_DIR/wsa-$ARCH-${RELEASE_TYPE_MAP[$RELEASE_TYPE]}.zip
-vclibs_PATH=vclibs-"$ARCH".appx
-xaml_PATH=xaml-"$ARCH".appx
+vclibs_PATH=$DOWNLOAD_DIR/vclibs-"$ARCH".appx
+xaml_PATH=$DOWNLOAD_DIR/xaml-"$ARCH".appx
MAGISK_PATH=$DOWNLOAD_DIR/magisk-$MAGISK_VER.zip
if [ "$GAPPS_BRAND" = "OpenGApps" ]; then
GAPPS_PATH="$DOWNLOAD_DIR"/OpenGApps-$ARCH-$GAPPS_VARIANT.zip
@@ -167,11 +174,11 @@ else
GAPPS_PATH="$DOWNLOAD_DIR"/MindTheGapps-"$ARCH".zip
fi
-if [ "$OFFLINE" != "1" ]; then
+if [ -z "${OFFLINE+x}" ]; then
trap 'rm -f -- "${DOWNLOAD_DIR:?}/${DOWNLOAD_CONF_NAME}"' EXIT
echo "Generate Download Links"
python3 generateWSALinks.py "$ARCH" "$RELEASE_TYPE" "$DOWNLOAD_DIR" "$DOWNLOAD_CONF_NAME" || abort
- if [ "$CUSTOM_MAGISK" != "1" ]; then
+ if [ -z "${CUSTOM_MAGISK+x}" ]; then
python3 generateMagiskLink.py "$MAGISK_VER" "$DOWNLOAD_DIR" "$DOWNLOAD_CONF_NAME" || abort
fi
if [ "$GAPPS_VARIANT" != 'none' ] && [ "$GAPPS_VARIANT" != '' ]; then
@@ -186,21 +193,20 @@ if [ "$OFFLINE" != "1" ]; then
exit 1
fi
else
- if [ ! -f "$WSA_ZIP_PATH" ] || [ ! -f "$xaml_PATH" ] || [ ! -f "$vclibs_PATH" ]; then
- echo "Offline mode: missing WSA files."
- OFFLINE_ERR="1"
- fi
- if [ ! -f "$MAGISK_PATH" ]; then
- echo "Offline mode: missing Magisk $MAGISK_VER file."
- OFFLINE_ERR="1"
- fi
+ declare -A FILES_CHECK_LIST=([WSA_ZIP_PATH]="$WSA_ZIP_PATH" [xaml_PATH]="$xaml_PATH" [vclibs_PATH]="$vclibs_PATH" [MAGISK_PATH]="$MAGISK_PATH")
+ for i in "${FILES_CHECK_LIST[@]}"; do
+ if [ ! -f "$i" ]; then
+ echo "Offline mode: missing [$i]."
+ OFFLINE_ERR="1"
+ fi
+ done
if [ "$GAPPS_VARIANT" != 'none' ] && [ "$GAPPS_VARIANT" != '' ]; then
if [ ! -f "$GAPPS_PATH" ]; then
- echo "Offline mode: missing $GAPPS_BRAND file."
+ echo "Offline mode: missing [$GAPPS_PATH]."
OFFLINE_ERR="1"
fi
fi
- if [ -n "$OFFLINE_ERR" ]; then
+ if [ "$OFFLINE_ERR" ]; then
echo "Offline mode: Some files are missing, please disable offline mode."
exit 1
fi
@@ -231,7 +237,7 @@ if [ -f "$MAGISK_PATH" ]; then
CLEAN_DOWNLOAD_MAGISK=1
abort
fi
-elif [ "$CUSTOM_MAGISK" != "1" ]; then
+elif [ -z "${CUSTOM_MAGISK+x}" ]; then
echo "The Magisk zip package does not exist, is the download incomplete?"
exit 1
else
@@ -318,7 +324,7 @@ sudo mount -o loop "$WORK_DIR"/wsa/"$ARCH"/product.img "$MOUNT_DIR"/product || a
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
+if [ "$REMOVE_AMAZON" ]; 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"
@@ -531,7 +537,7 @@ 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_PATH" "$DOWNLOAD_DIR"/"$xaml_PATH" "$WORK_DIR"/wsa/"$ARCH" || abort
+cp "$vclibs_PATH" "$xaml_PATH" "$WORK_DIR"/wsa/"$ARCH" || abort
tee "$WORK_DIR"/wsa/"$ARCH"/Install.ps1 <&2
exit 1
@@ -68,7 +69,8 @@ RELEASE_TYPE=$(
'insider slow' "Beta Channel" 'off' \
'insider fast' "Dev Channel" 'off'
)
-if [ "$CUSTOM_MAGISK" != "1" ]; then
+
+if [ -z "${CUSTOM_MAGISK+x}" ]; then
MAGISK_VER=$(
Radiolist '([title]="Magisk version"
[default]="stable")' \
From 73cb428d1bb97b36c701e3631ff06c80abb88721 Mon Sep 17 00:00:00 2001
From: Howard Wu <40033067+Howard20181@users.noreply.github.com>
Date: Tue, 30 Aug 2022 23:47:09 +0800
Subject: [PATCH 06/10] Check input
---
scripts/build.sh | 99 +++++++++++++++++++++++++++++++------
scripts/generateWSALinks.py | 9 ++--
2 files changed, 88 insertions(+), 20 deletions(-)
diff --git a/scripts/build.sh b/scripts/build.sh
index 04780d6..10b487a 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -47,8 +47,10 @@ umount_clean(){
sudo umount "$MOUNT_DIR"/system_ext
fi
sudo umount "$MOUNT_DIR"
+ sudo rm -rf "${WORK_DIR:?}"
+ else
+ rm -rf "${WORK_DIR:?}"
fi
- sudo rm -rf "${WORK_DIR:?}"
}
clean_download(){
if [ -d "$DOWNLOAD_DIR" ]; then
@@ -91,22 +93,22 @@ default(){
usage(){
default
if [ "$1" ]; then
- echo "Unknown parameter: $1"
+ echo "ERROR: $1"
fi
echo "Usage:
--arch Architecture of WSA, x64 or arm64, default: $ARCH
- --release-type Release type of WSA, retail or debug, default: $RELEASE_TYPE
+ --release-type Release type of WSA, retail, RP (Release Preview), WIS (Insider Slow) or WIF (Insider Fast), default: $RELEASE_TYPE
--magisk-ver Magisk version, stable or canary, default: $MAGISK_VER
--gapps-brand GApps brand, OpenGApps or MindTheGApps, default: $GAPPS_BRAND
--gapps-variant GApps variant, pico or full, etc...., default: $GAPPS_VARIANT
- --root-sol Root solution, magisk or null, default: $ROOT_SOL
+ --root-sol Root solution, magisk or none, default: $ROOT_SOL
--remove-amazon Remove Amazon from the system, default: false
--compress Compress the WSA, default: false
--offline Build WSA offline, default: false
--magisk-custom Install custom Magisk, default: false
--debug Debug build mode, default: false
"
- exit 1
+ abort
}
ARGUMENT_LIST=(
@@ -131,7 +133,7 @@ opts=$(getopt \
--name "$(basename "$0")" \
--options "" \
-- "$@"
-)
+) || abort
eval set --"$opts"
while [[ $# -gt 0 ]]; do
@@ -149,22 +151,87 @@ while [[ $# -gt 0 ]]; do
--debug ) DEBUG="on"; shift ;;
--help ) usage; shift ;;
-- ) shift; break;;
- ? ) usage "$2"; break ;;
+ ? ) usage "Unknown parameter: $2"; break ;;
esac
done
-declare -A PARA_CHECK_LIST=([ARCH]="$ARCH" [RELEASE_TYPE]="$RELEASE_TYPE" [MAGISK_VER]="$MAGISK_VER" [GAPPS_VARIANT]="$GAPPS_VARIANT" [ROOT_SOL]="$ROOT_SOL")
-for i in "${PARA_CHECK_LIST[@]}"; do
- if [ -z "${i+x}" ]; then
- usage
- fi
-done
+ARCH_MAP=(
+ "x64"
+ "arm64"
+)
-echo -e "build: ARCH=$ARCH\nRELEASE_TYPE=$RELEASE_TYPE\nMAGISK_VER=$MAGISK_VER\nGAPPS_VARIANT=$GAPPS_VARIANT\nROOT_SOL=$ROOT_SOL"
+RELEASE_TYPE_MAP=(
+ "retail"
+ "RP"
+ "WIS"
+ "WIF"
+)
-declare -A RELEASE_TYPE_MAP=(["retail"]="Retail" ["release preview"]="RP" ["insider slow"]="WIS" ["insider fast"]="WIF")
+MAGISK_VER_MAP=(
+ "stable"
+ "beta"
+ "canary"
+ "debug"
+)
-WSA_ZIP_PATH=$DOWNLOAD_DIR/wsa-$ARCH-${RELEASE_TYPE_MAP[$RELEASE_TYPE]}.zip
+GAPPS_BRAND_MAP=(
+ "OpenGApps"
+ "MindTheGApps"
+)
+
+GAPPS_VARIANT_MAP=(
+ "super"
+ "stock"
+ "full"
+ "mini"
+ "micro"
+ "nano"
+ "pico"
+ "tvstock"
+ "tvmini"
+)
+
+ROOT_SOL_MAP=(
+ "magisk"
+ "none"
+)
+
+check_list(){
+ local input=$1
+ local name=$2
+ shift
+ local arr=("$@")
+ local list_count=${#arr[@]}
+ for i in "${arr[@]}"; do
+ if [ "$input" == "$i" ]; then
+ break
+ fi
+ ((list_count--))
+ if (( "$list_count" <= 0 )); then
+ usage "Invalid $name: $input"
+ fi
+ done
+}
+
+check_list "$ARCH" "Architecture" "${ARCH_MAP[@]}"
+check_list "$RELEASE_TYPE" "Release Type" "${RELEASE_TYPE_MAP[@]}"
+check_list "$MAGISK_VER" "Magisk Version" "${MAGISK_VER_MAP[@]}"
+check_list "$GAPPS_BRAND" "GApps Brand" "${GAPPS_BRAND_MAP[@]}"
+check_list "$GAPPS_VARIANT" "GApps Variant" "${GAPPS_VARIANT_MAP[@]}"
+check_list "$ROOT_SOL" "Root Solution" "${ROOT_SOL_MAP[@]}"
+
+if [ "$DEBUG" ]; then
+ set -x
+fi
+
+declare -A RELEASE_NAME_MAP=(["retail"]="Retail" ["RP"]="Release Preview" ["WIS"]="Insider Slow" ["WIF"]="Insider Fast")
+RELEASE_NAME=${RELEASE_NAME_MAP[$RELEASE_TYPE]} || abort
+
+echo -e "build: ARCH=$ARCH\nRELEASE_TYPE=$RELEASE_NAME\nMAGISK_VER=$MAGISK_VER\nGAPPS_VARIANT=$GAPPS_VARIANT\nROOT_SOL=$ROOT_SOL"
+if [ "$(sudo whoami)" != "root" ]; then
+ sudo echo ""
+fi
+WSA_ZIP_PATH=$DOWNLOAD_DIR/wsa-$ARCH-$RELEASE_TYPE.zip
vclibs_PATH=$DOWNLOAD_DIR/vclibs-"$ARCH".appx
xaml_PATH=$DOWNLOAD_DIR/xaml-"$ARCH".appx
MAGISK_PATH=$DOWNLOAD_DIR/magisk-$MAGISK_VER.zip
diff --git a/scripts/generateWSALinks.py b/scripts/generateWSALinks.py
index 2c2038a..95ac2f9 100644
--- a/scripts/generateWSALinks.py
+++ b/scripts/generateWSALinks.py
@@ -32,13 +32,14 @@ warnings.filterwarnings("ignore")
arch = sys.argv[1]
-release_type_map = {"retail": "Retail", "release preview": "RP",
- "insider slow": "WIS", "insider fast": "WIF"}
-release_type = release_type_map[sys.argv[2]] if sys.argv[2] != "" else "Retail"
+release_name_map = {"retail": "Retail", "RP": "Release Preview",
+ "WIS": "Insider Slow", "WIF": "Insider Fast"}
+release_type = sys.argv[2] if sys.argv[2] != "" else "Retail"
+release_name = release_name_map[release_type]
download_dir = Path.cwd().parent / "download" if sys.argv[3] == "" else Path(sys.argv[3]).resolve()
tempScript = sys.argv[4]
cat_id = '858014f3-3934-4abe-8078-4aa193e74ca8'
-print(f"Generating WSA download link: arch={arch} release_type={release_type}", flush=True)
+print(f"Generating WSA download link: arch={arch} release_type={release_name}", flush=True)
with open(Path.cwd().parent / ("xml/GetCookie.xml"), "r") as f:
cookie_content = f.read()
From 5d608e3a8624f07eb85d9f3bc40aec1cb6dcb2f4 Mon Sep 17 00:00:00 2001
From: Howard Wu <40033067+Howard20181@users.noreply.github.com>
Date: Tue, 30 Aug 2022 23:57:26 +0800
Subject: [PATCH 07/10] Fix release type selector
---
scripts/build.sh | 1 -
scripts/run.sh | 4 ++--
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/scripts/build.sh b/scripts/build.sh
index 10b487a..372a1ec 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -151,7 +151,6 @@ while [[ $# -gt 0 ]]; do
--debug ) DEBUG="on"; shift ;;
--help ) usage; shift ;;
-- ) shift; break;;
- ? ) usage "Unknown parameter: $2"; break ;;
esac
done
diff --git a/scripts/run.sh b/scripts/run.sh
index 8ff1da8..0cf84dc 100755
--- a/scripts/run.sh
+++ b/scripts/run.sh
@@ -150,7 +150,7 @@ fi
# fi
# OFFLINE="--offline"
clear
-
-COMMAND_LINE=(--arch "$ARCH" --release-type "$RELEASE_TYPE" --magisk-ver "$MAGISK_VER" --gapps-brand "$GAPPS_BRAND" --gapps-variant "$GAPPS_VARIANT" "$REMOVE_AMAZON" --root-sol "$ROOT_SOL" "$COMPRESS_OUTPUT" "$OFFLINE" "$DEBUG" "$CUSTOM_MAGISK")
+declare -A RELEASE_TYPE_MAP=(["retail"]="retail" ["release preview"]="RP" ["insider slow"]="WIS" ["insider fast"]="WIF")
+COMMAND_LINE=(--arch "$ARCH" --release-type "${RELEASE_TYPE_MAP[$RELEASE_TYPE]}" --magisk-ver "$MAGISK_VER" --gapps-brand "$GAPPS_BRAND" --gapps-variant "$GAPPS_VARIANT" "$REMOVE_AMAZON" --root-sol "$ROOT_SOL" "$COMPRESS_OUTPUT" "$OFFLINE" "$DEBUG" "$CUSTOM_MAGISK")
echo "COMMAND_LINE=${COMMAND_LINE[*]}"
./build.sh "${COMMAND_LINE[@]}"
From c0fb8f1d2b5352219100eac7fa6be8bd73599a8a Mon Sep 17 00:00:00 2001
From: Howard Wu <40033067+Howard20181@users.noreply.github.com>
Date: Wed, 31 Aug 2022 00:23:41 +0800
Subject: [PATCH 08/10] Show help without reporting errors.
---
scripts/build.sh | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/scripts/build.sh b/scripts/build.sh
index 372a1ec..0eb46e8 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -94,6 +94,7 @@ usage(){
default
if [ "$1" ]; then
echo "ERROR: $1"
+ abort
fi
echo "Usage:
--arch Architecture of WSA, x64 or arm64, default: $ARCH
@@ -108,7 +109,7 @@ usage(){
--magisk-custom Install custom Magisk, default: false
--debug Debug build mode, default: false
"
- abort
+ exit 0
}
ARGUMENT_LIST=(
From cfe108f47c80140d7536c9a5f3ba4654d11c38f6 Mon Sep 17 00:00:00 2001
From: Howard Wu <40033067+Howard20181@users.noreply.github.com>
Date: Wed, 31 Aug 2022 00:50:21 +0800
Subject: [PATCH 09/10] Fix custom Magisk install
---
scripts/build.sh | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/scripts/build.sh b/scripts/build.sh
index 0eb46e8..280fb8a 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -35,8 +35,8 @@ DOWNLOAD_CONF_NAME=download.list
OUTPUT_DIR=../output
MOUNT_DIR="$WORK_DIR"/system
umount_clean(){
- echo "Cleanup Work Directory"
if [ -d "$MOUNT_DIR" ]; then
+ echo "Cleanup Work Directory"
if [ -d "$MOUNT_DIR/vendor" ]; then
sudo umount "$MOUNT_DIR"/vendor
fi
@@ -90,12 +90,14 @@ default(){
ROOT_SOL=magisk
}
+exit_with_message(){
+ echo "ERROR: $1"
+ usage
+ abort
+}
+
usage(){
default
- if [ "$1" ]; then
- echo "ERROR: $1"
- abort
- fi
echo "Usage:
--arch Architecture of WSA, x64 or arm64, default: $ARCH
--release-type Release type of WSA, retail, RP (Release Preview), WIS (Insider Slow) or WIF (Insider Fast), default: $RELEASE_TYPE
@@ -108,8 +110,12 @@ usage(){
--offline Build WSA offline, default: false
--magisk-custom Install custom Magisk, default: false
--debug Debug build mode, default: false
+ --help Show this help message and exit
+
+ Example:
+ ./build.sh --arch x64 --release-type retail --magisk-ver stable --gapps-brand OpenGApps --gapps-variant pico --remove-amazon
+ ./build.sh --arch x64 --release-type retail --remove-amazon --magisk-custom --offline
"
- exit 0
}
ARGUMENT_LIST=(
@@ -148,9 +154,9 @@ while [[ $# -gt 0 ]]; do
--remove-amazon ) REMOVE_AMAZON="remove"; shift ;;
--compress ) COMPRESS_OUTPUT="yes"; shift ;;
--offline ) OFFLINE="on"; shift ;;
- --magisk-custom ) CUSTOM_MAGISK="debug"; MAGISK_VER=$CUSTOM_MAGISK shift ;;
+ --magisk-custom ) CUSTOM_MAGISK="debug"; MAGISK_VER=$CUSTOM_MAGISK; shift ;;
--debug ) DEBUG="on"; shift ;;
- --help ) usage; shift ;;
+ --help ) usage; exit 0 ;;
-- ) shift; break;;
esac
done
@@ -208,7 +214,7 @@ check_list(){
fi
((list_count--))
if (( "$list_count" <= 0 )); then
- usage "Invalid $name: $input"
+ exit_with_message "Invalid $name: $input"
fi
done
}
From 9908c9a90961a5e4d0ef9905a1cc8e82b2fac6c6 Mon Sep 17 00:00:00 2001
From: Howard Wu <40033067+Howard20181@users.noreply.github.com>
Date: Wed, 31 Aug 2022 01:10:20 +0800
Subject: [PATCH 10/10] Check if custom Magisk exists
---
scripts/build.sh | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/scripts/build.sh b/scripts/build.sh
index 280fb8a..7f8c7c2 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -234,19 +234,25 @@ declare -A RELEASE_NAME_MAP=(["retail"]="Retail" ["RP"]="Release Preview" ["WIS"
RELEASE_NAME=${RELEASE_NAME_MAP[$RELEASE_TYPE]} || abort
echo -e "build: ARCH=$ARCH\nRELEASE_TYPE=$RELEASE_NAME\nMAGISK_VER=$MAGISK_VER\nGAPPS_VARIANT=$GAPPS_VARIANT\nROOT_SOL=$ROOT_SOL"
-if [ "$(sudo whoami)" != "root" ]; then
- sudo echo ""
-fi
+
WSA_ZIP_PATH=$DOWNLOAD_DIR/wsa-$ARCH-$RELEASE_TYPE.zip
vclibs_PATH=$DOWNLOAD_DIR/vclibs-"$ARCH".appx
xaml_PATH=$DOWNLOAD_DIR/xaml-"$ARCH".appx
MAGISK_PATH=$DOWNLOAD_DIR/magisk-$MAGISK_VER.zip
+if [ "$CUSTOM_MAGISK" ]; then
+ if [ ! -f "$MAGISK_PATH" ]; then
+ echo "Custom Magisk not found, please rename it to magisk-debug.zip and put it in $DOWNLOAD_DIR"
+ abort
+ fi
+fi
if [ "$GAPPS_BRAND" = "OpenGApps" ]; then
GAPPS_PATH="$DOWNLOAD_DIR"/OpenGApps-$ARCH-$GAPPS_VARIANT.zip
else
GAPPS_PATH="$DOWNLOAD_DIR"/MindTheGapps-"$ARCH".zip
fi
-
+if [ "$(sudo whoami)" != "root" ]; then
+ sudo echo "sudo is required to run this script"
+fi
if [ -z "${OFFLINE+x}" ]; then
trap 'rm -f -- "${DOWNLOAD_DIR:?}/${DOWNLOAD_CONF_NAME}"' EXIT
echo "Generate Download Links"