-
Notifications
You must be signed in to change notification settings - Fork 1
/
init-windows.ps1
105 lines (87 loc) · 3.14 KB
/
init-windows.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<#
.SYNOPSIS
This script downloads, extracts, and sets up a repository from GitHub into the user's home directory.
.DESCRIPTION
The script performs the following steps:
1. Checks if the script is being run with administrative privileges.
2. Downloads a specified repository from GitHub as a zip file.
3. Extracts the contents of the zip file to a temporary directory.
4. Copies the extracted contents to the `~/.setup` directory.
5. Runs an installation script located in the `windows` subdirectory of the extracted contents.
6. Starts a new PowerShell session with no logo.
.PARAMETER None
This script does not accept any parameters.
.EXAMPLE
.\setup.ps1
Runs the script to download, extract, and set up the repository.
.NOTES
Author: Robb Currall
Date: 2024-08-15
Version: 1.0
.LINK
https://github.com/rlcurrall/setup
#>
$currentUser = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$isAdmin = $currentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin)
{
Write-Error "Please run this as an admin"
exit
}
$account = "rlcurrall"
$repo = "setup"
$branch = "main"
$downloadUrl = "https://github.com/$account/$repo/archive/$branch.zip"
$setupDir = Join-Path $HOME ".setup"
$downloadsDir = Join-Path $HOME "Downloads"
$sourceFile = Join-Path $downloadsDir "setup.zip"
$extractDir = Join-Path $downloadsDir "$repo-$branch"
if (![System.IO.Directory]::Exists($setupDir))
{
[System.IO.Directory]::CreateDirectory($setupDir)
}
# Download zip of repository
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri $downloadUrl -OutFile $sourceFile
# Unzip the repository
$filePath = Resolve-Path $sourceFile
$destinationPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($downloadsDir)
If (($PSVersionTable.PSVersion.Major -ge 3) -and
(
[version](Get-ItemProperty -Path "HKLM:\Software\Microsoft\NET Framework Setup\NDP\v4\Full" -ErrorAction SilentlyContinue).Version -ge [version]"4.5" -or
[version](Get-ItemProperty -Path "HKLM:\Software\Microsoft\NET Framework Setup\NDP\v4\Client" -ErrorAction SilentlyContinue).Version -ge [version]"4.5"
))
{
try
{
[System.Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem") | Out-Null
[System.IO.Compression.ZipFile]::ExtractToDirectory("$filePath", "$destinationPath")
} catch
{
Write-Error -Message "Unexpected Error. Error details: $_.Exception.Message"
exit
}
} else
{
try
{
$shell = New-Object -ComObject Shell.Application
$shell.Namespace($destinationPath).copyhere(($shell.NameSpace($filePath)).items())
} catch
{
Write-Error -Message "Unexpected Error. Error details: $_.Exception.Message"
exit
}
}
# Copy files to the `~/.setup` folder
Push-Location $extractDir
Copy-Item * -Destination $setupDir -Recurse -Force
Pop-Location
# Run install script
Push-Location $setupDir
& .\windows\install.ps1
Pop-Location
$newProcess = New-Object System.Diagnostics.ProcessStartInfo "pwsh";
$newProcess.Arguments = "-nologo";
[System.Diagnostics.Process]::Start($newProcess);
exit