Skip to content

Commit

Permalink
Merge remote-tracking branch 'source/main' into source
Browse files Browse the repository at this point in the history
  • Loading branch information
wxy1343 committed Sep 19, 2022
2 parents da9661c + 42f56d9 commit d4e7281
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 50 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
82 changes: 49 additions & 33 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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?"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 <<EOF
# Automated Install script by Midonei
# http://github.com/doneibcn
\$Host.UI.RawUI.WindowTitle = "Installing MagiskOnWSA..."
function Test-Administrator {
[OutputType([bool])]
param()
Expand All @@ -678,37 +681,36 @@ function Finish {
Start-Process "wsa://com.android.vending"
}
if (-not (Test-Administrator)) {
If (-Not (Test-Administrator)) {
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force
\$proc = Start-Process -PassThru -WindowStyle Hidden -Verb RunAs powershell.exe -Args "-executionpolicy bypass -command Set-Location '\$PSScriptRoot'; &'\$PSCommandPath' EVAL"
\$proc = Start-Process -PassThru -WindowStyle Hidden -Verb RunAs powershell.exe -Args "-ExecutionPolicy Bypass -Command Set-Location '\$PSScriptRoot'; &'\$PSCommandPath' EVAL"
\$proc.WaitForExit()
if (\$proc.ExitCode -ne 0) {
If (\$proc.ExitCode -Ne 0) {
Clear-Host
Write-Warning "Failed to launch start as Administrator\`r\`nPress any key to exit"
\$null = \$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
}
exit
}
elseif ((\$args.Count -eq 1) -and (\$args[0] -eq "EVAL")) {
Start-Process powershell.exe -Args "-executionpolicy bypass -command Set-Location '\$PSScriptRoot'; &'\$PSCommandPath'"
ElseIf ((\$args.Count -Eq 1) -And (\$args[0] -Eq "EVAL")) {
Start-Process powershell.exe -Args "-ExecutionPolicy Bypass -Command Set-Location '\$PSScriptRoot'; &'\$PSCommandPath'"
exit
}
if (((Test-Path -Path $(find "$WORK_DIR"/wsa/"$ARCH" -maxdepth 1 -mindepth 1 -printf "\"%P\"\n" | paste -sd "," -)) -eq \$false).Count) {
If (((Test-Path -Path $(find "$WORK_DIR"/wsa/"$ARCH" -maxdepth 1 -mindepth 1 -printf "\"%P\"\n" | paste -sd "," -)) -Eq \$false).Count) {
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"
\$VMP = Get-WindowsOptionalFeature -Online -FeatureName 'VirtualMachinePlatform'
if (\$VMP.State -ne "Enabled") {
If (\$(Get-WindowsOptionalFeature -Online -FeatureName 'VirtualMachinePlatform').State -Ne "Enabled") {
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')
If ("y" -eq \$key.Character) {
If ("y" -Eq \$key.Character) {
Restart-Computer -Confirm
}
Else {
Expand All @@ -722,11 +724,11 @@ Add-AppxPackage -ForceApplicationShutdown -ForceUpdateFromAnyVersion -Path xaml-
\$Installed = \$null
\$Installed = Get-AppxPackage -Name 'MicrosoftCorporationII.WindowsSubsystemForAndroid'
If ((\$null -ne \$Installed) -and (-not (\$Installed.IsDevelopmentMode))) {
If ((\$null -Ne \$Installed) -And (-Not (\$Installed.IsDevelopmentMode))) {
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')
If ("y" -eq \$key.Character) {
If ("y" -Eq \$key.Character) {
Remove-AppxPackage -Package \$Installed.PackageFullName
}
Else {
Expand All @@ -735,23 +737,37 @@ If ((\$null -ne \$Installed) -and (-not (\$Installed.IsDevelopmentMode))) {
}
Clear-Host
Write-Host "Installing MagiskOnWSA..."
Stop-Process -Name "wsaclient" -ErrorAction "silentlycontinue"
Stop-Process -Name "WsaClient" -ErrorAction SilentlyContinue
Add-AppxPackage -ForceApplicationShutdown -ForceUpdateFromAnyVersion -Register .\AppxManifest.xml
if (\$?) {
If (\$?) {
Finish
}
Elseif (\$null -ne \$Installed) {
ElseIf (\$null -Ne \$Installed) {
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 .\AppxManifest.xml
if (\$?) {
If (\$?) {
Finish
}
}
Write-Host "All Done\`r\`nPress any key to exit"
Write-Host "All Done!\`r\`nPress any key to exit"
\$null = \$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
EOF
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 (
start powershell.exe -File .\Install.ps1 -ExecutionPolicy Bypass
exit
)
EOF
echo -e "Remove signature and add scripts done\n"

echo "Generate info"
Expand Down
7 changes: 3 additions & 4 deletions scripts/extractMagisk.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,16 @@
import sys

import zipfile
import os
from pathlib import Path
import platform

is_x86_64 = platform.machine() in ("AMD64", "x86_64")
host_abi = "x64" if is_x86_64 else "arm64"
arch = sys.argv[1]
magisk_zip = sys.argv[2]
if not os.path.exists(Path.cwd().parent / sys.argv[3] / "magisk"):
os.makedirs(Path.cwd().parent / sys.argv[3] / "magisk")
workdir = Path.cwd().parent / sys.argv[3] / "magisk"
workdir = Path(sys.argv[3]) / "magisk"
if not Path(workdir).is_dir():
workdir.mkdir()

abi_map = {"x64": ["x86_64", "x86"], "arm64": ["arm64-v8a", "armeabi-v7a"]}

Expand Down
10 changes: 5 additions & 5 deletions scripts/extractWSA.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@

arch = sys.argv[1]

if not os.path.exists(Path.cwd().parent / sys.argv[2] / "wsa"):
os.makedirs(Path.cwd().parent / sys.argv[2] / "wsa")
zip_name = ""
wsa_zip_path= Path(sys.argv[2]).resolve()
workdir = Path.cwd().parent / sys.argv[3] / "wsa"
workdir = Path(sys.argv[3]) / "wsa"
if not Path(workdir).is_dir():
workdir.mkdir()
with zipfile.ZipFile(wsa_zip_path) as zip:
for f in zip.filelist:
if arch in f.filename.lower():
zip_name = f.filename
output_name = zip_name[11:-5]
if not os.path.isfile(workdir / zip_name):
if not Path(workdir / zip_name).is_file():
zip_path = workdir / zip_name
print(f"unzipping to {workdir}", flush=True)
zip.extract(f, workdir)
Expand Down Expand Up @@ -67,6 +67,6 @@
g.filename = f'{name}.xml'
l.extract(g, workdir / 'xml')
with zipfile.ZipFile(zip_path) as zip:
if not os.path.isdir(workdir / arch):
if not Path(workdir / arch).is_dir():
print(f"unzipping from {zip_path}", flush=True)
zip.extractall(workdir / arch)
4 changes: 2 additions & 2 deletions scripts/fixGappsProp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

from __future__ import annotations
from io import TextIOWrapper
from os import system, path
from typing import OrderedDict
from pathlib import Path
import sys
class Prop(OrderedDict):
def __init__(self, file: TextIOWrapper) -> None:
Expand Down Expand Up @@ -61,7 +61,7 @@ def fingerprint(sec: str, p: Prop) -> str:


def fix_prop(sec, prop):
if not path.exists(prop):
if not Path(prop).is_file():
return

print(f"fixing {prop}", flush=True)
Expand Down
3 changes: 2 additions & 1 deletion scripts/generateGappsLink.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import sys

import requests
import os
import json
import re
from pathlib import Path
Expand All @@ -45,6 +44,8 @@
j = json.loads(res.content)
link = {i["name"]: i for i in j["archs"][abi_map[arch]]
["apis"][release]["variants"]}[variant]["zip"]
DATE=j["archs"][abi_map[arch]]["date"]
print(f"DATE={DATE}", flush=True)
except Exception:
print("Failed to fetch from OpenGApps API, fallbacking to SourceForge RSS...")
res = requests.get(
Expand Down
1 change: 0 additions & 1 deletion scripts/generateMagiskLink.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import sys

import os
import json
import requests
from pathlib import Path
Expand Down
5 changes: 2 additions & 3 deletions scripts/generateWSALinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import html
import warnings
import re
import os
from pathlib import Path

warnings.filterwarnings("ignore")
Expand Down Expand Up @@ -81,8 +80,8 @@
with open(Path.cwd().parent / "xml/FE3FileUrl.xml", "r") as f:
file_content = f.read()

if not os.path.exists(download_dir):
os.makedirs(download_dir)
if not download_dir.is_dir():
download_dir.mkdir()
tmpdownlist = open(download_dir/tempScript, 'a')
for i, v, f in identities:
if re.match(f"Microsoft\.UI\.Xaml\..*_{arch}_.*\.appx", f):
Expand Down
1 change: 1 addition & 0 deletions scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ check_dependencies() {
command -v resize2fs >/dev/null 2>&1 || NEED_INSTALL+=("e2fsprogs")
command -v pip >/dev/null 2>&1 || NEED_INSTALL+=("python3-pip")
command -v aria2c >/dev/null 2>&1 || NEED_INSTALL+=("aria2")
command -v 7z > /dev/null 2>&1 || NEED_INSTALL+=("p7zip-full")
}
check_dependencies
declare -A os_pm_install;
Expand Down

0 comments on commit d4e7281

Please sign in to comment.