forked from insomnyawolf/MagiskOnWSALocalAutoInstaller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MagiskOnWSALocalAutoInstaller.ps1
180 lines (127 loc) · 4.98 KB
/
MagiskOnWSALocalAutoInstaller.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# Reboot computer command
# https://www.windows-commandline.com/reboot-computer-from-command-line/
# "FIND" Exit codes info
# https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/find#exit-codes
# Execute commands in wsl
# https://github.com/microsoft/WSL/discussions/6128
# DISM DOCS
# https://ss64.com/nt/dism.html
# Automatically detect if the terminal is running as admin and if it isn't restart it with admin rights
$CurrentRole = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$IsAdmin = $CurrentRole.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
Write-Output "Checking Admin Rights";
if (!$IsAdmin) {
$originalArguments = "-NoLogo -NoProfile -NoExit -ExecutionPolicy Bypass"
$originalArguments += " -File `"$($MyInvocation.MyCommand.Source)`"";
foreach ($arg in $args) {
$originalArguments += ' ';
$originalArguments += $arg;
}
Start-Process -FilePath 'powershell' -Verb RunAs -ArgumentList $originalArguments;
exit
}
Write-Output "Checking Requieriments";
$windowsFeatures = DISM /Online /Get-Features /Format:table /English
function CheckAndActivateWindowsFeatureRequiered {
param (
[string]$FeatureName
)
Write-Output "Checking $($FeatureName) status";
$feature = $windowsFeatures | Select-String -Pattern $FeatureName;
if ($null -eq $feature) {
Write-Host "Feature requiered not found, exiting...";
exit
}
$parts = $feature.Line.Split("|");
if ($parts.Count -ne 2){
Write-Output "Script isn't processing feature info right. Exiting...";
exit
}
$featureStatus = $parts[1].Trim();
if ($featureStatus -eq "Disabled") {
Write-Output "Enabling $($FeatureName)";
DISM /Online /NoRestart /Enable-Feature /FeatureName:$FeatureName;
return $true;
}
elseif ($featureStatus -eq "Enabled"){
Write-Output "$($FeatureName) is already enabled, nothing to do.";
return $false;
}
else {
Write-Output "The script creator did something stupid, please report this error.";
exit
}
# command to reverse this:
# DISM /Online /Disable-Feature /FeatureName:$FeatureName
}
$FeaturesRequiered = @(
"Microsoft-Hyper-V-All",
"Microsoft-Windows-Subsystem-Linux"
)
$isRestartRequiered = $false;
foreach ($feature in $FeaturesRequiered) {
$test = CheckAndActivateWindowsFeatureRequiered -FeatureName $feature;
# Powershell is weird
if ($test[$test.Count - 1]){
$isRestartRequiered = $true;
}
}
if ($isRestartRequiered) {
$infoText = "The computer will be restarted to enable the needed features, please save your work and run this script again after the reboot";
Write-Output $infoText;
shutdown /r /t 300 /c $infoText
exit
}
Write-Output "Preparing building environment";
WSL --update
$wslAvailableDistrosRaw = wsl --list;
# regexr.com/6uoof
$wslAvailableDistrosClean = $wslAvailableDistrosRaw -replace '[^0-9A-Za-z()\- ]', '';
$distroWeNeed = $null;
foreach ($availableDistro in $wslAvailableDistrosClean) {
if ($availableDistro.StartsWith("Ubuntu")){
$distroWeNeed = $availableDistro.Split(" (")[0];
break;
}
}
if ($null -eq $distroWeNeed){
$distroWeNeed = "Ubuntu";
Write-Host "Installing wsl distro that is needed to continue..."
wsl --install $distroWeNeed
}
wsl --set-version $distroWeNeed 2
Write-Host "Updating System"
wsl --distribution $distroWeNeed --user root apt update
wsl --distribution $distroWeNeed --user root apt --yes full-upgrade
Write-Host "Installing requisites"
wsl --distribution $distroWeNeed --user root apt --yes install setools lzip patchelf e2fsprogs aria2 python3 attr wine winetricks python3-pip git
wsl --distribution $distroWeNeed --user root winetricks msxml6
wsl --distribution $distroWeNeed --user root pip install requests
Set-Location $HOME
$folder = "source";
if (!(Test-Path -Path $folder)) {
Write-Host "Creating Working Directory"
New-Item -Path $folder -ItemType Directory
}
Set-Location $folder
$subfolderPath = "MagiskOnWSALocal";
if (Test-Path -Path $subfolderPath) {
Write-Host "Updating files..."
Set-Location $subfolderPath
wsl --distribution $distroWeNeed git pull
}
else{
Write-Host "Downloading files..."
wsl --distribution $distroWeNeed git clone https://github.com/LSPosed/MagiskOnWSALocal
Set-Location $subfolderPath
}
wsl --distribution $distroWeNeed --user root scripts/build.sh --arch x64 --release-type WIF --gapps-brand MindTheGapps --gapps-variant pico --root-sol magisk --magisk-ver canary
Set-Location "output"
$lastestRelease = Get-ChildItem -Directory | Sort-Object LastWriteTime -Descending | Select-Object -First 1
Set-Location $lastestRelease.PSChildName;
#PowerShell.exe -ExecutionPolicy Bypass -File .\Install.ps1
& .\Install.ps1
if ($Host.Name -eq "ConsoleHost") {
Write-Host "Press any key to continue..."
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp") > $null
}