Skip to content

Instantly share code, notes, and snippets.

@Konfekt
Last active September 17, 2024 05:35
Show Gist options
  • Save Konfekt/e58feb64a4f1051cbc0b9bdeeb9739d9 to your computer and use it in GitHub Desktop.
Save Konfekt/e58feb64a4f1051cbc0b9bdeeb9739d9 to your computer and use it in GitHub Desktop.
Install a batch of useful scoop apps
<#
.SYNOPSIS
Script to install Scoop apps
.DESCRIPTION
Script uses scoop
.NOTES
**NOTE** Will configure the Execution Policy for the "CurrentUser" to Unrestricted.
Original Author: Mike Pruett
Date: October 18th, 2018
Last Updated on December 26th, 2022
Adapted by: Enno
Date: April 9th, 2024
#>
$VerbosePreference = "Continue"
# Configure ExecutionPolicy to Unrestricted for CurrentUser Scope
if ((Get-ExecutionPolicy -Scope CurrentUser) -notcontains "Unrestricted") {
Write-Verbose -Message "Trying to elevate Execution Policy for Current User to Unrestricted ..."
try {
Start-Process -FilePath "PowerShell" -ArgumentList "Set-ExecutionPolicy","-Scope","CurrentUser","-ExecutionPolicy","Unrestricted","-Force" -Verb RunAs -Wait -ErrorAction Stop
Write-Verbose -Message "... successfully!"
Write-Output "Restart/Re-Run script!!!"
Start-Sleep -Seconds 3
Break
} catch {
Write-Verbose -Message "... failed with error: $_"
}
}
function Install-ScoopApp {
param (
[string]$Package
)
Write-Verbose -Message "Preparing to install $Package"
if (! (scoop info $Package).Installed ) {
Write-Verbose -Message "Installing $Package"
scoop install $Package
} else {
Write-Verbose -Message "Package $Package already installed! Skipping..."
}
}
function Enable-Bucket {
param (
[string]$Bucket
)
if (!($(scoop bucket list).Name -eq "$Bucket")) {
Write-Verbose -Message "Adding Bucket $Bucket to scoop..."
scoop bucket add $Bucket
} else {
Write-Verbose -Message "Bucket $Bucket already added! Skipping..."
}
}
# Install Scoop, if not already installed
if ( !(Get-Command -Name "scoop" -CommandType Application -ErrorAction SilentlyContinue) ) {
Write-Verbose -Message "Installing Scoop..."
iex ((New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh'))
}
# From https://stackoverflow.com/questions/46758437/how-to-refresh-the-environment-of-a-powershell-session-after-a-chocolatey-instal/69918699#69918699
function refreshenv {
# Call a powershell process to act as a wrapper to capture the output:
& ([Diagnostics.Process]::GetCurrentProcess().ProcessName) -NoP -c (
# String wrapper to help make the code more readable through comma-separation:
[String]::Join(' ', (
# Start a process that escapes the active environment:
'Start-Process', [Diagnostics.Process]::GetCurrentProcess().ProcessName,
'-UseNewEnvironment -NoNewWindow -Wait -Args ''-c'',',
# List the environment variables, separated by a tab character:
'''Get-ChildItem env: | &{process{ $_.Key + [char]9 + $_.Value }}'''
))) | &{process{
# Set each line of output to a process-scoped environment variable:
[Environment]::SetEnvironmentVariable(
$_.Split("`t")[0], # Key
$_.Split("`t")[1], # Value
'Process' # Scope
)
}}
}
# # Install refreshenv
# Install-ScoopApp -Package "refreshenv"
# Start-Sleep -Seconds 5
# refreshenv
# Start-Sleep -Seconds 5
# if ( !(Get-Command -Name "scoop" -CommandType Application -ErrorAction SilentlyContinue) ) {
# Write-Verbose -Message "Removing refreshenv command from Scoop to be replaced by that of Chocolatey..."
# scoop uninstall refreshenv
# }
refreshenv
Start-Sleep -Seconds 5
if (Get-Command git -ErrorAction SilentlyContinue) {
Write-Output "Git is already installed."
} else {
# Install Git
Install-ScoopApp -Package "git"
# Configure git
Start-Sleep -Seconds 5
}
if (!($Env:GIT_SSH)) {
Write-Verbose -Message "Setting GIT_SSH User Environment Variable"
[System.Environment]::SetEnvironmentVariable('GIT_SSH', (Resolve-Path (scoop which ssh)), 'USER')
}
if ((Get-Service -Name ssh-agent).Status -ne "Running") {
Write-Verbose -Message "Trying to register the SSH-Agent service ..."
try {
Start-Process -FilePath "PowerShell" -ArgumentList "Set-Service","ssh-agent","-StartupType","Manual" -Verb RunAs -Wait -WindowStyle Hidden -ErrorAction Stop
Write-Verbose -Message "... successfully!"
} catch {
Write-Verbose -Message "... failed with error: $_"
}
}
# Configure Aria2 Download Manager
Install-ScoopApp -Package "aria2"
if (!$(scoop config aria2-enabled) -eq $True) {
scoop config aria2-enabled true
}
if (!$(scoop config aria2-warning-enabled) -eq $False) {
scoop config aria2-warning-enabled false
}
if (!(Get-ScheduledTaskInfo -TaskName "Aria2RPC" -ErrorAction Ignore)) {
@'
$Action = New-ScheduledTaskAction -Execute $Env:UserProfile\scoop\apps\aria2\current\aria2c.exe -Argument "--enable-rpc --rpc-listen-all" -WorkingDirectory $Env:UserProfile\Downloads
$Trigger = New-ScheduledTaskTrigger -AtStartup
$Principal = New-ScheduledTaskPrincipal -UserID "$Env:ComputerName\$Env:Username" -LogonType S4U
$Settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit 0 -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
Register-ScheduledTask -TaskName "Aria2RPC" -Action $Action -Trigger $Trigger -Principal $Principal -Settings $Settings
'@ > $Env:Temp\aria2.ps1
Write-Verbose -Message "Trying to register the Aria2RPC service ..."
try {
Start-Process -FilePath "PowerShell" -ArgumentList "$Env:Temp\aria2.ps1" -Verb RunAs -Wait -ErrorAction Stop #-WindowStyle Hidden
Write-Verbose -Message "... successfully!"
} catch {
Write-Verbose -Message "... failed with error: $_"
}
Remove-Item -Path $Env:Temp\aria2.ps1 -Force
}
# Only install OpenSSH Package, if not on Windows 10
if ([Environment]::OSVersion.Version.Major -lt 10) {
Install-ScoopApp -Package "openssh"
}
# Install OpenSSH.Client on Windows 10+
@'
if ((Get-WindowsCapability -Online -Name OpenSSH.Client*).State -ne "Installed") {
Add-WindowsCapability -Online -Name OpenSSH.Client*
}
'@ > "${Env:Temp}\openssh.ps1"
Write-Verbose -Message "Trying to add OpenSSH Windows Capability ..."
try {
Start-Process -FilePath "PowerShell" -ArgumentList "${Env:Temp}\openssh.ps1" -Verb RunAs -Wait -WindowStyle Hidden -ErrorAction Stop
Write-Verbose -Message "... successfully!"
} catch {
Write-Verbose -Message "... failed with error: $_"
}
Remove-Item -Path "${Env:Temp}\openssh.ps1" -Force
# UNIX Tools
Write-Verbose -Message "Removing curl Alias..."
if (Get-Alias -Name curl -ErrorAction SilentlyContinue) {
Remove-Item alias:curl
}
if (!($Env:TERM)) {
Write-Verbose -Message "Setting TERM User Environment Variable"
[System.Environment]::SetEnvironmentVariable("TERM", "xterm-256color", "USER")
}
# Create $Env:UserProfile\bin, if not exist
if (!(Test-Path -Path $Env:UserProfile\bin)) {
Write-Verbose -Message "Creating bin directory in $Env:UserProfile"
New-Item -Path $Env:UserProfile\bin -ItemType Directory | Out-Null
#[System.Environment]::SetEnvironmentVariable("PATH", $Env:PATH + ";$Env:UserProfile\bin","USER")
}
# Minimal Setup:
Enable-Bucket -Bucket "extras"
# Includes corretto-jre8
Enable-Bucket -Bucket "java"
$Scoop = @(
# # install first so that its shims are overridden by the following installations
# # of gawk, grep, less, make, sed, vim, ...
"coreutils",
"curl",
# "wget",
"wget2",
"uget",
"unar",
"7zip-zstd",
"less",
"bat",
"mdcat",
"tealdeer",
# "git",
"delta",
"difftastic",
"fd",
"ripgrep",
"ugrep",
"rga",
"fzf",
# "peco",
"lf",
"vim",
"notepadplusplus",
# "aspell",
# "doublecmd",
"grep",
"gawk",
"sed",
"make",
"just",
"ctags",
# "jdupes",
"jq",
# "htmlq",
"jid",
"tidy",
"python",
"pipx"
"ruff",
"lua",
"luajit",
# "stylua",
# "luacheck",
# "lua-language-server",
"nodejs", # for Github Copilot
# "npm",
# "perl",
# "mingw-winlibs",
# "clangd",
"cppcheck",
"pandoc",
# "pandoc-crossref",
# "vale",
"autohotkey",
# See https://news.ycombinator.com/item?id=41545737
# "glazewm",
"komorebi",
"sysinternals",
"bottom",
# "ntop",
"xkill"
# "lockhunter",
"rapidee",
# "hotkeyslist", # requries scoop bucket add nirsoft
# "syncthing",
# "synctrayzor",
"qalculate",
"ditto",
# "zeal",
"gpg",
"gopass",
"pass-winmenu-nogpg",
"windows-terminal",
"pwsh",
"starship",
"clink",
# "colortool",
# "concfg",
"sudo",
"gsudo",
"PowerToys",
# "sharex",
"grepwin",
# # "dngrep",
# # "everything",
"mediainfo",
# "mediainfo-gui",
"imagemagick",
"mupdf",
"sumatrapdf",
"okular",
"paint.net",
# "krita",
# # "irfanview",
# # "jpegview",
"corretto8-jre",
# "kopia",
# "kopia-ui",
# "cacert",
# "open-log-viewer",
# "baretail",
# "hosts-file-editor",
"poppler",
# "djvulibre",
# "tesseract",
# "xournalpp",
# # ! Set default file format to DocX as in
# # https://www.howtogeek.com/281166/how-to-change-the-default-file-format-in-libreoffice/
# "libreoffice",
# # ! Install add-ons from https://addons.mozilla.org/en-US/firefox/collections/17831851/Serenity/
# "firefox",
# "brave",
# "thunderbird",
"msedgeredirect"
# "zoom",
# "microsoft-teams",
# "vlc",
# "smplayer",
# "mpv",
# "ffmpeg",
# "lame",
# "musicbee",
# "mp3tag",
# "yt-dlp",
# "spacesniffer",
# # "wiztree",
# "driverstoreexplorer",
# "speccy",
# "hwmonitor",
# "cpu-z",
# "gpu-z",
# "ssd-z",
)
foreach ($item in $Scoop) {
Install-ScoopApp -Package "$item"
}
# Customize DOS/PowerShell Environment
Write-Verbose -Message "Customize DOS/PowerShell Environment..."
if ((Get-ItemProperty -Path "HKCU:\Software\Microsoft\Command Processor" -ErrorAction SilentlyContinue).AutoRun -eq $Null) {
Start-Process -FilePath "cmd" -ArgumentList "/c","clink","autorun","install" -Wait -WindowStyle Hidden -ErrorAction stop
}
Write-Verbose -Message "Trying to elevate Execution Policy for Current User to Unrestricted ..."
try {
Start-Process -FilePath "cmd" -ArgumentList "/c","concfg","import","solarized-light" -Verb RunAs -Wait -ErrorAction stop
Write-Verbose -Message "... successfully!"
} catch {
Write-Verbose -Message "... failed with error: $_"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment