Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download the latest adb at runtime on Windows #126

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions backup-windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,43 @@ Write-Output ""
pause
# Corrects the cwd if it's different than the script directory
Set-Location -Path $PSScriptRoot
# Ask the user if they want to download the latest ADB platform tools from Google
# This is done to always have the latest version and lessen the incentive to slip in malware into the repository while still respecting the user's privacy
# On Linux and macOS adb is managed by the package manager.
$downloadAdb = Read-Host "Do you want to download the latest dependencies (adb)? This will connect you to Google's servers. You can safely decline. (y/n)"
if ($downloadAdb.ToLower().StartsWith("y")) {
# Delete ./windows-dependencies/adb/ if it exists
if (Test-Path ./windows-dependencies/adb) {
Remove-Item -Recurse -Force ./windows-dependencies/adb
}
# Download the latest adb platform tools from Google
Write-Output "Downloading the latest ADB platform tools..."
Invoke-WebRequest -Uri "https://dl.google.com/android/repository/platform-tools-latest-windows.zip" -OutFile "./windows-dependencies/platform-tools-latest-windows.zip"
# Extract the downloaded zip
Write-Output "Extracting..."
Expand-Archive -Path "./windows-dependencies/platform-tools-latest-windows.zip" -DestinationPath "./windows-dependencies"
# Rename the extracted folder to 'adb'
Rename-Item -Path "./windows-dependencies/platform-tools" -NewName "./windows-dependencies/adb"
# Remove the downloaded zip
Remove-Item -Path "./windows-dependencies/platform-tools-latest-windows.zip"
}
# Update WSL to avoid compatibility issues
Write-Output "Updating WSL..."
wsl --update
wsl --shutdown
wsl sudo apt update
wsl sudo apt dist-upgrade -y
# Install everything we need
Write-Output "Installing dependencies and setting up environment..."
wsl sudo apt install p7zip-full secure-delete whiptail curl dos2unix pv bc zenity '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev -y
# Convert line endings to Unix format, as what Windows uses by default may cause issues
Write-Output "Converting files - this may take several minutes..."
wsl bash -c "sudo find ./ -name '*.sh' -type f -print0 | sudo xargs -0 dos2unix --"
Clear-Host
Write-Output "Ready to run the backup script."
pause
Clear-Host
# Run the 'bootstrapper' script which configures the main script to use the Windows-provided adb.exe
wsl ./windows-dependencies/env-startup.sh
Write-Output Exiting.
pause
Loading