-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbootstrap-windows.ps1
More file actions
92 lines (76 loc) · 2 KB
/
bootstrap-windows.ps1
File metadata and controls
92 lines (76 loc) · 2 KB
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
#Requires -Version 5.1
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
function main() {
New-Item -ItemType Directory -Force "$HOME/.bootstrap" >$null
# Install essential commands.
if (iscmd scoop) {
log 'Already installed Scoop'
}
else {
log 'Installing Scoop'
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
scoop install git
}
updatesystem
# Install hyperupcall/dotfiles.
clonerepo 'https://github.com/hyperupcall/dotfiles' "$HOME/.dotfiles"
Push-Location "$HOME/.dotfiles"
git remote set-url me 'git@github.com:hyperupcall/dotfiles'
Pop-Location
# Symlink ~/scripts.
New-Item -Type SymbolicLink -Force -Path "$HOME/scripts" -Value "$HOME/.dotfiles/windows-scripts" >$null
# Export variables.
Write-Output @"
`$Env:NAME = 'Edwin Kofler'
`$Env:EMAIL = 'edwin@kofler.dev'
`$Env:EDITOR = 'nvim'
`$Env:VISUAL = "`$Env:EDITOR"
`$Env:Path = "`$HOME/.dotfiles/.data/bin;`$Env:Path"
"@ | Out-File -FilePath "$HOME/.bootstrap/bootstrap-out.ps1"
}
function die([string]$message) {
error "$message"
[Console]::Error.WriteLine("=> Exiting")
exit 1
}
function error([string]$message) {
[Console]::Error.WriteLine("=> Error: $message")
}
function log([string]$message) {
Write-Output "=> Info: $message"
}
function iscmd([string]$command) {
Get-Command "$command" -ErrorAction SilentlyContinue
}
function updatesystem() {
scoop update
}
function installcmd([string]$command) {
scoop info "$command" >$null
if ($?) {
log "Already installed $command"
}
else {
log "Installing $command"
scoop install "$command"
scoop info "$command" >$null
if (!($?)) {
die "Automatic installation of $command failed"
}
}
}
function clonerepo([string]$uri, [string]$directory) {
if (Test-Path -Path $directory) {
log "Already cloned $uri"
}
else {
log "Cloning $uri"
git clone --quiet "$uri" "$directory" --recurse-submodules
[array] $git_remote = git -C "$directory" remote
if ($git_remote[0] -eq 'origin') {
git -C "$directory" remote rename origin me
}
}
}
main