refactor: finish moving ssh-* scripts to own installers
[webi-installers/.git] / nerdfont / install.ps1
1 #!/bin/pwsh
2
3 $my_nerdfont_otf = "Droid Sans Mono for Powerline Nerd Font Complete Windows Compatible.otf"
4 $my_fontdir = "$Env:UserProfile\AppData\Local\Microsoft\Windows\Fonts"
5
6 New-Item -Path "$my_fontdir" -ItemType Directory -Force | out-null
7 IF (!(Test-Path -Path "$my_fontdir\$my_nerdfont_otf"))
8 {
9     & curl.exe -fsSLo "$my_nerdfont_otf" 'https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/DroidSansMono/complete/Droid%20Sans%20Mono%20Nerd%20Font%20Complete%20Windows%20Compatible.otf'
10     & move "$my_nerdfont_otf" "$my_fontdir"
11 }
12
13
14 pushd "$my_fontdir"
15
16 $regFontPath = "\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"
17 $fontRegistryPath = "HKCU:$regFontPath"
18 $fontFiles = Get-ChildItem -Recurse -Include *.ttf, *.otf
19 foreach($font in $fontFiles) {
20     # See https://github.com/PPOSHGROUP/PPoShTools/blob/master/PPoShTools/Public/FileSystem/Add-Font.ps1#L80
21     Add-Type -AssemblyName System.Drawing
22     $objFontCollection = New-Object System.Drawing.Text.PrivateFontCollection
23     $objFontCollection.AddFontFile($font.FullName)
24     $FontName = $objFontCollection.Families.Name
25
26     $regTest = Get-ItemProperty -Path $fontRegistryPath -Name "*$FontName*" -ErrorAction SilentlyContinue
27     if (-not ($regTest)) {
28         New-ItemProperty -Name $FontName -Path $fontRegistryPath -PropertyType string -Value $font.Name
29         Write-Output "Registered font {$($font.Name)} in Current User registry as {$FontName}"
30     }
31     echo "Installed $my_nerdfont_otf to $my_fontdir"
32     # because adding to the registry alone doesn't actually take
33     & start $font.FullName
34     echo ""
35     echo "IMPORTANT: Click 'Install' to complete installation"
36 }