2022-08-29 20:03:07 +02:00
#!/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 <https://www.gnu.org/licenses/>.
#
# Copyright (C) 2022 LSPosed Contributors
#
2022-09-03 18:43:31 +02:00
if [ ! " $BASH_VERSION " ] ; then
2022-08-29 20:03:07 +02:00
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
2022-09-10 08:58:18 +02:00
# export TMPDIR=$(dirname "$PWD")/WORK_DIR_
2022-09-07 13:53:36 +02:00
if [ " $TMPDIR " ] && [ ! -d " $TMPDIR " ] ; then
mkdir -p " $TMPDIR "
fi
2022-08-29 20:03:07 +02:00
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
2022-09-23 00:27:11 +02:00
SUDO = " $( which sudo 2>/dev/null) "
2022-09-23 10:31:12 +02:00
if [ -z " $SUDO " ] ; then
unset SUDO
fi
2022-12-08 09:06:23 +01:00
WSA_WORK_ENV = " ${ WORK_DIR : ? } " /ENV
if [ -f " $WSA_WORK_ENV " ] ; then rm -f " ${ WSA_WORK_ENV : ? } " ; fi
touch " $WSA_WORK_ENV "
export WSA_WORK_ENV
2022-09-03 18:43:31 +02:00
umount_clean( ) {
2022-08-29 20:03:07 +02:00
if [ -d " $MOUNT_DIR " ] ; then
2022-08-30 18:50:21 +02:00
echo "Cleanup Work Directory"
2022-08-29 20:03:07 +02:00
if [ -d " $MOUNT_DIR /vendor " ] ; then
2022-09-23 00:27:11 +02:00
$SUDO umount " $MOUNT_DIR " /vendor
2022-08-29 20:03:07 +02:00
fi
if [ -d " $MOUNT_DIR /product " ] ; then
2022-09-23 00:27:11 +02:00
$SUDO umount " $MOUNT_DIR " /product
2022-08-29 20:03:07 +02:00
fi
if [ -d " $MOUNT_DIR /system_ext " ] ; then
2022-09-23 00:27:11 +02:00
$SUDO umount " $MOUNT_DIR " /system_ext
2022-08-29 20:03:07 +02:00
fi
2022-09-23 00:27:11 +02:00
$SUDO umount " $MOUNT_DIR "
$SUDO rm -rf " ${ WORK_DIR : ? } "
2022-08-30 17:47:09 +02:00
else
rm -rf " ${ WORK_DIR : ? } "
2022-08-29 20:03:07 +02:00
fi
2022-09-07 13:53:36 +02:00
if [ " $TMPDIR " ] && [ -d " $TMPDIR " ] ; then
rm -rf " ${ TMPDIR : ? } "
unset TMPDIR
fi
2022-08-29 20:03:07 +02:00
}
2022-09-03 18:43:31 +02:00
clean_download( ) {
2022-08-29 20:03:07 +02:00
if [ -d " $DOWNLOAD_DIR " ] ; then
echo "Cleanup Download Directory"
2022-08-30 15:59:26 +02:00
if [ " $CLEAN_DOWNLOAD_WSA " ] ; then
2022-08-29 20:03:07 +02:00
rm -f " ${ WSA_ZIP_PATH : ? } "
fi
2022-08-30 15:59:26 +02:00
if [ " $CLEAN_DOWNLOAD_MAGISK " ] ; then
2022-08-29 20:03:07 +02:00
rm -f " ${ MAGISK_PATH : ? } "
fi
2022-08-30 15:59:26 +02:00
if [ " $CLEAN_DOWNLOAD_GAPPS " ] ; then
2022-08-29 20:03:07 +02:00
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
2022-12-08 09:06:23 +01:00
Gen_Rand_Str( ) {
2022-08-30 01:42:11 +02:00
head /dev/urandom | tr -dc A-Za-z0-9 | head -c" $1 "
2022-08-29 20:03:07 +02:00
}
2022-09-03 18:43:31 +02:00
default( ) {
2022-08-30 15:59:26 +02:00
ARCH = x64
RELEASE_TYPE = retail
MAGISK_VER = stable
2022-09-10 09:02:46 +02:00
GAPPS_BRAND = MindTheGapps
2022-08-30 15:59:26 +02:00
GAPPS_VARIANT = pico
ROOT_SOL = magisk
}
2022-09-03 18:43:31 +02:00
exit_with_message( ) {
2022-08-30 18:50:21 +02:00
echo " ERROR: $1 "
usage
2022-09-03 06:24:28 +02:00
exit 1
2022-08-29 20:03:07 +02:00
}
2022-08-30 17:47:09 +02:00
ARCH_MAP = (
"x64"
"arm64"
)
RELEASE_TYPE_MAP = (
"retail"
"RP"
"WIS"
"WIF"
)
MAGISK_VER_MAP = (
"stable"
"beta"
"canary"
"debug"
2022-10-26 16:14:59 +02:00
"release"
2022-08-30 17:47:09 +02:00
)
GAPPS_BRAND_MAP = (
"OpenGApps"
2022-09-03 18:32:32 +02:00
"MindTheGapps"
2022-09-01 04:40:35 +02:00
"none"
2022-08-30 17:47:09 +02:00
)
2022-08-29 10:29:54 +02:00
2022-08-30 17:47:09 +02:00
GAPPS_VARIANT_MAP = (
"super"
"stock"
"full"
"mini"
"micro"
"nano"
"pico"
"tvstock"
"tvmini"
)
ROOT_SOL_MAP = (
"magisk"
"none"
)
2022-10-21 19:03:02 +02:00
COMPRESS_FORMAT_MAP = (
"7z"
"xz"
2022-10-22 12:30:46 +02:00
"zip"
2022-10-21 19:03:02 +02:00
)
2022-09-03 18:43:31 +02:00
ARR_TO_STR( ) {
2022-09-03 18:32:32 +02:00
local arr = ( " $@ " )
local joined
2022-09-03 18:43:31 +02:00
printf -v joined "%s, " " ${ arr [@] } "
2022-09-03 18:32:32 +02:00
echo " ${ joined %, } "
}
2022-11-15 02:07:29 +01:00
GAPPS_PROPS_MSG1 = "\033[0;31mWARNING: Services such as the Play Store may stop working properly."
GAPPS_PROPS_MSG2 = "We are not responsible for any problems caused by this!\033[0m"
GAPPS_PROPS_MSG3 = "Info: https://support.google.com/android/answer/10248227"
2022-09-03 18:43:31 +02:00
usage( ) {
2022-08-30 15:59:26 +02:00
default
2022-11-15 02:07:29 +01:00
echo -e "
Usage:
2022-12-09 11:10:28 +01:00
--arch Architecture of WSA.
2022-09-03 18:32:32 +02:00
2022-12-09 11:10:28 +01:00
Possible values: $( ARR_TO_STR " ${ ARCH_MAP [@] } " )
Default: $ARCH
2022-09-03 18:32:32 +02:00
2022-12-09 11:10:28 +01:00
--release-type Release type of WSA.
RP means Release Preview, WIS means Insider Slow, WIF means Insider Fast.
2022-09-03 18:32:32 +02:00
2022-12-09 11:10:28 +01:00
Possible values: $( ARR_TO_STR " ${ RELEASE_TYPE_MAP [@] } " )
Default: $RELEASE_TYPE
2022-09-03 18:32:32 +02:00
2022-12-09 11:10:28 +01:00
--magisk-ver Magisk version.
2022-09-03 18:32:32 +02:00
2022-12-09 11:10:28 +01:00
Possible values: $( ARR_TO_STR " ${ MAGISK_VER_MAP [@] } " )
Default: $MAGISK_VER
2022-09-03 18:32:32 +02:00
2022-12-09 11:10:28 +01:00
--gapps-brand GApps brand.
\" none\" for no integration of GApps
2022-09-03 18:32:32 +02:00
2022-12-09 11:10:28 +01:00
Possible values: $( ARR_TO_STR " ${ GAPPS_BRAND_MAP [@] } " )
Default: $GAPPS_BRAND
2022-09-03 18:32:32 +02:00
2022-12-09 11:10:28 +01:00
--gapps-variant GApps variant.
2022-09-03 18:32:32 +02:00
2022-12-09 11:10:28 +01:00
Possible values: $( ARR_TO_STR " ${ GAPPS_VARIANT_MAP [@] } " )
Default: $GAPPS_VARIANT
2022-09-03 18:32:32 +02:00
2022-12-09 11:10:28 +01:00
--root-sol Root solution.
\" none\" means no root.
2022-09-03 18:32:32 +02:00
2022-12-09 11:10:28 +01:00
Possible values: $( ARR_TO_STR " ${ ROOT_SOL_MAP [@] } " )
Default: $ROOT_SOL
2022-09-03 18:32:32 +02:00
2022-10-21 19:03:02 +02:00
--compress-format
2022-12-09 11:10:28 +01:00
Compress format of output file.
If this option is not specified and --compress is not specified, the generated file will not be compressed
2022-10-21 19:03:02 +02:00
2022-12-09 11:10:28 +01:00
Possible values: $( ARR_TO_STR " ${ COMPRESS_FORMAT_MAP [@] } " )
2022-10-21 19:03:02 +02:00
2022-09-03 18:32:32 +02:00
Additional Options:
2022-12-09 11:10:28 +01:00
--remove-amazon Remove Amazon Appstore from the system
--compress Compress the WSA, The default format is 7z, you can use the format specified by --compress-format
--offline Build WSA offline
--magisk-custom Install custom Magisk
--skip-download-wsa Skip download WSA
--debug Debug build mode
--help Show this help message and exit
--nofix-props No fix \" build.prop\"
$GAPPS_PROPS_MSG1
$GAPPS_PROPS_MSG2
$GAPPS_PROPS_MSG3
2022-09-03 18:32:32 +02:00
2022-09-03 18:43:31 +02:00
Example:
2022-09-03 18:32:32 +02:00
./build.sh --release-type RP --magisk-ver beta --gapps-variant pico --remove-amazon
2022-11-15 02:10:25 +01:00
./build.sh --arch arm64 --release-type WIF --gapps-brand OpenGApps --nofix-props
2022-09-03 18:32:32 +02:00
./build.sh --release-type WIS --gapps-brand none
./build.sh --offline --gapps-variant pico --magisk-custom
2022-08-29 10:29:54 +02:00
"
}
ARGUMENT_LIST = (
2022-09-03 18:43:31 +02:00
"arch:"
"release-type:"
"magisk-ver:"
"gapps-brand:"
"gapps-variant:"
2022-11-15 02:07:29 +01:00
"nofix-props"
2022-09-03 18:43:31 +02:00
"root-sol:"
2022-10-21 19:03:02 +02:00
"compress-format:"
2022-09-03 18:43:31 +02:00
"remove-amazon"
"compress"
"offline"
"magisk-custom"
"debug"
"help"
2022-12-09 11:10:28 +01:00
"skip-download-wsa"
2022-08-29 10:29:54 +02:00
)
2022-08-29 20:03:07 +02:00
2022-08-30 15:59:26 +02:00
default
2022-09-03 18:43:31 +02:00
opts = $(
getopt \
--longoptions " $( printf "%s," " ${ ARGUMENT_LIST [@] } " ) " \
--name " $( basename " $0 " ) " \
--options "" \
-- " $@ "
2022-09-01 04:55:19 +02:00
) || exit_with_message "Failed to parse options, please check your input"
2022-08-29 10:29:54 +02:00
eval set --" $opts "
while [ [ $# -gt 0 ] ] ; do
case " $1 " in
2022-12-09 11:10:28 +01:00
--arch ) ARCH = " $2 " ; shift 2 ; ;
--release-type ) RELEASE_TYPE = " $2 " ; shift 2 ; ;
--gapps-brand ) GAPPS_BRAND = " $2 " ; shift 2 ; ;
--gapps-variant ) GAPPS_VARIANT = " $2 " ; shift 2 ; ;
--nofix-props ) NOFIX_PROPS = "yes" ; shift ; ;
--root-sol ) ROOT_SOL = " $2 " ; shift 2 ; ;
--compress-format ) COMPRESS_FORMAT = " $2 " ; shift 2 ; ;
--remove-amazon ) REMOVE_AMAZON = "yes" ; shift ; ;
--compress ) COMPRESS_OUTPUT = "yes" ; shift ; ;
--offline ) OFFLINE = "on" ; shift ; ;
--magisk-custom ) CUSTOM_MAGISK = "debug" ; shift ; ;
--magisk-ver ) MAGISK_VER = " $2 " ; shift 2 ; ;
--debug ) DEBUG = "on" ; shift ; ;
--skip-download-wsa ) DOWN_WSA = "no" ; shift ; ;
--help ) usage; exit 0 ; ;
-- ) shift; break; ;
2022-08-29 10:29:54 +02:00
esac
done
2022-11-11 08:40:54 +01:00
if [ " $CUSTOM_MAGISK " ] ; then
if [ -z " $MAGISK_VER " ] ; then
MAGISK_VER = $CUSTOM_MAGISK
fi
fi
2022-09-03 18:43:31 +02:00
check_list( ) {
2022-08-30 17:47:09 +02:00
local input = $1
2022-10-21 19:03:02 +02:00
if [ -n " $input " ] ; then
local name = $2
shift
local arr = ( " $@ " )
local list_count = ${# arr [@] }
for i in " ${ arr [@] } " ; do
if [ " $input " = = " $i " ] ; then
echo " INFO: $name : $input "
break
fi
( ( list_count--) )
if ( ( " $list_count " <= 0) ) ; then
exit_with_message " Invalid $name : $input "
fi
done
fi
2022-08-30 17:47:09 +02:00
}
2022-08-29 20:03:07 +02:00
2022-08-30 17:47:09 +02:00
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 [@] } "
2022-10-21 19:03:02 +02:00
check_list " $COMPRESS_FORMAT " "Compress Format" " ${ COMPRESS_FORMAT_MAP [@] } "
2022-08-29 20:03:07 +02:00
2022-08-30 17:47:09 +02:00
if [ " $DEBUG " ] ; then
set -x
fi
2022-09-17 15:23:18 +02:00
require_su( ) {
2022-09-23 10:31:12 +02:00
if test " $( whoami) " != "root" ; then
2022-09-23 10:43:50 +02:00
if [ -z " $SUDO " ] || [ " $( $SUDO whoami) " != "root" ] ; then
2022-09-23 10:31:12 +02:00
echo "ROOT/SUDO is required to run this script"
abort
fi
2022-09-17 15:23:18 +02:00
fi
}
2022-08-30 17:47:09 +02:00
declare -A RELEASE_NAME_MAP = ( [ "retail" ] = "Retail" [ "RP" ] = "Release Preview" [ "WIS" ] = "Insider Slow" [ "WIF" ] = "Insider Fast" )
2022-12-08 09:06:23 +01:00
declare -A ANDROID_API_MAP = ( [ "30" ] = "11.0" [ "32" ] = "12.1" [ "33" ] = "13.0" )
2022-08-30 17:47:09 +02:00
RELEASE_NAME = ${ RELEASE_NAME_MAP [ $RELEASE_TYPE ] } || abort
2022-09-23 10:31:12 +02:00
echo -e " Build: RELEASE_TYPE= $RELEASE_NAME "
2022-08-30 19:10:20 +02:00
2022-11-23 09:10:41 +01:00
WSA_ZIP_PATH = $DOWNLOAD_DIR /wsa-$RELEASE_TYPE .zip
2022-10-05 15:47:46 +02:00
vclibs_PATH = $DOWNLOAD_DIR /Microsoft.VCLibs." $ARCH " .14.00.Desktop.appx
xaml_PATH = $DOWNLOAD_DIR /Microsoft.UI.Xaml_" $ARCH " .appx
2022-10-26 16:14:59 +02:00
MAGISK_ZIP = magisk-$MAGISK_VER .zip
MAGISK_PATH = $DOWNLOAD_DIR /$MAGISK_ZIP
2022-08-30 19:10:20 +02:00
if [ " $CUSTOM_MAGISK " ] ; then
if [ ! -f " $MAGISK_PATH " ] ; then
2022-10-26 16:14:59 +02:00
echo " Custom Magisk $MAGISK_ZIP not found "
MAGISK_ZIP = app-$MAGISK_VER .apk
echo " Fallback to $MAGISK_ZIP "
MAGISK_PATH = $DOWNLOAD_DIR /$MAGISK_ZIP
if [ ! -f " $MAGISK_PATH " ] ; then
echo -e " Custom Magisk $MAGISK_ZIP not found\nPlease put custom Magisk in $DOWNLOAD_DIR "
abort
fi
2022-08-30 19:10:20 +02:00
fi
fi
2022-12-08 09:06:23 +01:00
ANDROID_API = 32
update_gapps_zip_name( ) {
if [ " $GAPPS_BRAND " = "OpenGApps" ] ; then
2022-12-10 00:18:19 +01:00
# TODO: keep it 11.0 since official opengapps does not support 12+ yet
# As soon as opengapps is available for 12+, we need to get the sdk/release from build.prop and download the corresponding version
2022-12-08 09:06:23 +01:00
ANDROID_API = 30
GAPPS_ZIP_NAME = " $GAPPS_BRAND - $ARCH - ${ ANDROID_API_MAP [ $ANDROID_API ] } - $GAPPS_VARIANT " .zip
else
GAPPS_ZIP_NAME = " $GAPPS_BRAND - $ARCH - ${ ANDROID_API_MAP [ $ANDROID_API ] } " .zip
fi
GAPPS_PATH = $DOWNLOAD_DIR /$GAPPS_ZIP_NAME
}
update_gapps_zip_name
2022-08-30 15:59:26 +02:00
if [ -z " ${ OFFLINE +x } " ] ; then
2022-08-29 20:03:07 +02:00
trap 'rm -f -- "${DOWNLOAD_DIR:?}/${DOWNLOAD_CONF_NAME}"' EXIT
2022-09-17 15:23:18 +02:00
require_su
2022-12-09 11:10:28 +01:00
if [ " ${ DOWN_WSA } " != "no" ] ; then
echo "Generate Download Links"
python3 generateWSALinks.py " $ARCH " " $RELEASE_TYPE " " $DOWNLOAD_DIR " " $DOWNLOAD_CONF_NAME " || abort
# shellcheck disable=SC1091
source " ${ WORK_DIR : ? } /ENV " || abort
else
DOWN_WSA_MAIN_VERSION = 2211
fi
2022-12-08 09:06:23 +01:00
if [ [ " $DOWN_WSA_MAIN_VERSION " -ge 2211 ] ] ; then
ANDROID_API = 33
update_gapps_zip_name
fi
2022-08-30 15:59:26 +02:00
if [ -z " ${ CUSTOM_MAGISK +x } " ] ; then
2022-08-29 20:03:07 +02:00
python3 generateMagiskLink.py " $MAGISK_VER " " $DOWNLOAD_DIR " " $DOWNLOAD_CONF_NAME " || abort
fi
2022-09-10 08:40:21 +02:00
if [ " $GAPPS_BRAND " != "none" ] ; then
2022-12-08 09:06:23 +01:00
python3 generateGappsLink.py " $ARCH " " $GAPPS_BRAND " " $GAPPS_VARIANT " " $DOWNLOAD_DIR " " $DOWNLOAD_CONF_NAME " " $ANDROID_API " " $GAPPS_ZIP_NAME " || abort
2022-08-29 20:03:07 +02:00
fi
echo "Download Artifacts"
2022-09-03 15:50:35 +02:00
if ! aria2c --no-conf --log-level= info --log= " $DOWNLOAD_DIR /aria2_download.log " -x16 -s16 -j5 -c -R -m0 --async-dns= false --check-integrity= true --continue= true --allow-overwrite= true --conditional-get= true -d" $DOWNLOAD_DIR " -i" $DOWNLOAD_DIR " /" $DOWNLOAD_CONF_NAME " ; then
2022-08-29 20:03:07 +02:00
echo "We have encountered an error while downloading files."
exit 1
fi
else
2022-08-30 15:59:26 +02:00
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
2022-09-03 17:44:52 +02:00
if [ " $GAPPS_BRAND " != 'none' ] ; then
2022-08-29 20:03:07 +02:00
if [ ! -f " $GAPPS_PATH " ] ; then
2022-08-30 15:59:26 +02:00
echo " Offline mode: missing [ $GAPPS_PATH ]. "
2022-08-29 20:03:07 +02:00
OFFLINE_ERR = "1"
fi
fi
2022-08-30 15:59:26 +02:00
if [ " $OFFLINE_ERR " ] ; then
2022-08-29 20:03:07 +02:00
echo "Offline mode: Some files are missing, please disable offline mode."
exit 1
fi
2022-09-17 15:23:18 +02:00
require_su
2022-08-29 20:03:07 +02:00
fi
echo "Extract WSA"
if [ -f " $WSA_ZIP_PATH " ] ; then
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
2022-12-08 09:06:23 +01:00
if [ [ " $WSA_MAIN_VER " -ge 2211 ] ] ; then
ANDROID_API = 33
update_gapps_zip_name
fi
2022-08-29 20:03:07 +02:00
else
echo "The WSA zip package does not exist, is the download incomplete?"
exit 1
fi
2022-09-17 15:15:44 +02:00
echo "Extract Magisk"
2022-08-29 20:03:07 +02:00
if [ -f " $MAGISK_PATH " ] ; then
2022-12-09 11:10:28 +01:00
version = ""
versionCode = 0
2022-08-29 20:03:07 +02:00
if ! python3 extractMagisk.py " $ARCH " " $MAGISK_PATH " " $WORK_DIR " ; then
echo "Unzip Magisk failed, is the download incomplete?"
CLEAN_DOWNLOAD_MAGISK = 1
abort
fi
2022-12-09 11:10:28 +01:00
# shellcheck disable=SC1091
2022-12-09 10:21:29 +01:00
source " ${ WORK_DIR : ? } /ENV " || abort
2022-09-23 00:27:11 +02:00
$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
2022-09-24 09:42:37 +02:00
chmod +x " ../linker/ $HOST_ARCH /linker64 " || abort
2022-09-23 00:27:11 +02:00
$SUDO patchelf --set-interpreter " ../linker/ $HOST_ARCH /linker64 " " $WORK_DIR " /magisk/magiskpolicy || abort
2022-09-16 13:32:04 +02:00
chmod +x " $WORK_DIR " /magisk/magiskpolicy || abort
2022-08-30 15:59:26 +02:00
elif [ -z " ${ CUSTOM_MAGISK +x } " ] ; then
2022-08-29 20:03:07 +02:00
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"
2022-09-03 17:44:52 +02:00
if [ " $GAPPS_BRAND " != 'none' ] ; then
2022-09-22 13:37:17 +02:00
echo " Extract $GAPPS_BRAND "
2022-08-29 20:03:07 +02:00
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? "
2022-12-08 13:06:42 +01:00
CLEAN_DOWNLOAD_GAPPS = 1
2022-08-29 20:03:07 +02:00
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
else
echo " The $GAPPS_BRAND zip package does not exist. "
2022-09-01 05:11:43 +02:00
abort
2022-08-29 20:03:07 +02:00
fi
echo -e "Extract done\n"
fi
echo "Expand images"
2022-09-23 00:27:11 +02:00
if [ ! -f /etc/mtab ] ; then $SUDO ln -s /proc/self/mounts /etc/mtab; fi
2022-09-22 08:38:11 +02:00
e2fsck -pf " $WORK_DIR " /wsa/" $ARCH " /system_ext.img || abort
2022-08-29 20:03:07 +02:00
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
2022-09-22 08:38:11 +02:00
e2fsck -pf " $WORK_DIR " /wsa/" $ARCH " /product.img || abort
2022-08-29 20:03:07 +02:00
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
2022-09-22 08:38:11 +02:00
e2fsck -pf " $WORK_DIR " /wsa/" $ARCH " /system.img || abort
2022-08-29 20:03:07 +02:00
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
2022-09-22 08:38:11 +02:00
e2fsck -pf " $WORK_DIR " /wsa/" $ARCH " /vendor.img || abort
2022-08-29 20:03:07 +02:00
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"
2022-09-23 00:27:11 +02:00
$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
2022-08-29 20:03:07 +02:00
echo -e "done\n"
2022-08-30 15:59:26 +02:00
if [ " $REMOVE_AMAZON " ] ; then
2022-09-04 16:44:31 +02:00
echo "Remove Amazon Appstore"
2022-09-23 00:27:11 +02:00
find " ${ MOUNT_DIR : ? } " /product/{ etc/permissions,etc/sysconfig,framework,priv-app} | grep -e amazon -e venezia | $SUDO xargs rm -rf
2022-12-09 13:13:22 +01:00
find " ${ MOUNT_DIR : ? } " /system_ext/{ etc/*permissions,framework,priv-app} | grep -e amazon -e venezia | $SUDO xargs rm -rf
2022-08-29 20:03:07 +02:00
echo -e "done\n"
fi
2022-10-02 13:31:42 +02:00
echo "Add device administration features"
$SUDO sed -i -e '/cts/a \ \ \ \ <feature name="android.software.device_admin" />' -e '/print/i \ \ \ \ <feature name="android.software.managed_users" />' " $MOUNT_DIR " /vendor/etc/permissions/windows.permissions.xml
2022-10-02 13:40:49 +02:00
$SUDO setfattr -n security.selinux -v "u:object_r:vendor_configs_file:s0" " $MOUNT_DIR " /vendor/etc/permissions/windows.permissions.xml || abort
2022-10-02 13:31:42 +02:00
echo -e "done\n"
2022-08-29 20:03:07 +02:00
if [ " $ROOT_SOL " = 'magisk' ] || [ " $ROOT_SOL " = '' ] ; then
echo "Integrate Magisk"
2022-09-23 00:27:11 +02:00
$SUDO mkdir " $MOUNT_DIR " /sbin
$SUDO setfattr -n security.selinux -v "u:object_r:rootfs:s0" " $MOUNT_DIR " /sbin || abort
$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
2022-08-29 20:03:07 +02:00
#!/system/bin/sh
mkdir -p /data/adb/magisk
cp /sbin/* /data/adb/magisk/
2022-10-28 06:38:23 +02:00
sync
2022-08-29 20:03:07 +02:00
chmod -R 755 /data/adb/magisk
restorecon -R /data/adb/magisk
for module in \$ ( ls /data/adb/modules) ; do
if ! [ -f "/data/adb/modules/\$module/disable" ] && [ -f "/data/adb/modules/\$module/sepolicy.rule" ] ; then
/sbin/magiskpolicy --live --apply "/data/adb/modules/\$module/sepolicy.rule"
fi
done
EOF
2022-09-23 00:27:11 +02:00
$SUDO find " $MOUNT_DIR " /sbin -type f -exec chmod 0755 { } \;
$SUDO find " $MOUNT_DIR " /sbin -type f -exec chown root:root { } \;
$SUDO find " $MOUNT_DIR " /sbin -type f -exec setfattr -n security.selinux -v "u:object_r:system_file:s0" { } \; || abort
2022-09-16 13:32:04 +02:00
2022-08-29 20:03:07 +02:00
TMP_PATH = $( Gen_Rand_Str 8)
2022-09-23 00:27:11 +02:00
echo " /dev/ $TMP_PATH (/.*)? u:object_r:magisk_file:s0 " | $SUDO tee -a " $MOUNT_DIR " /vendor/etc/selinux/vendor_file_contexts
echo '/data/adb/magisk(/.*)? u:object_r:magisk_file:s0' | $SUDO tee -a " $MOUNT_DIR " /vendor/etc/selinux/vendor_file_contexts
$SUDO " $WORK_DIR " /magisk/magiskpolicy --load " $MOUNT_DIR " /vendor/etc/selinux/precompiled_sepolicy --save " $MOUNT_DIR " /vendor/etc/selinux/precompiled_sepolicy --magisk "allow * magisk_file lnk_file *" || abort
2022-08-29 20:03:07 +02:00
SERVER_NAME1 = $( Gen_Rand_Str 12)
SERVER_NAME2 = $( Gen_Rand_Str 12)
SERVER_NAME3 = $( Gen_Rand_Str 12)
SERVER_NAME4 = $( Gen_Rand_Str 12)
2022-09-23 00:27:11 +02:00
$SUDO tee -a " $MOUNT_DIR " /system/etc/init/hw/init.rc <<EOF
2022-08-29 20:03:07 +02:00
on post-fs-data
start adbd
mkdir /dev/$TMP_PATH
mount tmpfs tmpfs /dev/$TMP_PATH mode = 0755
copy /sbin/magisk64 /dev/$TMP_PATH /magisk64
chmod 0755 /dev/$TMP_PATH /magisk64
symlink ./magisk64 /dev/$TMP_PATH /magisk
symlink ./magisk64 /dev/$TMP_PATH /su
symlink ./magisk64 /dev/$TMP_PATH /resetprop
copy /sbin/magisk32 /dev/$TMP_PATH /magisk32
chmod 0755 /dev/$TMP_PATH /magisk32
copy /sbin/magiskinit /dev/$TMP_PATH /magiskinit
chmod 0755 /dev/$TMP_PATH /magiskinit
copy /sbin/magiskpolicy /dev/$TMP_PATH /magiskpolicy
chmod 0755 /dev/$TMP_PATH /magiskpolicy
mkdir /dev/$TMP_PATH /.magisk 700
mkdir /dev/$TMP_PATH /.magisk/mirror 700
mkdir /dev/$TMP_PATH /.magisk/block 700
copy /sbin/magisk.apk /dev/$TMP_PATH /stub.apk
2022-10-24 16:25:13 +02:00
chmod 0644 /dev/$TMP_PATH /stub.apk
2022-08-29 20:03:07 +02:00
rm /dev/.magisk_unblock
2022-10-28 06:38:23 +02:00
exec_start $SERVER_NAME1
2022-08-29 20:03:07 +02:00
start $SERVER_NAME2
wait /dev/.magisk_unblock 40
rm /dev/.magisk_unblock
service $SERVER_NAME1 /system/bin/sh /sbin/loadpolicy.sh
user root
seclabel u:r:magisk:s0
oneshot
service $SERVER_NAME2 /dev/$TMP_PATH /magisk --post-fs-data
user root
seclabel u:r:magisk:s0
oneshot
service $SERVER_NAME3 /dev/$TMP_PATH /magisk --service
class late_start
user root
seclabel u:r:magisk:s0
oneshot
on property:sys.boot_completed= 1
mkdir /data/adb/magisk 755
copy /sbin/magisk.apk /data/adb/magisk/magisk.apk
start $SERVER_NAME4
service $SERVER_NAME4 /dev/$TMP_PATH /magisk --boot-complete
user root
seclabel u:r:magisk:s0
oneshot
EOF
2022-09-03 18:43:31 +02:00
echo -e "Integrate Magisk done\n"
2022-08-29 20:03:07 +02:00
fi
echo "Merge Language Resources"
2022-12-09 13:11:20 +01:00
cp " $WORK_DIR " /wsa/" $ARCH " /resources.pri " $WORK_DIR " /wsa/pri/en-us.pri \
&& cp " $WORK_DIR " /wsa/" $ARCH " /AppxManifest.xml " $WORK_DIR " /wsa/xml/en-us.xml && {
tee " $WORK_DIR " /wsa/priconfig.xml <<EOF
2022-08-29 20:03:07 +02:00
<?xml version = "1.0" encoding = "UTF-8" standalone = "yes" ?>
<resources targetOsVersion = "10.0.0" majorVersion = "1" >
<index root = "\" startIndexAt=" \" >
<indexer-config type = "folder" foldernameAsQualifier = "true" filenameAsQualifier = "true" qualifierDelimiter = "." />
<indexer-config type = "PRI" />
</index>
</resources>
EOF
2022-12-09 13:11:20 +01:00
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/<Resources.*Resources>/<Resources>\n $( cat " $WORK_DIR " /wsa/xml/* | grep -Po '<Resource [^>]*/>' | 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 -e "Merge Language Resources failed\n"
2022-08-29 20:03:07 +02:00
echo "Add extra packages"
2022-09-23 00:27:11 +02:00
$SUDO cp -r ../" $ARCH " /system/* " $MOUNT_DIR " || abort
find ../" $ARCH " /system/system/priv-app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /system/priv-app/placeholder -type d -exec chmod 0755 { } \;
find ../" $ARCH " /system/system/priv-app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /system/priv-app/placeholder -type f -exec chmod 0644 { } \;
find ../" $ARCH " /system/system/priv-app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /system/priv-app/placeholder -exec chown root:root { } \;
find ../" $ARCH " /system/system/priv-app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /system/priv-app/placeholder -exec setfattr -n security.selinux -v "u:object_r:system_file:s0" { } \; || abort
2022-08-29 20:03:07 +02:00
echo -e "Add extra packages done\n"
2022-09-03 17:44:52 +02:00
if [ " $GAPPS_BRAND " != 'none' ] ; then
2022-09-22 13:37:17 +02:00
echo " Integrate $GAPPS_BRAND "
2022-08-29 20:03:07 +02:00
2022-09-23 00:27:11 +02:00
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 { } \;
2022-08-29 20:03:07 +02:00
file_list = " $( find " $WORK_DIR /gapps/ " -mindepth 1 -type f | cut -d/ -f5-) "
for file in $file_list ; do
2022-09-23 00:27:11 +02:00
$SUDO chown root:root " $WORK_DIR /gapps/ ${ file } "
$SUDO chmod 0644 " $WORK_DIR /gapps/ ${ file } "
2022-08-29 20:03:07 +02:00
done
if [ " $GAPPS_BRAND " = "OpenGApps" ] ; then
2022-09-23 00:27:11 +02:00
find " $WORK_DIR " /gapps/ -maxdepth 1 -mindepth 1 -type d -not -path '*product' -exec $SUDO cp --preserve= all -r { } " $MOUNT_DIR " /system \; || abort
2022-08-29 20:03:07 +02:00
elif [ " $GAPPS_BRAND " = "MindTheGapps" ] ; then
2022-09-23 00:27:11 +02:00
$SUDO cp --preserve= all -r " $WORK_DIR " /gapps/system_ext/* " $MOUNT_DIR " /system_ext/ || abort
2022-09-03 18:43:31 +02:00
if [ -e " $MOUNT_DIR " /system_ext/priv-app/SetupWizard ] ; then
2022-08-29 20:03:07 +02:00
rm -rf " ${ MOUNT_DIR : ? } /system_ext/priv-app/Provision "
fi
fi
2022-09-23 00:27:11 +02:00
$SUDO cp --preserve= all -r " $WORK_DIR " /gapps/product/* " $MOUNT_DIR " /product || abort
2022-08-29 20:03:07 +02:00
2022-09-23 00:27:11 +02:00
find " $WORK_DIR " /gapps/product/overlay -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /product/overlay/placeholder -type f -exec setfattr -n security.selinux -v "u:object_r:vendor_overlay_file:s0" { } \; || abort
2022-08-29 20:03:07 +02:00
if [ " $GAPPS_BRAND " = "OpenGApps" ] ; then
2022-09-23 00:27:11 +02:00
find " $WORK_DIR " /gapps/app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /system/app/placeholder -type d -exec setfattr -n security.selinux -v "u:object_r:system_file:s0" { } \; || abort
find " $WORK_DIR " /gapps/framework/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /system/framework/placeholder -type d -exec setfattr -n security.selinux -v "u:object_r:system_file:s0" { } \; || abort
find " $WORK_DIR " /gapps/priv-app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /system/priv-app/placeholder -type d -exec setfattr -n security.selinux -v "u:object_r:system_file:s0" { } \; || abort
find " $WORK_DIR " /gapps/app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /system/app/placeholder -type f -exec setfattr -n security.selinux -v "u:object_r:system_file:s0" { } \; || abort
find " $WORK_DIR " /gapps/framework/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /system/framework/placeholder -type f -exec setfattr -n security.selinux -v "u:object_r:system_file:s0" { } \; || abort
find " $WORK_DIR " /gapps/priv-app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /system/priv-app/placeholder -type f -exec setfattr -n security.selinux -v "u:object_r:system_file:s0" { } \; || abort
find " $WORK_DIR " /gapps/etc/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /system/etc/placeholder -type d -exec setfattr -n security.selinux -v "u:object_r:system_file:s0" { } \; || abort
find " $WORK_DIR " /gapps/etc/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /system/etc/placeholder -type f -exec setfattr -n security.selinux -v "u:object_r:system_file:s0" { } \; || abort
2022-08-29 20:03:07 +02:00
else
2022-09-23 00:27:11 +02:00
find " $WORK_DIR " /gapps/product/app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /product/app/placeholder -type d -exec setfattr -n security.selinux -v "u:object_r:system_file:s0" { } \; || abort
find " $WORK_DIR " /gapps/product/etc/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /product/etc/placeholder -type d -exec setfattr -n security.selinux -v "u:object_r:system_file:s0" { } \; || abort
find " $WORK_DIR " /gapps/product/priv-app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /product/priv-app/placeholder -type d -exec setfattr -n security.selinux -v "u:object_r:system_file:s0" { } \; || abort
find " $WORK_DIR " /gapps/product/framework/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /product/framework/placeholder -type d -exec setfattr -n security.selinux -v "u:object_r:system_file:s0" { } \; || abort
find " $WORK_DIR " /gapps/product/app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /product/app/placeholder -type f -exec setfattr -n security.selinux -v "u:object_r:system_file:s0" { } \; || abort
find " $WORK_DIR " /gapps/product/etc/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /product/etc/placeholder -type f -exec setfattr -n security.selinux -v "u:object_r:system_file:s0" { } \; || abort
find " $WORK_DIR " /gapps/product/priv-app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /product/priv-app/placeholder -type f -exec setfattr -n security.selinux -v "u:object_r:system_file:s0" { } \; || abort
find " $WORK_DIR " /gapps/product/framework/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /product/framework/placeholder -type f -exec setfattr -n security.selinux -v "u:object_r:system_file:s0" { } \; || abort
find " $WORK_DIR " /gapps/system_ext/etc/permissions/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /system_ext/etc/permissions/placeholder -type f -exec setfattr -n security.selinux -v "u:object_r:system_file:s0" { } \; || abort
$SUDO setfattr -n security.selinux -v "u:object_r:system_lib_file:s0" " $MOUNT_DIR " /product/lib || abort
find " $WORK_DIR " /gapps/product/lib/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /product/lib/placeholder -exec setfattr -n security.selinux -v "u:object_r:system_lib_file:s0" { } \; || abort
find " $WORK_DIR " /gapps/product/lib64/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /product/lib64/placeholder -type f -exec setfattr -n security.selinux -v "u:object_r:system_lib_file:s0" { } \; || abort
find " $WORK_DIR " /gapps/system_ext/priv-app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /system_ext/priv-app/placeholder -type d -exec setfattr -n security.selinux -v "u:object_r:system_file:s0" { } \; || abort
find " $WORK_DIR " /gapps/system_ext/etc/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /system_ext/etc/placeholder -type d -exec setfattr -n security.selinux -v "u:object_r:system_file:s0" { } \; || abort
find " $WORK_DIR " /gapps/system_ext/priv-app/ -maxdepth 1 -mindepth 1 -printf '%P\n' | xargs -I placeholder $SUDO find " $MOUNT_DIR " /system_ext/priv-app/placeholder -type f -exec setfattr -n security.selinux -v "u:object_r:system_file:s0" { } \; || abort
2022-08-29 20:03:07 +02:00
fi
2022-09-23 00:27:11 +02:00
$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" "allow gmscore_app system_server_tmpfs filesystem getattr" "allow gmscore_app gpu_device dir search" || abort
2022-09-22 13:37:17 +02:00
echo -e " Integrate $GAPPS_BRAND done\n "
2022-08-29 20:03:07 +02:00
fi
2022-09-03 17:44:52 +02:00
if [ " $GAPPS_BRAND " != 'none' ] ; then
2022-11-15 02:07:29 +01:00
if [ " $NOFIX_PROPS " ] ; then
echo -e " Skip fix $GAPPS_BRAND prop!\n $GAPPS_PROPS_MSG1 \n $GAPPS_PROPS_MSG2 \n $GAPPS_PROPS_MSG3 \n "
else
echo " Fix $GAPPS_BRAND prop "
$SUDO python3 fixGappsProp.py " $MOUNT_DIR " || abort
echo -e "done\n"
fi
2022-08-29 20:03:07 +02:00
fi
echo "Umount images"
2022-09-23 00:27:11 +02:00
$SUDO find " $MOUNT_DIR " -exec touch -hamt 200901010000.00 { } \;
$SUDO umount " $MOUNT_DIR " /vendor
$SUDO umount " $MOUNT_DIR " /product
$SUDO umount " $MOUNT_DIR " /system_ext
$SUDO umount " $MOUNT_DIR "
2022-08-29 20:03:07 +02:00
echo -e "done\n"
echo "Shrink images"
2022-09-22 08:38:11 +02:00
e2fsck -pf " $WORK_DIR " /wsa/" $ARCH " /system.img || abort
2022-08-29 20:03:07 +02:00
resize2fs -M " $WORK_DIR " /wsa/" $ARCH " /system.img || abort
2022-09-22 08:38:11 +02:00
e2fsck -pf " $WORK_DIR " /wsa/" $ARCH " /vendor.img || abort
2022-08-29 20:03:07 +02:00
resize2fs -M " $WORK_DIR " /wsa/" $ARCH " /vendor.img || abort
2022-09-22 08:38:11 +02:00
e2fsck -pf " $WORK_DIR " /wsa/" $ARCH " /product.img || abort
2022-08-29 20:03:07 +02:00
resize2fs -M " $WORK_DIR " /wsa/" $ARCH " /product.img || abort
2022-09-22 08:38:11 +02:00
e2fsck -pf " $WORK_DIR " /wsa/" $ARCH " /system_ext.img || abort
2022-08-29 20:03:07 +02:00
resize2fs -M " $WORK_DIR " /wsa/" $ARCH " /system_ext.img || abort
echo -e "Shrink images done\n"
echo "Remove signature and add scripts"
2022-09-23 00:27:11 +02:00
$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
2022-08-30 15:59:26 +02:00
cp " $vclibs_PATH " " $xaml_PATH " " $WORK_DIR " /wsa/" $ARCH " || abort
2022-08-29 20:03:07 +02:00
tee " $WORK_DIR " /wsa/" $ARCH " /Install.ps1 <<EOF
# Automated Install script by Midonei
2022-09-17 14:38:33 +02:00
\$ Host.UI.RawUI.WindowTitle = "Installing MagiskOnWSA..."
2022-08-29 20:03:07 +02:00
function Test-Administrator {
[ OutputType( [ bool] ) ]
param( )
process {
[ Security.Principal.WindowsPrincipal] \$ user = [ Security.Principal.WindowsIdentity] ::GetCurrent( ) ;
return \$ user.IsInRole( [ Security.Principal.WindowsBuiltinRole] ::Administrator) ;
}
}
2022-10-05 15:47:46 +02:00
function Get-InstalledDependencyVersion {
param (
[ string] \$ Name,
[ string] \$ ProcessorArchitecture
)
process {
return Get-AppxPackage -Name \$ Name | ForEach-Object { if ( \$ _.Architecture -eq \$ ProcessorArchitecture) { \$ _ } } | Sort-Object -Property Version | Select-Object -ExpandProperty Version -Last 1;
}
}
2022-08-29 20:03:07 +02:00
function Finish {
Clear-Host
Start-Process "wsa://com.topjohnwu.magisk"
Start-Process "wsa://com.android.vending"
}
2022-09-17 14:38:33 +02:00
If ( -Not ( Test-Administrator) ) {
2022-08-29 20:03:07 +02:00
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force
2022-10-02 13:05:08 +02:00
\$ proc = Start-Process -PassThru -WindowStyle Hidden -Verb RunAs ConHost.exe -Args "powershell -ExecutionPolicy Bypass -Command Set-Location '\$PSScriptRoot'; &'\$PSCommandPath' EVAL"
2022-08-29 20:03:07 +02:00
\$ proc.WaitForExit( )
2022-09-17 14:38:33 +02:00
If ( \$ proc.ExitCode -Ne 0) {
2022-08-29 20:03:07 +02:00
Clear-Host
Write-Warning "Failed to launch start as Administrator\`r\`nPress any key to exit"
\$ null = \$ Host.UI.RawUI.ReadKey( 'NoEcho,IncludeKeyDown' ) ;
}
exit
}
2022-09-17 14:38:33 +02:00
ElseIf ( ( \$ args.Count -Eq 1) -And ( \$ args[ 0] -Eq "EVAL" ) ) {
2022-10-05 15:47:46 +02:00
Start-Process ConHost.exe -Args "powershell -ExecutionPolicy Bypass -Command Set-Location '\$PSScriptRoot'; &'\$PSCommandPath'"
2022-08-29 20:03:07 +02:00
exit
}
2022-09-17 14:38:33 +02:00
If ( ( ( Test-Path -Path $( find " $WORK_DIR " /wsa/" $ARCH " -maxdepth 1 -mindepth 1 -printf "\"%P\"\n" | paste -sd "," -) ) -Eq \$ false ) .Count) {
2022-08-29 20:03:07 +02:00
Write-Error "Some files are missing in the folder. Please try to build again. Press any key to exist"
\$ null = \$ Host.UI.RawUI.ReadKey( 'NoEcho,IncludeKeyDown' )
exit 1
}
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1"
2022-09-17 14:38:33 +02:00
If ( \$ ( Get-WindowsOptionalFeature -Online -FeatureName 'VirtualMachinePlatform' ) .State -Ne "Enabled" ) {
2022-08-29 20:03:07 +02:00
Enable-WindowsOptionalFeature -Online -NoRestart -FeatureName 'VirtualMachinePlatform'
Clear-Host
Write-Warning "Need restart to enable virtual machine platform\`r\`nPress y to restart or press any key to exit"
\$ key = \$ Host.UI.RawUI.ReadKey( 'NoEcho,IncludeKeyDown' )
2022-09-17 14:38:33 +02:00
If ( "y" -Eq \$ key.Character) {
2022-08-29 20:03:07 +02:00
Restart-Computer -Confirm
}
Else {
exit 1
}
}
2022-10-05 15:47:46 +02:00
[ xml] \$ Xml = Get-Content ".\AppxManifest.xml" ;
\$ Name = \$ Xml.Package.Identity.Name;
\$ ProcessorArchitecture = \$ Xml.Package.Identity.ProcessorArchitecture;
\$ Dependencies = \$ Xml.Package.Dependencies.PackageDependency;
\$ Dependencies | ForEach-Object {
If ( \$ _.Name -Eq "Microsoft.VCLibs.140.00.UWPDesktop" ) {
\$ HighestInstalledVCLibsVersion = Get-InstalledDependencyVersion -Name \$ _.Name -ProcessorArchitecture \$ ProcessorArchitecture;
If ( \$ HighestInstalledVCLibsVersion -Lt \$ _.MinVersion ) {
Add-AppxPackage -ForceApplicationShutdown -ForceUpdateFromAnyVersion -Path "Microsoft.VCLibs.\$ProcessorArchitecture.14.00.Desktop.appx"
}
}
ElseIf ( \$ _.Name -Match "Microsoft.UI.Xaml" ) {
\$ HighestInstalledXamlVersion = Get-InstalledDependencyVersion -Name \$ _.Name -ProcessorArchitecture \$ ProcessorArchitecture;
If ( \$ HighestInstalledXamlVersion -Lt \$ _.MinVersion ) {
Add-AppxPackage -ForceApplicationShutdown -ForceUpdateFromAnyVersion -Path "Microsoft.UI.Xaml_\$ProcessorArchitecture.appx"
}
}
}
2022-08-29 20:03:07 +02:00
\$ Installed = \$ null
2022-10-05 15:47:46 +02:00
\$ Installed = Get-AppxPackage -Name \$ Name
2022-08-29 20:03:07 +02:00
2022-09-17 14:38:33 +02:00
If ( ( \$ null -Ne \$ Installed) -And ( -Not ( \$ Installed.IsDevelopmentMode) ) ) {
2022-08-29 20:03:07 +02:00
Clear-Host
Write-Warning "There is already one installed WSA. Please uninstall it first.\`r\`nPress y to uninstall existing WSA or press any key to exit"
\$ key = \$ Host.UI.RawUI.ReadKey( 'NoEcho,IncludeKeyDown' )
2022-09-17 14:38:33 +02:00
If ( "y" -Eq \$ key.Character) {
2022-08-29 20:03:07 +02:00
Remove-AppxPackage -Package \$ Installed.PackageFullName
}
Else {
exit 1
}
}
Clear-Host
Write-Host "Installing MagiskOnWSA..."
2022-09-17 14:38:33 +02:00
Stop-Process -Name "WsaClient" -ErrorAction SilentlyContinue
2022-08-29 20:03:07 +02:00
Add-AppxPackage -ForceApplicationShutdown -ForceUpdateFromAnyVersion -Register .\A ppxManifest.xml
2022-09-17 14:38:33 +02:00
If ( \$ ?) {
2022-08-29 20:03:07 +02:00
Finish
}
2022-09-17 14:38:33 +02:00
ElseIf ( \$ null -Ne \$ Installed) {
2022-08-29 20:03:07 +02:00
Clear-Host
Write-Host "Failed to update, try to uninstall existing installation while preserving userdata..."
Remove-AppxPackage -PreserveApplicationData -Package \$ Installed.PackageFullName
Add-AppxPackage -ForceApplicationShutdown -ForceUpdateFromAnyVersion -Register .\A ppxManifest.xml
2022-09-17 14:38:33 +02:00
If ( \$ ?) {
2022-08-29 20:03:07 +02:00
Finish
}
}
2022-09-17 14:38:33 +02:00
Write-Host "All Done!\`r\`nPress any key to exit"
2022-08-29 20:03:07 +02:00
\$ null = \$ Host.UI.RawUI.ReadKey( 'NoEcho,IncludeKeyDown' )
EOF
2022-09-17 14:38:33 +02:00
tee " $WORK_DIR " /wsa/" $ARCH " /Run.bat <<EOF
:: Automated Install batch script by Syuugo
@echo off
if not exist Install.ps1 (
echo "Install.ps1" is not found.
echo Press any key to exit
pause>nul
exit 1
) else (
2022-09-22 08:38:11 +02:00
start powershell.exe -ExecutionPolicy Bypass -File .\I nstall.ps1
2022-09-17 14:38:33 +02:00
exit
)
EOF
2022-08-29 20:03:07 +02:00
echo -e "Remove signature and add scripts done\n"
echo "Generate info"
if [ [ " $ROOT_SOL " = "none" ] ] ; then
name1 = ""
2022-12-09 10:21:29 +01:00
elif [ " $ROOT_SOL " = "" ] || [ " $ROOT_SOL " = "magisk" ] ; then
name1 = " -with-magisk- $version ( $versionCode )- $MAGISK_VER "
2022-08-29 20:03:07 +02:00
else
name1 = " -with- $ROOT_SOL - $MAGISK_VER "
fi
2022-09-03 17:44:52 +02:00
if [ " $GAPPS_BRAND " = "none" ] ; then
2022-08-29 20:03:07 +02:00
name2 = "-NoGApps"
else
if [ " $GAPPS_BRAND " = "OpenGApps" ] ; then
2022-12-09 10:21:29 +01:00
name2 = " - $GAPPS_BRAND - ${ ANDROID_API_MAP [ $ANDROID_API ] } - ${ GAPPS_VARIANT } "
2022-08-29 20:03:07 +02:00
else
2022-12-09 10:21:29 +01:00
name2 = " - $GAPPS_BRAND - ${ ANDROID_API_MAP [ $ANDROID_API ] } "
2022-08-29 20:03:07 +02:00
fi
2022-08-30 15:59:26 +02:00
if [ " $GAPPS_BRAND " = "OpenGApps" ] && [ " $DEBUG " ] ; then
2022-08-29 20:03:07 +02:00
echo ":warning: Since OpenGApps doesn't officially support Android 12.1 yet, lock the variant to pico!"
fi
fi
2022-10-23 08:35:22 +02:00
artifact_name = "WSA"
2022-08-29 20:03:07 +02:00
echo -e "\nFinishing building...."
if [ -f " $OUTPUT_DIR " ] ; then
2022-09-23 00:27:11 +02:00
$SUDO rm -rf " ${ OUTPUT_DIR : ? } "
2022-08-29 20:03:07 +02:00
fi
if [ ! -d " $OUTPUT_DIR " ] ; then
mkdir -p " $OUTPUT_DIR "
fi
2022-10-22 12:32:39 +02:00
OUTPUT_PATH = " ${ OUTPUT_DIR : ? } / $artifact_name "
2022-10-21 19:03:02 +02:00
if [ " $COMPRESS_OUTPUT " ] || [ -n " $COMPRESS_FORMAT " ] ; then
2022-09-23 10:31:12 +02:00
mv " $WORK_DIR /wsa/ $ARCH " " $WORK_DIR /wsa/ $artifact_name "
2022-10-22 12:30:46 +02:00
if [ -z " $COMPRESS_FORMAT " ] ; then
COMPRESS_FORMAT = "7z"
fi
if [ -n " $COMPRESS_FORMAT " ] ; then
FILE_EXT = " . $COMPRESS_FORMAT "
if [ " $FILE_EXT " = ".xz" ] ; then
FILE_EXT = " .tar $FILE_EXT "
fi
2022-10-22 12:57:06 +02:00
OUTPUT_PATH = " $OUTPUT_PATH $FILE_EXT "
2022-10-22 12:30:46 +02:00
fi
2022-10-22 12:57:06 +02:00
rm -f " ${ OUTPUT_PATH : ? } " || abort
2022-10-21 19:03:02 +02:00
if [ " $COMPRESS_FORMAT " = "7z" ] ; then
2022-10-23 09:04:02 +02:00
echo "Compressing with 7z..."
2022-10-22 12:57:06 +02:00
7z a " ${ OUTPUT_PATH : ? } " " $WORK_DIR /wsa/ $artifact_name " || abort
2022-10-21 19:03:02 +02:00
elif [ " $COMPRESS_FORMAT " = "xz" ] ; then
2022-10-23 09:04:02 +02:00
echo "Compressing with tar xz..."
2022-10-22 12:57:06 +02:00
if ! ( tar -cP -I 'xz -9 -T0' -f " ${ OUTPUT_PATH : ? } " " $WORK_DIR /wsa/ $artifact_name " ) ; then
2022-10-21 19:03:02 +02:00
echo "Out of memory? Trying again with single threads..."
2022-10-22 12:57:06 +02:00
tar -cPJvf " ${ OUTPUT_PATH : ? } " " $WORK_DIR /wsa/ $artifact_name " || abort
2022-10-21 19:03:02 +02:00
fi
2022-10-22 12:30:46 +02:00
elif [ " $COMPRESS_FORMAT " = "zip" ] ; then
2022-10-23 09:04:02 +02:00
echo "Compressing with zip..."
2022-10-22 12:57:06 +02:00
7z -tzip a " ${ OUTPUT_PATH : ? } " " $WORK_DIR /wsa/ $artifact_name " || abort
2022-10-21 19:03:02 +02:00
fi
2022-08-30 15:59:26 +02:00
else
2022-10-22 12:32:39 +02:00
rm -rf " ${ OUTPUT_PATH : ? } " || abort
cp -r " $WORK_DIR " /wsa/" $ARCH " " $OUTPUT_PATH " || abort
2022-08-29 20:03:07 +02:00
fi
echo -e "done\n"
echo "Cleanup Work Directory"
2022-09-23 00:27:11 +02:00
$SUDO rm -rf " ${ WORK_DIR : ? } "
2022-08-29 20:03:07 +02:00
echo "done"