-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstaller.ps1
71 lines (58 loc) · 2.46 KB
/
installer.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
# First time installation for new Windows system.
# TODO: review paths and refactor
# TODO: review Setup.ps1 and merge
# function mklink {
# cmd /c mklink $args
# # cmd /c mklink c:\path\to\symlink c:\target\file
# # must pass /d if path to is a directory
# # cmd /c mklink /d c:\path\to\symlink c:\target\directory
# }
# # powershell version
# function make-link ($target, $link) {
# # Junction (for directory)
# New-Item -Path $link -ItemType SymbolicLink -Value $target
# }
$DownloadResult = $FALSE;
try
{
git | Out-Null
git clone https://github.com/kylejb/dotfiles $HOME\.dotfiles
$DownloadResult = $TRUE;
}
catch [System.Management.Automation.CommandNotFoundException] {
$GitHubRepositoryUri = "https://github.com/${GitHubRepositoryAuthor}/${GitHubRepositoryName}/archive/refs/heads/main.zip";
$DotfilesFolder = Join-Path -Path $HOME -ChildPath ".dotfiles";
$ZipRepositoryFile = Join-Path -Path $DotfilesFolder -ChildPath "${GitHubRepositoryName}-main.zip";
$DotfilesWorkFolder = Join-Path -Path $DotfilesFolder -ChildPath "${GitHubRepositoryName}-main"
# Request custom values
$ComputerName = Read-Host -Prompt "Input the new computer name here";
$GitUserName = Read-Host -Prompt "Input your Git user name here";
$GitUserEmail = Read-Host -Prompt "Input your Git user email here";
$ValidDisks = Get-PSDrive -PSProvider "FileSystem" | Select-Object -ExpandProperty "Root";
do {
Write-Host "Choose the location of your development workspace:" -ForegroundColor "Green";
Write-Host $ValidDisks -ForegroundColor "Green";
$WorkspaceDisk = Read-Host -Prompt "Please choose one of the available disks";
}
while (-not ($ValidDisks -Contains $WorkspaceDisk));
# Create Dotfiles folder
if (Test-Path $DotfilesFolder) {
Remove-Item -Path $DotfilesFolder -Recurse -Force;
}
New-Item $DotfilesFolder -ItemType directory;
# Download Dotfiles repository as Zip
try {
Invoke-WebRequest $GitHubRepositoryUri -O $ZipRepositoryFile;
$DownloadResult = $TRUE;
}
catch [System.Net.WebException] {
Write-Host "Error connecting to GitHub, check the internet connection or the repository url." -ForegroundColor "Red";
}
if ($DownloadResult) {
Add-Type -AssemblyName System.IO.Compression.FileSystem;
[System.IO.Compression.ZipFile]::ExtractToDirectory($ZipRepositoryFile, $DotfilesFolder);
}
}
# Run setup
Set-Location $HOME\.dotfiles
.\Setup.ps1