Skip to content

Commit d774ebb

Browse files
committed
Windows: download the latest adb on demand
1 parent d570a14 commit d774ebb

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

backup-windows.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,43 @@ Write-Output ""
99
pause
1010
# Corrects the cwd if it's different than the script directory
1111
Set-Location -Path $PSScriptRoot
12+
# Ask the user if they want to download the latest ADB platform tools from Google
13+
# 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
14+
# On Linux and macOS adb is managed by the package manager.
15+
$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)"
16+
if ($downloadAdb.ToLower().StartsWith("y")) {
17+
# Delete ./windows-dependencies/adb/ if it exists
18+
if (Test-Path ./windows-dependencies/adb) {
19+
Remove-Item -Recurse -Force ./windows-dependencies/adb
20+
}
21+
# Download the latest adb platform tools from Google
22+
Write-Output "Downloading the latest ADB platform tools..."
23+
Invoke-WebRequest -Uri "https://dl.google.com/android/repository/platform-tools-latest-windows.zip" -OutFile "./windows-dependencies/platform-tools-latest-windows.zip"
24+
# Extract the downloaded zip
25+
Write-Output "Extracting..."
26+
Expand-Archive -Path "./windows-dependencies/platform-tools-latest-windows.zip" -DestinationPath "./windows-dependencies"
27+
# Rename the extracted folder to 'adb'
28+
Rename-Item -Path "./windows-dependencies/platform-tools" -NewName "./windows-dependencies/adb"
29+
# Remove the downloaded zip
30+
Remove-Item -Path "./windows-dependencies/platform-tools-latest-windows.zip"
31+
}
32+
# Update WSL to avoid compatibility issues
1233
Write-Output "Updating WSL..."
1334
wsl --update
1435
wsl --shutdown
1536
wsl sudo apt update
1637
wsl sudo apt dist-upgrade -y
38+
# Install everything we need
1739
Write-Output "Installing dependencies and setting up environment..."
1840
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
41+
# Convert line endings to Unix format, as what Windows uses by default may cause issues
1942
Write-Output "Converting files - this may take several minutes..."
2043
wsl bash -c "sudo find ./ -name '*.sh' -type f -print0 | sudo xargs -0 dos2unix --"
2144
Clear-Host
2245
Write-Output "Ready to run the backup script."
2346
pause
2447
Clear-Host
48+
# Run the 'bootstrapper' script which configures the main script to use the Windows-provided adb.exe
2549
wsl ./windows-dependencies/env-startup.sh
2650
Write-Output Exiting.
2751
pause

0 commit comments

Comments
 (0)