-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.ps1
79 lines (60 loc) · 2.4 KB
/
bootstrap.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
<#
.SYNOPSIS
Bootstrap script to download and set up the dotfiles-windows repository.
.DESCRIPTION
This script downloads the dotfiles-windows repository from GitHub as a ZIP file, extracts it to a specified directory, and prepares it for execution.
.PARAMETER RepositoryUrl
The URL of the GitHub repository to download.
.PARAMETER DestinationPath
The path where the repository will be extracted.
.EXAMPLE
.\bootstrap.ps1
Downloads and extracts the repository to the default path.
#>
[CmdletBinding()]
param (
[string]$RepositoryUrl = 'https://github.com/yourusername/dotfiles-windows/archive/refs/heads/main.zip',
[string]$DestinationPath = "$env:USERPROFILE\dotfiles-windows"
)
function Download-And-ExtractRepo {
param (
[Parameter(Mandatory = $true)]
[string]$RepoUrl,
[Parameter(Mandatory = $true)]
[string]$ExtractPath
)
# Create temporary directory
$tempPath = [System.IO.Path]::GetTempPath()
$zipFile = Join-Path $tempPath "dotfiles-windows.zip"
try {
# Download the ZIP file
Write-Host "Downloading repository from $RepoUrl..."
Invoke-WebRequest -Uri $RepoUrl -OutFile $zipFile -UseBasicParsing
# Create the destination directory if it doesn't exist
if (-not (Test-Path -Path $ExtractPath)) {
New-Item -ItemType Directory -Path $ExtractPath -Force | Out-Null
}
# Extract the ZIP file
Write-Host "Extracting repository to $ExtractPath..."
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipFile, $ExtractPath)
# Clean up the ZIP file
Remove-Item $zipFile -Force
# Move contents up if necessary
$extractedFolder = Join-Path $ExtractPath 'dotfiles-windows-main'
if (Test-Path $extractedFolder) {
Get-ChildItem -Path $extractedFolder -Force | Move-Item -Destination $ExtractPath -Force
Remove-Item $extractedFolder -Force -Recurse
}
Write-Host "Repository downloaded and extracted successfully."
} catch {
Write-Error "An error occurred: $_"
exit 1
}
}
Download-And-ExtractRepo -RepoUrl $RepositoryUrl -ExtractPath $DestinationPath
# Change directory to the destination path
Set-Location $DestinationPath
# Optionally, run the main installation script
Write-Host "Starting installation..."
.\InstallPackages.ps1