Last active
May 31, 2024 17:24
-
-
Save Niktendo/6d29cf0568ee5318621552ee1bae65a1 to your computer and use it in GitHub Desktop.
simple platform-tools installer and more
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ErrorActionPreference = "Stop"; | |
| $toolname="platform-tools" | |
| $toolurl='https://dl.google.com/android/repository/platform-tools-latest-linux.zip' | |
| $fileending='.zip' | |
| $host.UI.RawUI.WindowTitle = "Installing $toolname..." | |
| $ErrorActionPreference = "Ignore"; | |
| & ~/$toolname/adb kill-server | |
| $ErrorActionPreference = "Stop"; | |
| Remove-Item "~/$toolname" -Recurse -force -ErrorAction Continue | |
| Invoke-WebRequest "$toolurl" -OutFile (New-Item -Path "~/$toolname$fileending" -Force) | |
| New-Item "~/$toolname" -ItemType "directory" | |
| unzip -oj ~/$toolname$fileending -d ~/$toolname | |
| Remove-Item "~/$toolname$fileending" | |
| $value = "~/$toolname" | |
| $path = [System.Environment]::GetEnvironmentVariable("PATH") | |
| $new = ($path.Split(':') | Where-Object { $_ -ne "$value" }) -join ':' | |
| [System.Environment]::SetEnvironmentVariable("PATH", $new) | |
| [System.Environment]::SetEnvironmentVariable("PATH", $new + ":$value") | |
| Add-Content -Path ~/.bashrc -Value "export PATH=`$HOME/${toolname}:`$PATH" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ErrorActionPreference = "Stop"; | |
| $toolname="PowerShellPreview" | |
| # to use latest | |
| # $toolurl="$(curl -s https://api.github.com/repos/PowerShell/powershell/releases/latest | ConvertFrom-Json | Select-Object -ExpandProperty "assets" | Select-Object -ExpandProperty "browser_download_url" | Select-String -Pattern linux-x64.tar.gz)" | |
| $toolurl="$(curl -s https://api.github.com/repos/PowerShell/powershell/releases | ConvertFrom-Json | Select-Object -ExpandProperty "assets" | Select-Object -ExpandProperty "browser_download_url" | Select-String -Pattern linux-x64.tar.gz | Select-Object -First 1)" | |
| $fileending='.tar.gz' | |
| $host.UI.RawUI.WindowTitle = "Installing $toolname..." | |
| Remove-Item "~/$toolname" -Recurse -force -ErrorAction Continue | |
| Invoke-WebRequest "$toolurl" -OutFile (New-Item -Path "~/$toolname$fileending" -Force) | |
| #Unterschied bei der Extrahierung - striplevel0(files Lvl0) | |
| New-Item "~/$toolname" -ItemType "directory" | |
| tar -xvzf ~/$toolname$fileending -C ~/$toolname | |
| Remove-Item "~/$toolname$fileending" | |
| $value = "~/$toolname" | |
| $path = [System.Environment]::GetEnvironmentVariable("PATH") | |
| $new = ($path.Split(':') | Where-Object { $_ -ne "$value" }) -join ':' | |
| [System.Environment]::SetEnvironmentVariable("PATH", $new) | |
| [System.Environment]::SetEnvironmentVariable("PATH", $new + ":$value") | |
| Add-Content -Path ~/.bashrc -Value "export PATH=`$HOME/${toolname}:`$PATH" | |
| sudo chmod a+x ~/$toolname/pwsh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ErrorActionPreference = "Stop"; | |
| #$params="%*" | |
| $currentuser=[Environment]::Username | |
| $root="Users/$currentuser" | |
| $toolname="platform-tools" | |
| $toolurl='https://dl.google.com/android/repository/platform-tools-latest-darwin.zip' | |
| $fileending='.zip' | |
| $host.UI.RawUI.WindowTitle = "Installing $toolname..." | |
| $ErrorActionPreference = "Ignore"; | |
| & ./$root/$toolname/adb kill-server | |
| $ErrorActionPreference = "Stop"; | |
| Remove-Item "/$root/$toolname" -Recurse -force -ErrorAction Continue | |
| Invoke-WebRequest "$toolurl" -OutFile (New-Item -Path "/$root/$toolname$fileending" -Force) | |
| #Expand-Archive -Force "/$root/$toolname$fileending" "/$root/" | |
| #Unterschied bei der Extrahierung - striplevel1(files Lvl1) | |
| mkdir "/$root/$toolname" | |
| tar -xvzf "/$root/$toolname$fileending" -C "/$root/$toolname" --strip 1 | |
| Remove-Item "/$root/$toolname$fileending" | |
| $value = "/$root/$toolname" | |
| $path = [System.Environment]::GetEnvironmentVariable("PATH") | |
| $new = ($path.Split(':') | Where-Object { $_ -ne "$value" }) -join ':' | |
| [System.Environment]::SetEnvironmentVariable("PATH", $new) | |
| [System.Environment]::SetEnvironmentVariable("PATH", $new + ":$value") | |
| Add-Content -Path ~/.zshrc -Value "export PATH=`$HOME/${toolname}:`$PATH" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ErrorActionPreference = "Stop"; | |
| $toolname="PowerShellPreview" | |
| # to use latest | |
| # $toolurl="$(curl -s https://api.github.com/repos/PowerShell/powershell/releases/latest | ConvertFrom-Json | Select-Object -ExpandProperty "assets" | Select-Object -ExpandProperty "browser_download_url" | Select-String -Pattern osx-x64.tar.gz)" | |
| $toolurl="$(curl -s https://api.github.com/repos/PowerShell/powershell/releases | ConvertFrom-Json | Select-Object -ExpandProperty "assets" | Select-Object -ExpandProperty "browser_download_url" | Select-String -Pattern osx-x64.tar.gz | Select-Object -First 1)" | |
| $fileending='.tar.gz' | |
| $host.UI.RawUI.WindowTitle = "Installing $toolname..." | |
| Remove-Item "~/$toolname" -Recurse -force -ErrorAction Continue | |
| Invoke-WebRequest "$toolurl" -OutFile (New-Item -Path "~/$toolname$fileending" -Force) | |
| #Unterschied bei der Extrahierung - striplevel0(files Lvl0) | |
| New-Item "~/$toolname" -ItemType "directory" | |
| tar -xvzf ~/$toolname$fileending -C ~/$toolname | |
| Remove-Item "~/$toolname$fileending" | |
| $value = "~/$toolname" | |
| $path = [System.Environment]::GetEnvironmentVariable("PATH") | |
| $new = ($path.Split(':') | Where-Object { $_ -ne "$value" }) -join ':' | |
| [System.Environment]::SetEnvironmentVariable("PATH", $new) | |
| [System.Environment]::SetEnvironmentVariable("PATH", $new + ":$value") | |
| Add-Content -Path ~/.zshrc -Value "export PATH=`$HOME/${toolname}:`$PATH" | |
| sudo chmod a+x ~/$toolname/pwsh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo off | |
| cd /d "%~dp0" && ( if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs" ) && fsutil dirty query %systemdrive% 1>nul 2>nul || ( echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "wt", "cmd.exe /k cd ""%~sdp0"" && %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" && "%temp%\getadmin.vbs" && exit /B ) | |
| winget install --id=9P95ZZKTNRN4 -e | |
| pwsh -nop -c "iex(New-Object Net.WebClient).DownloadString('https://gist.githubusercontent.com/Niktendo/6d29cf0568ee5318621552ee1bae65a1/raw/W_download-adb.ps1')" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ErrorActionPreference = "Stop"; | |
| #$params="%*" | |
| $currentuser=[Environment]::Username | |
| $root="$env:HOMEDRIVE" | |
| $toolname="platform-tools" | |
| $toolurl='https://dl.google.com/android/repository/platform-tools-latest-windows.zip' | |
| $fileending='.zip' | |
| $host.UI.RawUI.WindowTitle = "Installing $toolname..." | |
| function Expand-ZIPFile($file, $destination) | |
| { | |
| $shell = new-object -com shell.application | |
| $zip = $shell.NameSpace($file) | |
| foreach($item in $zip.items()) | |
| { | |
| $shell.Namespace($destination).copyhere($item) | |
| } | |
| } | |
| $ErrorActionPreference = "Ignore"; | |
| & $root\$toolname\adb.exe kill-server | |
| $ErrorActionPreference = "Stop"; | |
| Remove-Item "$root\$toolname" -Recurse -force -ErrorAction Continue | |
| (New-Object System.Net.WebClient).DownloadFile("$toolurl", "$env:temp\$toolname$fileending") | |
| Expand-ZipFile "$env:temp\$toolname$fileending" -destination "$root\" | |
| Remove-Item "$env:temp\$toolname$fileending" | |
| $value = "$root\$toolname" | |
| $path = [System.Environment]::GetEnvironmentVariable("PATH", [EnvironmentVariableTarget]::User) | |
| $new = ($path.Split(';') | Where-Object { $_ -ne "$value" }) -join ';' | |
| [System.Environment]::SetEnvironmentVariable("PATH", $new, [EnvironmentVariableTarget]::User) | |
| [System.Environment]::SetEnvironmentVariable("PATH", $new + ";$value", [EnvironmentVariableTarget]::User) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { | |
| exit; | |
| } | |
| $ErrorActionPreference = "Stop"; | |
| #$params="%*" | |
| $currentuser=[Environment]::Username | |
| $root="$env:HOMEDRIVE" | |
| $toolname="platform-tools" | |
| $toolurl='https://dl.google.com/android/repository/platform-tools-latest-windows.zip' | |
| $fileending='.zip' | |
| $host.UI.RawUI.WindowTitle = "Installing $toolname..." | |
| $ErrorActionPreference = "Ignore"; | |
| & $root\$toolname\adb.exe kill-server | |
| $ErrorActionPreference = "Stop"; | |
| Remove-Item "$root\$toolname" -Recurse -force -ErrorAction Continue | |
| Invoke-WebRequest "$toolurl" -OutFile "$env:temp\$toolname$fileending" | |
| #Expand-Archive -Force "$env:temp\platform-tools.zip" "$env:HOMEDRIVE\" | |
| mkdir "$root\$toolname" | |
| tar -xvzf "$env:temp\$toolname$fileending" -C "$root\$toolname" --strip 1 | |
| Remove-Item "$env:temp\$toolname$fileending" | |
| $value = "$root\$toolname" | |
| $path = [System.Environment]::GetEnvironmentVariable("PATH", [EnvironmentVariableTarget]::Machine) | |
| $new = ($path.Split(';') | Where-Object { $_ -ne "$value" }) -join ';' | |
| [System.Environment]::SetEnvironmentVariable("PATH", $new, [EnvironmentVariableTarget]::Machine) | |
| [System.Environment]::SetEnvironmentVariable("PATH", $new + ";$value", [EnvironmentVariableTarget]::Machine) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ErrorActionPreference = "Stop"; | |
| #$params="%*" | |
| $currentuser=[Environment]::Username | |
| $root="$env:HOMEDRIVE" | |
| $toolname="platform-tools" | |
| $toolurl='https://dl.google.com/android/repository/platform-tools-latest-windows.zip' | |
| $fileending='.zip' | |
| $host.UI.RawUI.WindowTitle = "Installing $toolname..." | |
| & $root\$toolname\adb.exe kill-server | |
| Remove-Item "$root\$toolname" -Recurse -force -ErrorAction Continue | |
| Invoke-WebRequest "$toolurl" -OutFile "$env:temp\$toolname$fileending" | |
| #Expand-Archive -Force "$env:temp\platform-tools.zip" "$env:HOMEDRIVE\" | |
| mkdir "$root\$toolname" | |
| tar -xvzf "$env:temp\$toolname$fileending" -C "$root\$toolname" --strip 1 | |
| Remove-Item "$env:temp\$toolname$fileending" | |
| $value = "$root\$toolname" | |
| $path = [System.Environment]::GetEnvironmentVariable("PATH", [EnvironmentVariableTarget]::User) | |
| $new = ($path.Split(';') | Where-Object { $_ -ne "$value" }) -join ';' | |
| [System.Environment]::SetEnvironmentVariable("PATH", $new, [EnvironmentVariableTarget]::User) | |
| [System.Environment]::SetEnvironmentVariable("PATH", $new + ";$value", [EnvironmentVariableTarget]::User) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { | |
| exit; | |
| } | |
| $ErrorActionPreference = "Stop"; | |
| #$params="%*" | |
| $currentuser=[Environment]::Username | |
| $root="$env:HOMEDRIVE" | |
| $toolname="scrcpy" | |
| $content = ConvertFrom-Json $(Invoke-WebRequest -UseBasicParsing https://api.github.com/repos/Genymobile/scrcpy/releases); [string] $toolurl = ($content | Select-Object -ExpandProperty "assets" | Select-Object -ExpandProperty "browser_download_url" | Select-String -Pattern scrcpy-win64 | Select-Object -First 1); $filename = "$(Split-Path $toolurl -Leaf)" | |
| $host.UI.RawUI.WindowTitle = "Installing $toolname..." | |
| Invoke-WebRequest "$toolurl" -OutFile "$env:temp\$filename" | |
| #Expand-Archive -Force "$env:temp\platform-tools.zip" "$env:HOMEDRIVE\" | |
| mkdir "$root\$toolname" | |
| tar -xvzf "$env:temp\$filename" -C "$root\$toolname" --strip 1 | |
| Remove-Item "$env:temp\$filename" | |
| $value = "$root\$toolname" | |
| $path = [System.Environment]::GetEnvironmentVariable("PATH", [EnvironmentVariableTarget]::Machine) | |
| $new = ($path.Split(';') | Where-Object { $_ -ne "$value" }) -join ';' | |
| [System.Environment]::SetEnvironmentVariable("PATH", $new, [EnvironmentVariableTarget]::Machine) | |
| [System.Environment]::SetEnvironmentVariable("PATH", $new + ";$value", [EnvironmentVariableTarget]::Machine) | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
MacOS-Editionen sind unabhängiger, eher variablenbasiert.
MacOS-Editionen arbeiten mit dem temporären PowerShellCore-Umgebungsvariablen.
2 unterschiedliche Machanismen:
ADB-Installer: Beispiel für Tool, welches $toolname$fileending>ZuextrahierenderOrdner(zufällig=$toolname)>files
-> Extrahieren durch simples Extrahieren des ZuextrahierenderOrdner in $root
PowerShell-Installer: Beispiel für Tool, welches $toolname$fileending>files
-> Extrahieren durch anpassen von $root durch $root+gewünschterOrdner