Skip to content

Commit

Permalink
Merge pull request #161 from jonz94/font-installation-for-non-admin-user
Browse files Browse the repository at this point in the history
Allow font installation for non-admin user

- Install fonts into user's font directory `$env:LOCALAPPDATA\Microsoft\Windows\Fonts` (administrator rights are **not** required)
    - This feature required Windows 10 version 1809 and above (build number >= `17763`)
    - Fallback to install fonts into system fonts directory `$env:windir\Fonts` if Windows version is before 1809 (administrator rights are required)

- Add support for scoop global installation (e.g. `scoop install -g SarasaGothic-ttc`)
    - When `-g` is provided, the fonts will be installed into system fonts directory `$env:windir\Fonts` (administrator rights are required)

- Remove `sudo` as dependency

And thanks to linyinfeng's information (#10 (comment)) for the inspiration of this commit
  • Loading branch information
jonz94 committed Nov 27, 2021
2 parents 11a7306 + 85c5771 commit 4e9ef12
Show file tree
Hide file tree
Showing 190 changed files with 5,529 additions and 1,735 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ To add this bucket:
scoop bucket add nerd-fonts
```

#### Note: Admin rights are required to install these fonts, because their installers modify the registry. Additionally, restarting your computer after uninstalling a font is necessary for the font to be fully removed.
#### Note: Admin rights are required to install these fonts for Windows version before Windows 10 1809, because their installers modify the `HKEY_LOCAL_MACHINE` registry. Additionally, restarting your computer after uninstalling a font is necessary for the font to be fully removed.

## Generating font manifests

Expand Down
39 changes: 30 additions & 9 deletions bucket/3270-NF-Mono.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,46 @@
"url": "https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/3270.zip",
"hash": "b39bb03a46bf51cacf094a53d9f07c090ede4571efa2c24600c66a25a3fee1cc",
"checkver": "github",
"depends": "sudo",
"autoupdate": {
"url": "https://github.com/ryanoasis/nerd-fonts/releases/download/v$version/3270.zip"
},
"installer": {
"script": [
"if(!(is_admin)) { error \"Admin rights are required, please run 'sudo scoop install $app'\"; exit 1 }",
"Get-ChildItem $dir -filter '*Mono Windows Compatible.*' | ForEach-Object {",
" New-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts' -Name $_.Name.Replace($_.Extension, ' (TrueType)') -Value $_.Name -Force | Out-Null",
" Copy-Item $_.FullName -destination \"$env:windir\\Fonts\"",
"$currentBuildNumber = [int] (Get-ItemProperty \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\").CurrentBuildNumber",
"$windows1809BuildNumber = 17763",
"$isPerUserFontInstallationSupported = $currentBuildNumber -ge $windows1809BuildNumber",
"$isFontInstallationForAllUsers = $global -or !$isPerUserFontInstallationSupported",
"if ($isFontInstallationForAllUsers -and !(is_admin)) {",
" error \"Administrator rights are required to install $app.\"",
" exit 1",
"}",
"$fontInstallDir = if ($isFontInstallationForAllUsers) { \"$env:windir\\Fonts\" } else { \"$env:LOCALAPPDATA\\Microsoft\\Windows\\Fonts\" }",
"$registryRoot = if ($isFontInstallationForAllUsers) { \"HKLM\" } else { \"HKCU\" }",
"$registryKey = \"${registryRoot}:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\"",
"New-Item $fontInstallDir -ItemType Directory -ErrorAction SilentlyContinue | Out-Null",
"Get-ChildItem $dir -Filter '*Mono Windows Compatible.*' | ForEach-Object {",
" $value = if ($isFontInstallationForAllUsers) { $_.Name } else { \"$fontInstallDir\\$($_.Name)\" }",
" New-ItemProperty -Path $registryKey -Name $_.Name.Replace($_.Extension, ' (TrueType)') -Value $value -Force | Out-Null",
" Copy-Item $_.FullName -Destination $fontInstallDir",
"}"
]
},
"uninstaller": {
"script": [
"if(!(is_admin)) { error \"Admin rights are required, please run 'sudo scoop uninstall $app'\"; exit 1 }",
"Get-ChildItem $dir -filter '*Mono Windows Compatible.*' | ForEach-Object {",
" Remove-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts' -Name $_.Name.Replace($_.Extension, ' (TrueType)') -Force -ErrorAction SilentlyContinue",
" Remove-Item \"$env:windir\\Fonts\\$($_.Name)\" -Force -ErrorAction SilentlyContinue",
"$currentBuildNumber = [int] (Get-ItemProperty \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\").CurrentBuildNumber",
"$windows1809BuildNumber = 17763",
"$isPerUserFontInstallationSupported = $currentBuildNumber -ge $windows1809BuildNumber",
"$isFontInstallationForAllUsers = $global -or !$isPerUserFontInstallationSupported",
"if ($isFontInstallationForAllUsers -and !(is_admin)) {",
" error \"Administrator rights are required to uninstall $app.\"",
" exit 1",
"}",
"$fontInstallDir = if ($isFontInstallationForAllUsers) { \"$env:windir\\Fonts\" } else { \"$env:LOCALAPPDATA\\Microsoft\\Windows\\Fonts\" }",
"$registryRoot = if ($isFontInstallationForAllUsers) { \"HKLM\" } else { \"HKCU\" }",
"$registryKey = \"${registryRoot}:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\"",
"Get-ChildItem $dir -Filter '*Mono Windows Compatible.*' | ForEach-Object {",
" Remove-ItemProperty -Path $registryKey -Name $_.Name.Replace($_.Extension, ' (TrueType)') -Force -ErrorAction SilentlyContinue",
" Remove-Item \"$fontInstallDir\\$($_.Name)\" -Force -ErrorAction SilentlyContinue",
"}",
"Write-Host \"The '$($app.Replace('-NF', ''))' Font family has been uninstalled and will not be present after restarting your computer.\" -Foreground Magenta"
]
Expand Down
39 changes: 30 additions & 9 deletions bucket/3270-NF.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,46 @@
"url": "https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/3270.zip",
"hash": "b39bb03a46bf51cacf094a53d9f07c090ede4571efa2c24600c66a25a3fee1cc",
"checkver": "github",
"depends": "sudo",
"autoupdate": {
"url": "https://github.com/ryanoasis/nerd-fonts/releases/download/v$version/3270.zip"
},
"installer": {
"script": [
"if(!(is_admin)) { error \"Admin rights are required, please run 'sudo scoop install $app'\"; exit 1 }",
"Get-ChildItem $dir -filter '*Complete Windows Compatible.*' | ForEach-Object {",
" New-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts' -Name $_.Name.Replace($_.Extension, ' (TrueType)') -Value $_.Name -Force | Out-Null",
" Copy-Item $_.FullName -destination \"$env:windir\\Fonts\"",
"$currentBuildNumber = [int] (Get-ItemProperty \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\").CurrentBuildNumber",
"$windows1809BuildNumber = 17763",
"$isPerUserFontInstallationSupported = $currentBuildNumber -ge $windows1809BuildNumber",
"$isFontInstallationForAllUsers = $global -or !$isPerUserFontInstallationSupported",
"if ($isFontInstallationForAllUsers -and !(is_admin)) {",
" error \"Administrator rights are required to install $app.\"",
" exit 1",
"}",
"$fontInstallDir = if ($isFontInstallationForAllUsers) { \"$env:windir\\Fonts\" } else { \"$env:LOCALAPPDATA\\Microsoft\\Windows\\Fonts\" }",
"$registryRoot = if ($isFontInstallationForAllUsers) { \"HKLM\" } else { \"HKCU\" }",
"$registryKey = \"${registryRoot}:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\"",
"New-Item $fontInstallDir -ItemType Directory -ErrorAction SilentlyContinue | Out-Null",
"Get-ChildItem $dir -Filter '*Complete Windows Compatible.*' | ForEach-Object {",
" $value = if ($isFontInstallationForAllUsers) { $_.Name } else { \"$fontInstallDir\\$($_.Name)\" }",
" New-ItemProperty -Path $registryKey -Name $_.Name.Replace($_.Extension, ' (TrueType)') -Value $value -Force | Out-Null",
" Copy-Item $_.FullName -Destination $fontInstallDir",
"}"
]
},
"uninstaller": {
"script": [
"if(!(is_admin)) { error \"Admin rights are required, please run 'sudo scoop uninstall $app'\"; exit 1 }",
"Get-ChildItem $dir -filter '*Complete Windows Compatible.*' | ForEach-Object {",
" Remove-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts' -Name $_.Name.Replace($_.Extension, ' (TrueType)') -Force -ErrorAction SilentlyContinue",
" Remove-Item \"$env:windir\\Fonts\\$($_.Name)\" -Force -ErrorAction SilentlyContinue",
"$currentBuildNumber = [int] (Get-ItemProperty \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\").CurrentBuildNumber",
"$windows1809BuildNumber = 17763",
"$isPerUserFontInstallationSupported = $currentBuildNumber -ge $windows1809BuildNumber",
"$isFontInstallationForAllUsers = $global -or !$isPerUserFontInstallationSupported",
"if ($isFontInstallationForAllUsers -and !(is_admin)) {",
" error \"Administrator rights are required to uninstall $app.\"",
" exit 1",
"}",
"$fontInstallDir = if ($isFontInstallationForAllUsers) { \"$env:windir\\Fonts\" } else { \"$env:LOCALAPPDATA\\Microsoft\\Windows\\Fonts\" }",
"$registryRoot = if ($isFontInstallationForAllUsers) { \"HKLM\" } else { \"HKCU\" }",
"$registryKey = \"${registryRoot}:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\"",
"Get-ChildItem $dir -Filter '*Complete Windows Compatible.*' | ForEach-Object {",
" Remove-ItemProperty -Path $registryKey -Name $_.Name.Replace($_.Extension, ' (TrueType)') -Force -ErrorAction SilentlyContinue",
" Remove-Item \"$fontInstallDir\\$($_.Name)\" -Force -ErrorAction SilentlyContinue",
"}",
"Write-Host \"The '$($app.Replace('-NF', ''))' Font family has been uninstalled and will not be present after restarting your computer.\" -Foreground Magenta"
]
Expand Down
39 changes: 30 additions & 9 deletions bucket/Agave-NF-Mono.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,46 @@
"url": "https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/Agave.zip",
"hash": "0a6a5f056553cd8fa0c95dc57b0cdf027ff2f49016d0c470386bb2ba7918f549",
"checkver": "github",
"depends": "sudo",
"autoupdate": {
"url": "https://github.com/ryanoasis/nerd-fonts/releases/download/v$version/Agave.zip"
},
"installer": {
"script": [
"if(!(is_admin)) { error \"Admin rights are required, please run 'sudo scoop install $app'\"; exit 1 }",
"Get-ChildItem $dir -filter '*Mono Windows Compatible.*' | ForEach-Object {",
" New-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts' -Name $_.Name.Replace($_.Extension, ' (TrueType)') -Value $_.Name -Force | Out-Null",
" Copy-Item $_.FullName -destination \"$env:windir\\Fonts\"",
"$currentBuildNumber = [int] (Get-ItemProperty \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\").CurrentBuildNumber",
"$windows1809BuildNumber = 17763",
"$isPerUserFontInstallationSupported = $currentBuildNumber -ge $windows1809BuildNumber",
"$isFontInstallationForAllUsers = $global -or !$isPerUserFontInstallationSupported",
"if ($isFontInstallationForAllUsers -and !(is_admin)) {",
" error \"Administrator rights are required to install $app.\"",
" exit 1",
"}",
"$fontInstallDir = if ($isFontInstallationForAllUsers) { \"$env:windir\\Fonts\" } else { \"$env:LOCALAPPDATA\\Microsoft\\Windows\\Fonts\" }",
"$registryRoot = if ($isFontInstallationForAllUsers) { \"HKLM\" } else { \"HKCU\" }",
"$registryKey = \"${registryRoot}:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\"",
"New-Item $fontInstallDir -ItemType Directory -ErrorAction SilentlyContinue | Out-Null",
"Get-ChildItem $dir -Filter '*Mono Windows Compatible.*' | ForEach-Object {",
" $value = if ($isFontInstallationForAllUsers) { $_.Name } else { \"$fontInstallDir\\$($_.Name)\" }",
" New-ItemProperty -Path $registryKey -Name $_.Name.Replace($_.Extension, ' (TrueType)') -Value $value -Force | Out-Null",
" Copy-Item $_.FullName -Destination $fontInstallDir",
"}"
]
},
"uninstaller": {
"script": [
"if(!(is_admin)) { error \"Admin rights are required, please run 'sudo scoop uninstall $app'\"; exit 1 }",
"Get-ChildItem $dir -filter '*Mono Windows Compatible.*' | ForEach-Object {",
" Remove-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts' -Name $_.Name.Replace($_.Extension, ' (TrueType)') -Force -ErrorAction SilentlyContinue",
" Remove-Item \"$env:windir\\Fonts\\$($_.Name)\" -Force -ErrorAction SilentlyContinue",
"$currentBuildNumber = [int] (Get-ItemProperty \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\").CurrentBuildNumber",
"$windows1809BuildNumber = 17763",
"$isPerUserFontInstallationSupported = $currentBuildNumber -ge $windows1809BuildNumber",
"$isFontInstallationForAllUsers = $global -or !$isPerUserFontInstallationSupported",
"if ($isFontInstallationForAllUsers -and !(is_admin)) {",
" error \"Administrator rights are required to uninstall $app.\"",
" exit 1",
"}",
"$fontInstallDir = if ($isFontInstallationForAllUsers) { \"$env:windir\\Fonts\" } else { \"$env:LOCALAPPDATA\\Microsoft\\Windows\\Fonts\" }",
"$registryRoot = if ($isFontInstallationForAllUsers) { \"HKLM\" } else { \"HKCU\" }",
"$registryKey = \"${registryRoot}:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\"",
"Get-ChildItem $dir -Filter '*Mono Windows Compatible.*' | ForEach-Object {",
" Remove-ItemProperty -Path $registryKey -Name $_.Name.Replace($_.Extension, ' (TrueType)') -Force -ErrorAction SilentlyContinue",
" Remove-Item \"$fontInstallDir\\$($_.Name)\" -Force -ErrorAction SilentlyContinue",
"}",
"Write-Host \"The '$($app.Replace('-NF', ''))' Font family has been uninstalled and will not be present after restarting your computer.\" -Foreground Magenta"
]
Expand Down
39 changes: 30 additions & 9 deletions bucket/Agave-NF.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,46 @@
"url": "https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/Agave.zip",
"hash": "0a6a5f056553cd8fa0c95dc57b0cdf027ff2f49016d0c470386bb2ba7918f549",
"checkver": "github",
"depends": "sudo",
"autoupdate": {
"url": "https://github.com/ryanoasis/nerd-fonts/releases/download/v$version/Agave.zip"
},
"installer": {
"script": [
"if(!(is_admin)) { error \"Admin rights are required, please run 'sudo scoop install $app'\"; exit 1 }",
"Get-ChildItem $dir -filter '*Complete Windows Compatible.*' | ForEach-Object {",
" New-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts' -Name $_.Name.Replace($_.Extension, ' (TrueType)') -Value $_.Name -Force | Out-Null",
" Copy-Item $_.FullName -destination \"$env:windir\\Fonts\"",
"$currentBuildNumber = [int] (Get-ItemProperty \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\").CurrentBuildNumber",
"$windows1809BuildNumber = 17763",
"$isPerUserFontInstallationSupported = $currentBuildNumber -ge $windows1809BuildNumber",
"$isFontInstallationForAllUsers = $global -or !$isPerUserFontInstallationSupported",
"if ($isFontInstallationForAllUsers -and !(is_admin)) {",
" error \"Administrator rights are required to install $app.\"",
" exit 1",
"}",
"$fontInstallDir = if ($isFontInstallationForAllUsers) { \"$env:windir\\Fonts\" } else { \"$env:LOCALAPPDATA\\Microsoft\\Windows\\Fonts\" }",
"$registryRoot = if ($isFontInstallationForAllUsers) { \"HKLM\" } else { \"HKCU\" }",
"$registryKey = \"${registryRoot}:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\"",
"New-Item $fontInstallDir -ItemType Directory -ErrorAction SilentlyContinue | Out-Null",
"Get-ChildItem $dir -Filter '*Complete Windows Compatible.*' | ForEach-Object {",
" $value = if ($isFontInstallationForAllUsers) { $_.Name } else { \"$fontInstallDir\\$($_.Name)\" }",
" New-ItemProperty -Path $registryKey -Name $_.Name.Replace($_.Extension, ' (TrueType)') -Value $value -Force | Out-Null",
" Copy-Item $_.FullName -Destination $fontInstallDir",
"}"
]
},
"uninstaller": {
"script": [
"if(!(is_admin)) { error \"Admin rights are required, please run 'sudo scoop uninstall $app'\"; exit 1 }",
"Get-ChildItem $dir -filter '*Complete Windows Compatible.*' | ForEach-Object {",
" Remove-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts' -Name $_.Name.Replace($_.Extension, ' (TrueType)') -Force -ErrorAction SilentlyContinue",
" Remove-Item \"$env:windir\\Fonts\\$($_.Name)\" -Force -ErrorAction SilentlyContinue",
"$currentBuildNumber = [int] (Get-ItemProperty \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\").CurrentBuildNumber",
"$windows1809BuildNumber = 17763",
"$isPerUserFontInstallationSupported = $currentBuildNumber -ge $windows1809BuildNumber",
"$isFontInstallationForAllUsers = $global -or !$isPerUserFontInstallationSupported",
"if ($isFontInstallationForAllUsers -and !(is_admin)) {",
" error \"Administrator rights are required to uninstall $app.\"",
" exit 1",
"}",
"$fontInstallDir = if ($isFontInstallationForAllUsers) { \"$env:windir\\Fonts\" } else { \"$env:LOCALAPPDATA\\Microsoft\\Windows\\Fonts\" }",
"$registryRoot = if ($isFontInstallationForAllUsers) { \"HKLM\" } else { \"HKCU\" }",
"$registryKey = \"${registryRoot}:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\"",
"Get-ChildItem $dir -Filter '*Complete Windows Compatible.*' | ForEach-Object {",
" Remove-ItemProperty -Path $registryKey -Name $_.Name.Replace($_.Extension, ' (TrueType)') -Force -ErrorAction SilentlyContinue",
" Remove-Item \"$fontInstallDir\\$($_.Name)\" -Force -ErrorAction SilentlyContinue",
"}",
"Write-Host \"The '$($app.Replace('-NF', ''))' Font family has been uninstalled and will not be present after restarting your computer.\" -Foreground Magenta"
]
Expand Down
Loading

0 comments on commit 4e9ef12

Please sign in to comment.