From 5dc1fb0f1d42469f3715decf5e2579352d46d478 Mon Sep 17 00:00:00 2001 From: herrwinfried <52379312+herrwinfried@users.noreply.github.com> Date: Sun, 25 Sep 2022 15:04:03 +0300 Subject: [PATCH] Update automatic.ps1 --- powershell/automatic.ps1 | 404 ++++++++++++++++++++++----------------- 1 file changed, 226 insertions(+), 178 deletions(-) diff --git a/powershell/automatic.ps1 b/powershell/automatic.ps1 index a7f8184..936f685 100644 --- a/powershell/automatic.ps1 +++ b/powershell/automatic.ps1 @@ -1,206 +1,254 @@ -param ( - [string]$wsldistro = 'Ubuntu', - - [ValidateSet('amd64','arm64')] - [string]$arch = 'amd64', - - [ValidateSet('tr-tr','de-de', 'en-US')] - [string]$scriptlang = 'en-US', - - [ValidateSet('onlywsa','wsagascript', 'magiskonwsalocal')] - [string]$method = 'magiskonwsalocal', - - [ValidateSet('fast','slow', 'rp', 'retail')] - [string]$wsarelease = 'retail', - - [ValidateSet('stable','beta', 'canary', 'debug')] - [string]$magiskversion = 'stable', - - [ValidateSet('yes','no')] - [string]$amazonstore = 'no', - - [ValidateSet('yes','no')] - [string]$wsatools = 'no', - - [string]$productname = 'redfin', +param( +[string]$selectos, +[bool]$wsa, +[bool]$gapps, +[bool]$vmc, +[bool]$wsatools, +[bool]$wsadevwin, +[bool]$tempwsa, +[bool]$onlywsa, +[ValidateSet("default", "super", "stock", "full", "mini", "micro", "nano", "pico")][string]$gappsvariant + +) +if ([string]::IsNullOrEmpty($selectos)) { +$selectos = "Unknown" +} elseif ([string]::IsNullOrWhiteSpace($selectos)) { + $selectos = "Unknown" +} +if ([string]::IsNullOrEmpty($gappsvariant)) { + $gappsvariant = "default" + } elseif ([string]::IsNullOrWhiteSpace($gappsvariant)) { + $gappsvariant = "default" + } +$wsaint = [int][bool]::Parse($wsa) +$gappsint = [int][bool]::Parse($gapps) +$vmcint = [int][bool]::Parse($vmc) +$wsatoolsint = [int][bool]::Parse($wsatools) +$wsadevwinint = [int][bool]::Parse($wsadevwin) +$tempwsaint = [int][bool]::Parse($tempwsa) +$onlywsaint = [int][bool]::Parse($onlywsa) + +if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-ExecutionPolicy Bypass `"$PSCommandPath`" $selectos $wsaint $gappsint $vmcint $wsatoolsint $wsadevwinint $tempwsaint $onlywsaint $gappsvariant" -Verb RunAs; exit } +Clear-Host +Write-Host "1 = True/Yes/Active" -ForegroundColor Green +Write-Host "0 = False/No/Deactive" -ForegroundColor Red +Start-Sleep -s 0.75 +Write-Host "Select OS: " -ForegroundColor Yellow -NoNewline; Write-Host "$selectos" -ForegroundColor White +Start-Sleep -s 0.2 +Write-Host "WSA Value: " -ForegroundColor Green -NoNewline; Write-Host "$wsaint " -ForegroundColor White -NoNewline; Write-Host "| TempWSA Value: " -ForegroundColor Green -NoNewline; Write-Host "$tempwsaint" -ForegroundColor White +Start-Sleep -s 0.2 +Write-Host "openGapps Value: " -ForegroundColor Blue -NoNewline; Write-Host "$gappsint" -ForegroundColor White +Start-Sleep -s 0.2 +Write-Host "Only WSA Value: " -ForegroundColor Blue -NoNewline; Write-Host "$onlywsaint" -ForegroundColor White +Start-Sleep -s 0.2 +Write-Host "Virtual Machine Platform Value: " -ForegroundColor Cyan -NoNewline; Write-Host "$vmcint" -ForegroundColor White +Start-Sleep -s 0.2 +Write-Host "WSATools Value: " -ForegroundColor DarkYellow -NoNewline; Write-Host "$wsatoolsint" -ForegroundColor White +Start-Sleep -s 0.2 +Write-Host "WSA And Windows Developer Mode Value: " -ForegroundColor Magenta -NoNewline; Write-Host "$wsadevwinint" -ForegroundColor White +Start-Sleep -s 0.2 +Write-Host "Running Powershell version: " -ForegroundColor DarkBlue -NoNewline; Write-Host (Get-Host).Version -ForegroundColor White +Start-Sleep -s 0.2 +Write-Host "Gapps Variant: " -ForegroundColor DarkBlue -NoNewline; Write-Host $gappsvariant -ForegroundColor White + +Start-Sleep -s 3.88 +Clear-Host - [ValidateSet('super','stock', 'full', 'mini','micro','nano', 'pico')] - [string]$gappsvariant = 'pico', +##################################### +if ( ((Get-Host).Version).Major -ne "5" ) { + Import-Module -Name Appx -UseWIndowsPowershell +} - [ValidateSet('yes','no')] - [string]$winvmp = 'yes', +$Arch = ($env:PROCESSOR_ARCHITECTURE) - [ValidateSet('yes','no')] - [string]$windevmode = 'yes', +if ($Arch -eq 'x86') { + Write-Host -Object 'Running 32-bit PowerShell' -ForegroundColor Green + Write-Host -Object 'Sorry I dont support 32 bit.' -ForegroundColor Red + pause + exit +} +elseif ($Arch -eq 'Arm32') { + Write-Host -Object 'Running 32-bit arm PowerShell' -ForegroundColor Green + Write-Host -Object 'Sorry I dont support 32 bit.' -ForegroundColor Red + pause + exit +} - [ValidateSet('yes','no')] - [string]$adb = 'no' - ) - -$WindowsArch = ($env:PROCESSOR_ARCHITECTURE) -if (!$WindowsArch) { - Write-Host "Only Windows Powershell Core." -ForegroundColor Red; - Start-Sleep -s 0.60 - Exit 1 +elseif ($Arch -eq 'amd64') { + Write-Host -Object 'Running 64-bit PowerShell' -ForegroundColor Green } - elseif ($WindowsArch -eq 'x86' -or $WindowsArch -eq 'Arm32') { - write-Host "Sorry I dont support $WindowsArch" - Start-Sleep -s 0.60 - Exit 1 +elseif ($Arch -eq 'Arm64') { + Write-Host -Object 'Running 64-bit ARM PowerShell' -ForegroundColor Green } +####### +if ($Arch -eq 'Arm64' -or $Arch -eq 'amd64') { + if (Test-Path -Path 'C:\wsaproject') { + Write-Host "I found folder named wsaproject." -ForegroundColor Red + } else { + Write-Host "A folder will be created in the C directory named wsaproject" -ForegroundColor Green + mkdir "C:\wsaproject" + } -Write-Host "This script is for the wsa-gui project." -ForegroundColor Yellow; -Start-Sleep -s 0.70 -write-host "== Script ==" -ForegroundColor Cyan; -write-host $wsldistro $arch $scriptlang $method $wsarelease $magiskversion $amazonstore $wsatools $productname $gappsvariant -write-host "== Windows ==" -ForegroundColor Green; Write-Host $winvmp $windevmode $adb -#################################################################################################################################### -if ($winvmc) { - Write-host "[PREP] I Activate Virtual Machine Platform." - dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart -} + if ( $onlywsaint -eq 0 ) { -if ($adb) { - Write-host "[PREP] ADB." - $Folder = 'C:\src\platform-tools' -if (Test-Path -Path $Folder) { - Write-Host "[PREP] I found folder named platform-tools and deleted it.[ADB]" - Remove-Item C:\src\platform-tools -Recurse -} else { -} -Write-Host "[PREP] I'm downloading platform-tools r33.0.3-windows. [ADB]" -Invoke-WebRequest https://dl.google.com/android/repository/platform-tools_r33.0.3-windows.zip -OutFile c:\src\platform-tools_r33.0.3-windows.zip -Write-Host "[PREP] I unzip platform-tools r33.0.3-windows[ADB]" -Expand-Archive c:\src\platform-tools_r33.0.3-windows.zip -DestinationPath c:\src\platform-tools_r33.0.3-windows -Write-Host "[PREP] I find and extract the main folder[ADB]" -Move-Item -Path c:\src\platform-tools_r33.0.3-windows\platform-tools -Destination c:\src\platform-tools - -Write-Host "[PREP] I delete unnecessary files and folders.[ADB]" -Remove-Item c:\src\platform-tools_r33.0.3-windows.zip -Recurse -Remove-Item c:\src\platform-tools_r33.0.3-windows -Recurse - -$pathContent = [Environment]::GetEnvironmentVariable('Path', 'Machine') -$myPath = 'c:\src\platform-tools' -if ($pathContent -ne $null) -{ - # "Exist in the system!" - if ($pathContent -split ';' -contains $myPath) - { - # My path Exists - Write-Host "[PREP] I don't touch it because the path I will add is already there[ADB]" - } - else - { - Write-Host "[PREP] I add PATH as system. (It is added in the type that every user can use.)[ADB]" - $path = [Environment]::GetEnvironmentVariable('Path', 'Machine') - $newpath = $path + ';c:\src\platform-tools' - [Environment]::SetEnvironmentVariable("Path", $newpath, 'Machine') - Write-Host "[PREP] You may need to close all open CMD, Powershell, Terminal to use it. If it does not appear, restart your computer.[ADB]" - } -} -} + if (Test-Path -Path 'C:\wsa') { + Write-Host "I found folder named wsa." -ForegroundColor Red + } else { + Write-Host "A folder will be created in the C directory named WSA" -ForegroundColor Green + mkdir "C:\wsa" + } + if (Test-Path -Path 'C:\wsaproject\microsoftwsa') { + Write-Host "I found folder named microsoftwsa and delete." -ForegroundColor Red + Remove-Item -Path C:\wsaproject\microsoftwsa\ -Force -Recurse + } else { + } -$wslprep -$wslprep1 = 'sudo sh -c "' -$wslprep2 = '"' -$wslsetup = "&& ./setup.sh " + if ($Arch -eq 'amd64') { + if (Test-Path -Path 'C:\wsa\x64') { + Write-Host "I found folder named amd64 and delete." -ForegroundColor Red + Remove-Item -Path C:\wsa\x64 -Force -Recurse + } -if ( $wsldistro -eq "Ubuntu") { - $wslprep = "cd ~; sudo rm -rf /tmp/wsa*; sudo apt update && sudo apt upgrade -y; sudo apt install -y git curl wget; cd /tmp/; git clone -b beta https://github.com/herrwinfried/wsa-script.git ; cd wsa-script; cd scripts; cd bash; chmod +x ./*.sh " -} + } + elseif ($Arch -eq 'Arm64') { + if (Test-Path -Path 'C:\wsa\arm64') { + Write-Host "I found folder named arm64 and delete." -ForegroundColor Red + Remove-Item -Path C:\wsa\arm64 -Force -Recurse + } + } + if (Test-Path -Path 'C:\wsaproject') { + Write-Host "I found folder named wsaproject and delete." -ForegroundColor Red + Remove-Item -Path C:\wsaproject -Force -Recurse + } -elseif ( $wsldistro -eq "openSUSE-Tumbleweed") { - $wslprep = "cd ~; sudo rm -rf /tmp/wsa*; sudo zypper dup -y; sudo zypper install -y git curl wget; cd /tmp/; git clone -b beta https://github.com/herrwinfried/wsa-script.git ; cd wsa-script; cd scripts; cd bash; chmod +x ./*.sh " + } + if ($vmcint) { + dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart + Clear-Host + } + Clear-Host + if ( $selectos -eq "Ubuntu") { + $prep = "cd ~; sudo rm -rf /tmp/wsaproject; sudo mkdir /tmp/wsaproject; cd /tmp/wsaproject && sudo rm -rf setup.sh && sudo apt update && sudo apt upgrade -y && sudo apt install -y unzip lzip e2fsprogs git wget python3.9 python3-pip && wget https://raw.githubusercontent.com/herrwinfried/wsa-script/1.1.0/setup.sh -O setup.sh && sudo chmod +x ./setup.sh" + $OS = "Ubuntu" + } + + elseif ( $selectos -eq "openSUSE-Tumbleweed") { + $prep = "cd ~; sudo rm -rf /tmp/wsaproject; sudo mkdir /tmp/wsaproject; cd /tmp/wsaproject && sudo rm -rf setup.sh && sudo zypper ref && sudo zypper dup -y && sudo zypper in -y git curl wget lzip unzip e2fsprogs python39 python39-pip && wget https://raw.githubusercontent.com/herrwinfried/wsa-script/1.1.0/setup.sh -O setup.sh && sudo chmod +x ./setup.sh" + $OS = "openSUSE-Tumbleweed" + } + elseif ( $selectos -eq "Debian") { + $prep = "cd ~; sudo rm -rf /tmp/wsaproject; sudo mkdir /tmp/wsaproject; cd /tmp/wsaproject && sudo rm -rf setup.sh && sudo apt update && sudo apt upgrade -y && sudo apt install -y unzip lzip e2fsprogs git wget python3.9 python3-pip && wget https://raw.githubusercontent.com/herrwinfried/wsa-script/1.1.0/setup.sh -O setup.sh && sudo chmod +x ./setup.sh" + $OS = "Debian" + } + else { + Write-Host "cancel the transaction" -ForegroundColor Red + Start-Sleep 2 + exit + } + $setup = "&& ./setup.sh" + if ($Arch -eq 'Arm64') { + $setup = $setup + " --arm" + } + if ( $wsaint -eq "1") { + $setup = $setup + " --wsa" + } + if ( $gappsint -eq "1") + { + $setup = $setup + " --gapps" + } + if ( $gappsvariant -ne "default" ) { + $setup = $setup + " --variant="+$gappsvariant + } + $setup = $setup + " --all-okey" + if ( $Arch -eq 'Arm64' -and $wsatoolsint -eq "1") + { + White-Host "No WSATools Arm support." -ForegroundColor Red + Start-Sleep 2.5 + $wsatoolsint = $False; + $wsatools = $False; + } + elseif ( $Arch -eq 'amd64' -and $wsatoolsint -eq "1") + { + $setup = $setup + " --wsatools" + } + if ( $tempwsaint -eq "1") { + $setup = $setup + " --tempwsa" + } + if ( $tempwsaint -eq "0") { + $setup = $setup + " --no-tempwsa" + } + if ( $onlywsaint -eq "1") { + $setup = $setup + " --wsaonly" + } + $prep1 = 'sudo sh -c "' + $prep2 = '"' + +if ($Arch -eq 'Arm64' -or $Arch -eq 'amd64') { + if (Test-Path -Path 'C:\wsaproject') { + Write-Host "I found folder named wsaproject." + } else { + mkdir "C:\wsaproject" + } + if (Test-Path -Path 'C:\wsa') { + Write-Host "I found folder named wsa." + } else { + mkdir "C:\wsa" + } } -elseif ( $wsldistro -eq "Debian") { - $wslprep = "cd ~; sudo rm -rf /tmp/wsa*; sudo apt update && sudo apt upgrade -y; sudo apt install -y git curl wget; cd /tmp/; git clone -b beta https://github.com/herrwinfried/wsa-script.git ; cd wsa-script; cd scripts; cd bash; chmod +x ./*.sh " -} -else { - $wsldistro="Ubuntu" - $wslprep = "cd ~; sudo rm -rf /tmp/wsa*; sudo apt update && sudo apt upgrade -y; sudo apt install -y git curl wget; cd /tmp/; git clone -b beta https://github.com/herrwinfried/wsa-script.git ; cd wsa-script; cd scripts; cd bash; chmod +x ./*.sh " -} -if ($arch -eq "arm64") { -$wslsetup = $wslsetup + "--arm "; -} -$wslsetup = $wslsetup + "--lang="+$scriptlang+" "; -$wslsetup = $wslsetup + "--"+$method+" "; -$wslsetup = $wslsetup + "--wsarelease="+$wsarelease+" "; -$wslsetup = $wslsetup + "--magiskversion="+$magiskversion+" "; -$wslsetup = $wslsetup + "--amazonstore="+$amazonstore+" "; -$wslsetup = $wslsetup + "--wsatools="+$wsatools+" "; -$wslsetup = $wslsetup + "--productname="+$productname+" "; -$wslsetup = $wslsetup + "--variant="+$gappsvariant+" "; - -Write-Host "WSL will pass, please be careful. If you are asked for a password, please enter your password correctly. If you enter it incorrectly, a mishap may occur." -ForegroundColor Green -Start-Sleep -Seconds 5 Clear-Host -write-host "-d $wsldistro -u root -e $wslprep1 $wslprep $wslsetup $wslprep2" -Start-Sleep -Seconds 1 +if ($Arch -eq 'amd64') { + if (Test-Path -Path 'C:\wsa\x64') { + Write-Host "I found folder named x64." + } else { + mkdir "C:\wsa\x64" + } +} Clear-Host +if ($Arch -eq 'Arm64') { + if (Test-Path -Path 'C:\wsa\arm64') { + Write-Host "I found folder named arm64." + } else { + mkdir "C:\wsa\arm64" + } +} Clear-Host -$runwsl = "wsl -d $wsldistro -u root -e $wslprep1$wslprep$wslsetup$wslprep2" -Invoke-Expression $runwsl || Write-Host "WSL failed to start." -ForegroundColor Red +$runwsl = "wsl -d $OS -e $prep1$prep$setup$prep2" +Invoke-Expression $runwsl -####Finish -exit 1 - -### FFF -if ( ((Get-Host).Version).Major -ne "5" ) -{ - Import-Module -Name Appx -UseWIndowsPowershell -} -if ($method -ne "onlywsa") { - if ($method -eq "wsagascript") { - if ($arch -eq "amd64") { - Set-Location C:\wsa\x64 + if ( $wsatoolsint ) { + Clear-Host + Set-Location "C:\wsaproject" + .\wsatools.ps1 1 } - if ($method -eq "arm64") { - Set-Location C:\wsa\ARM64 + Set-Location "C:\wsaproject" + if ( $wsadevwinint -eq 1 ) { + reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1" + } + if ( $onlywsaint -eq 1 ) { + .\Setup.ps1 1 1 + } else { + .\Setup.ps1 1 } - ./install.ps1 0 0 - - Start-Sleep -s 10 - if ($windevmode) { - Write-host "[Finish.Prep] Windows developer mode and WSA Developer mode are activated." - reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1" + if ( $wsadevwinint -eq 1 ) { + $wsalocation = "$env:LOCALAPPDATA/Packages/MicrosoftCorporationII.WindowsSubsystemForAndroid_8wekyb3d8bbwe/Settings/settings.dat" - $mountPoint = "HKLM\WSA" - reg load $mountPoint $wsalocation - $develbit = "1" - $data = "Windows Registry Editor Version 5.00`n`n" - $data += "[HKEY_LOCAL_MACHINE\WSA]`n`n" - $data += "[HKEY_LOCAL_MACHINE\WSA\LocalState]`n" - $data += "`"DeveloperModeEnabled`"=hex(5f5e10b):0"+ $develbit + ",07,b9,6f,f3,d3,dc,d7,01`n" - $data | Out-File "./wsadevelopermode.reg" - [gc]::collect() - reg import "./wsadevelopermode.reg" - reg unload $mountPoint + $mountPoint = "HKLM\WSA" + reg load $mountPoint $wsalocation + $develbit = "1" + $data = "Windows Registry Editor Version 5.00`n`n" + $data += "[HKEY_LOCAL_MACHINE\WSA]`n`n" + $data += "[HKEY_LOCAL_MACHINE\WSA\LocalState]`n" + $data += "`"DeveloperModeEnabled`"=hex(5f5e10b):0"+ $develbit + ",07,b9,6f,f3,d3,dc,d7,01`n" + $data | Out-File "./wsadevelopermode.reg" + [gc]::collect() + reg import "./wsadevelopermode.reg" + reg unload $mountPoint } - } else { - Set-Location C:\wsa\wsamagisk - ./guiinstall.ps1 - } - -if ($method -eq "onlywsa") { - Set-Location "C:\wsaproject" - Add-AppxPackage Microsoft*WindowsSubsystemForAndroid*.msixbundle -} - -Start-Sleep -s 0.80 -if ($wsatools -eq "yes") { - Set-Location "C:\wsaproject" - add-appxpackage .\WSATools.Msixbundle -} - } - - - -