diff --git a/README.md b/README.md index 0538521894..c9e45cbe7b 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ 1. Select the root solution (none means no root) 1. Wait for the script to complete and the artifact will be in the `output` folder 1. Move the artifact to a place you like -1. Right-click `Install.ps1` and select `Run with PowerShell` +1. Double-click `Run.bat` - If you previously have a MagiskOnWSA installation, it will automatically uninstall the previous one while **preserving all user data** and install the new one, so don't worry about your data. - If you have an official WSA installation, you should uninstall it first. (In case you want to preserve your data, you can backup `%LOCALAPPDATA%\Packages\MicrosoftCorporationII.WindowsSubsystemForAndroid_8wekyb3d8bbwe\LocalCache\userdata.vhdx` before uninstallation and restore it after installation.) (If you want to restore the icons to the start menu, please install and use [WSAHelper](https://github.com/LSPosed/WSAHelper/releases/latest).) - If the popup windows disappear **without asking administrative permission** and WSA is not installed successfully, you should manually run `Install.ps1` as administrator: diff --git a/scripts/build.sh b/scripts/build.sh index 79b1668e3b..0078f7ceb0 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -275,6 +275,12 @@ if [ "$DEBUG" ]; then set -x fi +require_su() { + if [ "$(sudo whoami)" != "root" ]; then + sudo echo "sudo is required to run this script" + 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 @@ -295,11 +301,10 @@ if [ "$GAPPS_BRAND" = "OpenGApps" ]; then 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 + require_su echo "Generate Download Links" python3 generateWSALinks.py "$ARCH" "$RELEASE_TYPE" "$DOWNLOAD_DIR" "$DOWNLOAD_CONF_NAME" || abort if [ -z "${CUSTOM_MAGISK+x}" ]; then @@ -332,12 +337,14 @@ else echo "Offline mode: Some files are missing, please disable offline mode." exit 1 fi + require_su 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 + touch "$WSA_WORK_ENV" export WSA_WORK_ENV if ! python3 extractWSA.py "$ARCH" "$WSA_ZIP_PATH" "$WORK_DIR"; then echo "Unzip WSA failed, is the download incomplete?" @@ -351,14 +358,19 @@ else echo "The WSA zip package does not exist, is the download incomplete?" exit 1 fi -echo "Extract Magisk" +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 + 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 elif [ -z "${CUSTOM_MAGISK+x}" ]; then echo "The Magisk zip package does not exist, is the download incomplete?" exit 1 @@ -399,7 +411,7 @@ if [ "$GAPPS_BRAND" != 'none' ]; then fi echo "Expand images" - +if [ ! -f /etc/mtab ]; then sudo ln -s /proc/self/mounts /etc/mtab; fi 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 @@ -476,11 +488,7 @@ EOF 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 chcon --reference "$MOUNT_DIR"/product {} \; - 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 + TMP_PATH=$(Gen_Rand_Str 8) 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 @@ -623,12 +631,7 @@ if [ "$GAPPS_BRAND" != 'none' ]; then 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 + 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 echo -e "Integrate GApps done\n" fi @@ -662,7 +665,7 @@ sudo rm -rf "${WORK_DIR:?}"/wsa/"$ARCH"/\[Content_Types\].xml "$WORK_DIR"/wsa/"$ cp "$vclibs_PATH" "$xaml_PATH" "$WORK_DIR"/wsa/"$ARCH" || abort tee "$WORK_DIR"/wsa/"$ARCH"/Install.ps1 <