Skip to content

Instantly share code, notes, and snippets.

@RiceBen
Last active November 29, 2023 09:50
Show Gist options
  • Save RiceBen/837bf6353f4b911d6cb1e42acc30eaeb to your computer and use it in GitHub Desktop.
Save RiceBen/837bf6353f4b911d6cb1e42acc30eaeb to your computer and use it in GitHub Desktop.
Initialize development environment with scoop
param(
[string][Parameter(Mandatory = $true)] $DownloadFolder
)
function Test-CommandAvailable {
param (
[Parameter(Mandatory = $True, Position = 0)]
[String] $Command
)
return [Boolean](Get-Command $Command -ErrorAction SilentlyContinue)
}
function Add-UserPath {
param (
[string][Parameter(Mandatory = $true)] $AppExecPath
)
$PathParts = [System.Environment]::GetEnvironmentVariable('PATH', "User") -Split ";"
$NewPathParts = $PathParts.Where{ $_ -ne $AppExecPath }
$NewPathParts = ($AppExecPath) + $NewPathParts
$NewPath = $NewPathParts -Join ";"
[System.Environment]::SetEnvironmentVariable('PATH', $NewPath, "User")
}
function Set-Nuget {
# Ref: https://docs.microsoft.com/en-us/nuget/consume-packages/managing-the-global-packages-and-cache-folders
param (
# global packages, default will locate at '%userprofile%\.nuget\packages' in Windows.
[string] $NugetPackages = '',
# default will locate at '%localappdata%\NuGet\v3-cache' in Windows.
[string] $NugetHttpCachePath = '',
# A folder where NuGet stores the results from the operation claims request.
[string] $NugetPluginsCachePath = ''
)
if (($null -eq $Env:NUGET_PACKAGES) -and ($NugetPackages -ne '')) {
$Env:NUGET_PACKAGES = $NugetPackages
[Environment]::SetEnvironmentVariable('NUGET_PACKAGES', $Env:NUGET_PACKAGES, 'User')
}
if (($null -eq $Env:NUGET_HTTP_CACHE_PATH) -and ($NugetHttpCachePath -ne '')) {
$Env:NUGET_HTTP_CACHE_PATH = $NugetHttpCachePath
[Environment]::SetEnvironmentVariable('NUGET_HTTP_CACHE_PATH', $Env:NUGET_HTTP_CACHE_PATH, 'User')
}
if (($null -eq $Env:NUGET_PLUGINS_CACHE_PATH) -and ($NugetPluginsCachePath -ne '')) {
$Env:NUGET_PLUGINS_CACHE_PATH = $NugetPluginsCachePath
[Environment]::SetEnvironmentVariable('NUGET_PLUGINS_CACHE_PATH', $Env:NUGET_PLUGINS_CACHE_PATH, 'User')
}
}
function Install-LINQPad {
param (
[bool][Parameter(Mandatory = $true)] $Install,
# By setting these two environment variables, you can override the %LocalAppData% and %Temp% folders that LINQPad uses for compiling queries and executing updates.
[string] $LinqpadTEMP = '',
[string] $LinqpadLocalAPPData = ''
)
if ($Install -eq $False) {
return
}
if (($null -eq $Env:LINQPAD_LOCALAPPDATA) -and ($LinqpadLocalAPPData -ne '')) {
$Env:LINQPAD_LOCALAPPDATA = $LinqpadLocalAPPData
[Environment]::SetEnvironmentVariable('LINQPAD_LOCALAPPDATA', $Env:LINQPAD_LOCALAPPDATA, 'User')
}
if (($null -eq $Env:LINQPAD_TEMP) -and ($LinqpadTEMP -ne '')) {
$Env:LINQPAD_TEMP = $LinqpadTEMP
[Environment]::SetEnvironmentVariable('LINQPAD_TEMP', $Env:LINQPAD_TEMP, 'User')
}
scoop install extras/linqpad
}
function Install-DevLanguages {
<#
.SYNOPSIS
Install Development languages
.DESCRIPTION
Install language like Java, Python, NodeJS, Golang
.PARAMETER Java
Set to install Java.
.PARAMETER Python
Set to install Python.
.PARAMETER PyenvDir
When install Python, will install pyenv to management python version.
Set this param, you can decide where to install pyenv, leave it blank to use default value.
.PARAMETER PoetryHome
When install Python, will install poetry as package management tool.
Set this param, you can decide where to install poetry, leave it blank to use default value.
.PARAMETER NodeJs
Set to install NodeJS.
.PARAMETER VOLTAHome
When install NodeJS, will install Volta to manage NodeJS version and NodeJS ecomsystem.
Set this param, you can decide where to install Volta, leave it blank to use default value.
.PARAMETER Golang
Set to install Golang.
.EXAMPLE
Install-DevLanguages -Java `
-Python `
-PyenvDir '' `
-PoetryHome '' `
-NodeJs `
-VOLTAHome '' `
-Golang
.NOTES
N/A
#>
param (
[switch] $Java,
[switch][parameter(ParameterSetName = "python")] $Python,
[string][parameter(ParameterSetName = "python", Mandatory = $true)] $PyenvDir,
[string][parameter(ParameterSetName = "python", Mandatory = $true)] $PoetryHome,
[switch][parameter(ParameterSetName = "NodeJs")] $NodeJs,
[string][parameter(ParameterSetName = "NodeJs")] $VOLTAHome,
[switch] $Golang
)
if ($Java) {
Install-Java
}
if ($Python) {
Install-Python -PyenvDir $PyenvDir -PoetryHome $PoetryHome
}
if ($NodeJs) {
Install-NodeJS -VOLTAHome $VOLTAHome
}
if ($Golang) {
scoop install main/go
}
}
function Install-Java {
scoop bucket add java
scoop install java/zulu-jdk
$JavaHome = scoop prefix zulu-jdk
[System.Environment]::SetEnvironmentVariable('JAVA_HOME', $JavaHome, 'User')
$JavaBinPath = "$Env:JAVA_HOME\bin"
Add-UserPath -AppExecPath $JavaBinPath
}
function Install-Python {
param (
# Ref: https://github.com/pyenv/pyenv#environment-variables
[string] $PyenvDir = '',
# Ref: https://python-poetry.org/docs/#installation
[string] $PoetryHome = ''
)
if (($Null -eq $Env:POETRY_HOME) -and ($PoetryHome -ne '')) {
$Env:POETRY_HOME = $PoetryHome
[System.Environment]::SetEnviromentVariable('POETRY_HOME', $Env:POETRY_HOME, 'User')
}
if ($DownloadFolder -ne '') {
if ((Test-Path $DownloadFolder) -eq $False) {
New-Item $DownloadFolder -ItemType Directory
}
}
# setup python env
## Start install pyenv manually
Invoke-WebRequest -UseBasicParsing -Uri "https://raw.githubusercontent.com/pyenv-win/pyenv-win/master/pyenv-win/install-pyenv-win.ps1" -OutFile "$DownloadFolder/install-pyenv-win.ps1"
if ($PyenvDir -ne '') {
if ((Test-Path $PyenvDir) -eq $False) {
New-Item $PyenvDir -ItemType Directory
}
(Get-Content -Path $DownloadFolder/install-pyenv-win.ps1) -replace '\${env:USERPROFILE}', "$PyenvDir" | Add-Content -Path $DownloadFolder/install-pyenv-win.bak.ps1
Remove-Item -Path $DownloadFolder/install-pyenv-win.ps1
Move-Item -Path $DownloadFolder/install-pyenv-win.bak.ps1 -Destination $DownloadFolder/install-pyenv-win.ps1
}
## execute new install script
pwsh $DownloadFolder/install-pyenv-win.ps1
## using pyenv to install python
pyenv install 3.12.0
pyenv global 3.12.0
pyenv rehash
# install poetry
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -
}
function Install-NodeJS {
param (
# Ref: https://docs.volta.sh/guide/getting-started
[string] $VOLTAHome = ''
)
if (($Null -eq $Env:VOLTA_HOME) -and ($VOLTAHome -ne '')) {
$Env:VOLTA_HOME = $VOLTAHome
[System.Environment]::SetEnviromentVariable('VOLTA_HOME', $Env:VOLTA_HOME, 'User')
}
scoop install main/volta
# setup volta
volta install node@20.9.0
volta install npm@10.2.3
}
function Install-Podman {
param (
[bool][Parameter(Mandatory = $true)] $Install,
[string] $PodmanVersion = '4.8.0'
)
if ($Install -eq $False) {
exit
}
# install podman
if ((Test-Path $DownloadFolder) -eq $False) {
New-Item $DownloadFolder -ItemType Directory
}
Invoke-WebRequest -UseBasicParsing -Uri "https://github.com/containers/podman/releases/download/v${PodmanVersion}/podman-${PodmanVersion}-setup.exe" -OutFile "$DownloadFolder\podman-${PodmanVersion}-setup.exe"
Start-Process "$DownloadFolder\podman-${PodmanVersion}-setup.exe"
scoop install extras/podman-desktop
}
function Install-CloudCli {
param (
[switch][parameter(ParameterSetName = "aws")] $Aws,
# Ref: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html
# Ref: https://docs.aws.amazon.com/sdkref/latest/guide/file-location.html
[string][parameter(ParameterSetName = "aws", Mandatory = $true)] $AwsConfigFile = '',
# Ref: https://docs.aws.amazon.com/en-us/cli/latest/topic/config-vars.html#the-shared-credentials-file
[string][parameter(ParameterSetName = "aws", Mandatory = $true)] $AwsSharedCredentialFile = '',
[switch][parameter(ParameterSetName = "azure")] $Azure,
# Ref: https://learn.microsoft.com/en-us/dotnet/api/overview/azure/service-to-service-authentication?view=azure-dotnet#azureservicetokenprovider-cant-find-the-path-for-azure-cli
[string][parameter(ParameterSetName = "azure", Mandatory = $true)] $AzureCliPath = '',
# Ref: https://learn.microsoft.com/en-us/cli/azure/azure-cli-configuration#cli-configuration-file
[string][parameter(ParameterSetName = "azure", Mandatory = $true)] $AzureConfigDir = ''
)
if ($Aws) {
if (($null -eq $Env:AWS_CONFIG_FILE) -and ($AwsConfigFile -ne '')) {
$Env:AWS_CONFIG_FILE = $AwsConfigFile
[Environment]::SetEnviromentVariable('AWS_CONFIG_FILE', $Env:AWS_CONFIG_FILE, 'User')
}
if (($null -eq $Env:AWS_SHARED_CREDENTIALS_FILE) -and ($AwsSharedCredentialFile -ne '')) {
$Env:AWS_SHARED_CREDENTIALS_FILE = $AwsSharedCredentialFile
[Environment]::SetEnviromentVariable('AWS_SHARED_CREDENTIALS_FILE', $Env:AWS_SHARED_CREDENTIALS_FILE, 'User')
}
scoop install main/aws
}
if ($Azure) {
if (($null -eq $Env:AzureCLIPath) -and ($AzureCliPath -ne '')) {
$Env:AzureCLIPath = $AzureCliPath
[Environment]::SetEnviromentVariable('AzureCLIPath', $Env:AzureCLIPath, 'User')
}
if (($null -eq $Env:AZURE_CONFIG_DIR) -and ($AzureConfigDir -ne '')) {
$Env:AZURE_CONFIG_DIR = $AzureConfigDir
[Environment]::SetEnviromentVariable('AZURE_CONFIG_DIR', $Env:AZURE_CONFIG_DIR, 'User')
}
scoop install main/azure-cli
}
}
function Install-Tools {
param (
[switch] $DevTools,
[switch] $IDE,
[switch] $Fonts,
[switch] $BlogTool,
[switch] $Browsers,
[switch] $Others
)
if ($DevTools) {
scoop install extras/another-redis-desktop-manager
scoop install main/bfg
scoop install main/curl
scoop install extras/gittyup
scoop install extras/ilspy
scoop install main/k6
scoop install extras/lazygit
scoop install main/make
scoop install extras/mobaxterm
scoop install extras/posh-git
scoop install extras/postman
scoop install main/task
# infra-as-code
scoop install main/pulumi
scoop install main/terraform
scoop install main/terragrunt
$ilSpyExecPath = scoop prefix ilspy
$k6ExecPath = scoop prefix k6
Add-UserPath -AppExecPath $ilSpyExecPath
Add-UserPath -AppExecPath $k6ExecPath
}
if ($IDE) {
scoop install extras/notepadplusplus
scoop install extras/vscode
}
if ($Fonts) {
scoop install nerd-fonts/FiraCode
scoop install nerd-fonts/Hack-NF
scoop install nerd-fonts/Hermit-NF
}
if ($BlogTool) {
scoop install main/hugo
scoop install main/hugo-extended
scoop install extras/joplin
$hugoExecPath = scoop prefix hugo
Add-UserPath -AppExecPath $hugoExecPath
}
if ($Browsers) {
scoop install extras/brave
scoop install extras/sidekick-browser
}
if ($Others) {
scoop install extras/pdf-xchange-editor
scoop install extras/treesize-free
scoop install extras/vlc
scoop install extras/xmind
}
}
function Install-Scoop {
# Ref: https://scoop-docs.vercel.app/docs/getting-started/Quick-Start.html#install-scoop-to-a-custom-directory-by-changing-scoop
param (
# Assuming the target directory is C:\scoop
[string] $ScoopLocate = '',
# Default will locate {scoop install locate}/cache
[string] $ScoopCache = '',
# Assuming the target directory is C:\apps
[string] $ScoopGlobalApps = '',
[switch] $7zip,
[string] $StarshipConfig = ''
)
if (($null -eq $Env:SCOOP) -and ($ScoopLocate -ne '')) {
$Env:SCOOP = $ScoopLocate
[Environment]::SetEnvironmentVariable('SCOOP', $Env:SCOOP, 'User')
}
if (($null -eq $Env:SCOOP_CACHE) -and ($ScoopCache -ne '')) {
$Env:SCOOP_CACHE = $ScoopCache
[Environment]::SetEnvironmentVariable('SCOOP_CACHE', $Env:SCOOP_CACHE, 'User')
}
if (($null -eq $Env:SCOOP_GLOBAL) -and ($ScoopGlobalApps -ne '')) {
$Env:SCOOP_GLOBAL = $ScoopGlobalApps
[Environment]::SetEnvironmentVariable('SCOOP_GLOBAL', $Env:SCOOP_GLOBAL, 'User')
}
if (($null -eq $Env:STARSHIP_CONFIG) -and ($StarshipConfig -ne '')) {
$Env:STARSHIP_CONFIG = $StarshipConfig
[Environment]::SetEnvironmentVariable('STARSHIP_CONFIG', $Env:STARSHIP_CONFIG, 'User')
}
# install scoop
Invoke-WebRequest -useb get.scoop.sh | Invoke-Expression
if ($7zip) {
if (!(Test-CommandAvailable('7z'))) {
scoop install main/7zip
$7zipPath = scoop prefix 7zip
Add-UserPath -AppExecPath $7zipPath
}
}
if (!(Test-CommandAvailable('git'))) {
scoop install main/git
}
scoop install main/starship
$starshipPath = scoop prefix starship
Add-UserPath -AppExecPath $starshipPath
# add useful buckets
scoop bucket add extras
scoop bucket add nerd-fonts
}
Install-Scoop -ScoopLocate '' `
-ScoopCache '' `
-ScoopGlobalApps '' `
-7zip `
-StarshipConfig ''
Set-Nuget -NugetPackages '' `
-NugetHttpCachePath '' `
-NugetPluginsCachePath ''
Install-LINQPad -Install $True `
-LinqpadTEMP '' `
-LinqpadLocalAPPData ''
Install-DevLanguages -Java `
-Python `
-PyenvDir '' `
-PoetryHome '' `
-NodeJs `
-VOLTAHome '' `
-Golang
Install-Podman -Install $True `
-PodmanVersion '4.8.0'
Install-CloudCli -Aws `
-AwsConfigFile '' `
-AwsSharedCredentialFile '' `
-Azure `
-AzureCliPath '' `
-AzureConfigDir ''
Install-Tools -DevTools `
-IDE `
-Fonts `
-BlogTool `
-Browsers `
-Others
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment