mirror of
https://github.com/LSPosed/MagiskOnWSALocal.git
synced 2025-04-22 00:19:08 +00:00
Separating the install script from the build script and warn on uninstall (#344)
Co-authored-by: Howard20181 <40033067+Howard20181@users.noreply.github.com>
This commit is contained in:
parent
3c7be0aa1c
commit
a5f46350b8
3 changed files with 132 additions and 131 deletions
117
installer/Install.ps1
Normal file
117
installer/Install.ps1
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
# Automated Install script by Midonei
|
||||||
|
$Host.UI.RawUI.WindowTitle = "Installing MagiskOnWSA..."
|
||||||
|
function Test-Administrator {
|
||||||
|
[OutputType([bool])]
|
||||||
|
param()
|
||||||
|
process {
|
||||||
|
[Security.Principal.WindowsPrincipal]$user = [Security.Principal.WindowsIdentity]::GetCurrent();
|
||||||
|
return $user.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Finish {
|
||||||
|
Clear-Host
|
||||||
|
Start-Process "wsa://com.topjohnwu.magisk"
|
||||||
|
Start-Process "wsa://com.android.vending"
|
||||||
|
}
|
||||||
|
|
||||||
|
If (-Not (Test-Administrator)) {
|
||||||
|
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force
|
||||||
|
$proc = Start-Process -PassThru -WindowStyle Hidden -Verb RunAs ConHost.exe -Args "powershell -ExecutionPolicy Bypass -Command Set-Location '$PSScriptRoot'; &'$PSCommandPath' EVAL"
|
||||||
|
$proc.WaitForExit()
|
||||||
|
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 ConHost.exe -Args "powershell -ExecutionPolicy Bypass -Command Set-Location '$PSScriptRoot'; &'$PSCommandPath'"
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
$FileList = Get-Content -Path .\filelist.txt
|
||||||
|
If (((Test-Path -Path $FileList) -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"
|
||||||
|
|
||||||
|
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) {
|
||||||
|
Restart-Computer -Confirm
|
||||||
|
}
|
||||||
|
Else {
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$Installed = $null
|
||||||
|
$Installed = Get-AppxPackage -Name $Name
|
||||||
|
|
||||||
|
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) {
|
||||||
|
Remove-AppxPackage -Package $Installed.PackageFullName
|
||||||
|
}
|
||||||
|
Else {
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Clear-Host
|
||||||
|
Write-Host "Installing MagiskOnWSA..."
|
||||||
|
Stop-Process -Name "WsaClient" -ErrorAction SilentlyContinue
|
||||||
|
Add-AppxPackage -ForceApplicationShutdown -ForceUpdateFromAnyVersion -Register .\AppxManifest.xml
|
||||||
|
If ($?) {
|
||||||
|
Finish
|
||||||
|
}
|
||||||
|
ElseIf ($null -Ne $Installed) {
|
||||||
|
Clear-Host
|
||||||
|
Write-Error "Failed to update.`r`nPress any key to uninstall existing installation while preserving user data.`r`nTake in mind that this will remove the Android apps' icon from the start menu.`r`nIf you want to cancel, close this window now."
|
||||||
|
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
|
||||||
|
Remove-AppxPackage -PreserveApplicationData -Package $Installed.PackageFullName
|
||||||
|
Add-AppxPackage -ForceApplicationShutdown -ForceUpdateFromAnyVersion -Register .\AppxManifest.xml
|
||||||
|
If ($?) {
|
||||||
|
Finish
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-Host "All Done!`r`nPress any key to exit"
|
||||||
|
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
|
12
installer/Run.bat
Normal file
12
installer/Run.bat
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
:: 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 -ExecutionPolicy Bypass -File .\Install.ps1
|
||||||
|
exit
|
||||||
|
)
|
134
scripts/build.sh
134
scripts/build.sh
|
@ -757,137 +757,9 @@ echo -e "Shrink images done\n"
|
||||||
echo "Remove signature and add scripts"
|
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
|
$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 "$vclibs_PATH" "$xaml_PATH" "$WORK_DIR"/wsa/"$ARCH" || abort
|
cp "$vclibs_PATH" "$xaml_PATH" "$WORK_DIR"/wsa/"$ARCH" || abort
|
||||||
tee "$WORK_DIR"/wsa/"$ARCH"/Install.ps1 <<EOF >/dev/null
|
cp ../installer/Install.ps1 "$WORK_DIR"/wsa/"$ARCH" || abort
|
||||||
# Automated Install script by Midonei
|
cp ../installer/Run.bat "$WORK_DIR"/wsa/"$ARCH" || abort
|
||||||
\$Host.UI.RawUI.WindowTitle = "Installing MagiskOnWSA..."
|
find "$WORK_DIR"/wsa/"$ARCH" -maxdepth 1 -mindepth 1 -printf "%P\n" > "$WORK_DIR"/wsa/"$ARCH"/filelist.txt || abort
|
||||||
function Test-Administrator {
|
|
||||||
[OutputType([bool])]
|
|
||||||
param()
|
|
||||||
process {
|
|
||||||
[Security.Principal.WindowsPrincipal]\$user = [Security.Principal.WindowsIdentity]::GetCurrent();
|
|
||||||
return \$user.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function Finish {
|
|
||||||
Clear-Host
|
|
||||||
Start-Process "wsa://com.topjohnwu.magisk"
|
|
||||||
Start-Process "wsa://com.android.vending"
|
|
||||||
}
|
|
||||||
|
|
||||||
If (-Not (Test-Administrator)) {
|
|
||||||
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force
|
|
||||||
\$proc = Start-Process -PassThru -WindowStyle Hidden -Verb RunAs ConHost.exe -Args "powershell -ExecutionPolicy Bypass -Command Set-Location '\$PSScriptRoot'; &'\$PSCommandPath' EVAL"
|
|
||||||
\$proc.WaitForExit()
|
|
||||||
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 ConHost.exe -Args "powershell -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) {
|
|
||||||
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"
|
|
||||||
|
|
||||||
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) {
|
|
||||||
Restart-Computer -Confirm
|
|
||||||
}
|
|
||||||
Else {
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
\$Installed = \$null
|
|
||||||
\$Installed = Get-AppxPackage -Name \$Name
|
|
||||||
|
|
||||||
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) {
|
|
||||||
Remove-AppxPackage -Package \$Installed.PackageFullName
|
|
||||||
}
|
|
||||||
Else {
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Clear-Host
|
|
||||||
Write-Host "Installing MagiskOnWSA..."
|
|
||||||
Stop-Process -Name "WsaClient" -ErrorAction SilentlyContinue
|
|
||||||
Add-AppxPackage -ForceApplicationShutdown -ForceUpdateFromAnyVersion -Register .\AppxManifest.xml
|
|
||||||
If (\$?) {
|
|
||||||
Finish
|
|
||||||
}
|
|
||||||
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 (\$?) {
|
|
||||||
Finish
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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 >/dev/null
|
|
||||||
:: 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 -ExecutionPolicy Bypass -File .\Install.ps1
|
|
||||||
exit
|
|
||||||
)
|
|
||||||
EOF
|
|
||||||
echo -e "Remove signature and add scripts done\n"
|
echo -e "Remove signature and add scripts done\n"
|
||||||
|
|
||||||
echo "Generate info"
|
echo "Generate info"
|
||||||
|
|
Loading…
Add table
Reference in a new issue