diff --git a/.assets/provision/distro_check.sh b/.assets/provision/distro_check.sh index 34f5941d..56dad3e9 100755 --- a/.assets/provision/distro_check.sh +++ b/.assets/provision/distro_check.sh @@ -10,16 +10,16 @@ declare -A state=( ["conda"]=$([ -d $HOME/miniconda3 ] && echo "true" || echo "false") ["git_user"]=$([ -n "$(git config --global --get user.name 2>/dev/null)" ] && echo "true" || echo "false") ["git_email"]=$([ -n "$(git config --global --get user.email 2>/dev/null)" ] && echo "true" || echo "false") - ["gtkd"]=$([ grep -Fqw "dark" /etc/profile.d/gtk_theme.sh 2>/dev/null ] && echo "true" || echo "false") + ["gtkd"]=$(grep -Fqw "dark" /etc/profile.d/gtk_theme.sh 2>/dev/null && echo "true" || echo "false") ["k8s_base"]=$([ -f /usr/bin/kubectl ] && echo "true" || echo "false") ["k8s_ext"]=$([ -f /usr/local/bin/k3d ] && echo "true" || echo "false") ["omp"]=$([ -f /usr/bin/oh-my-posh ] && echo "true" || echo "false") ["pwsh"]=$([ -f /usr/bin/pwsh ] && echo "true" || echo "false") ["shell"]=$([ -f /usr/bin/rg ] && echo "true" || echo "false") ["ssh_key"]=$([ -f $HOME/.ssh/id_ed25519 ] && echo "true" || echo "false") - ["systemd"]=$([ grep -qw "systemd.*true" /etc/wsl.conf 2>/dev/null ] && echo "true" || echo "false") - ["tf"]=$([ -f /usr/local/bin/tfswitch ] && echo "true" || echo "false") - ["wsl_boot"]=$([ grep -qw "autoexec\.sh" /etc/wsl.conf 2>/dev/null ] && echo "true" || echo "false") + ["systemd"]=$(grep -qw "systemd.*true" /etc/wsl.conf 2>/dev/null && echo "true" || echo "false") + ["tf"]=$([ -f /usr/bin/terraform ] && echo "true" || echo "false") + ["wsl_boot"]=$(grep -Fqw "autoexec.sh" /etc/wsl.conf 2>/dev/null && echo "true" || echo "false") ["wslg"]=$([ -d /mnt/wslg ] && echo "true" || echo "false") ["zsh"]=$([ -f /usr/bin/zsh ] && echo "true" || echo "false") ) diff --git a/.assets/provision/install_azurecli.sh b/.assets/provision/install_azurecli.sh index 50f5ffd7..18bf9e44 100755 --- a/.assets/provision/install_azurecli.sh +++ b/.assets/provision/install_azurecli.sh @@ -59,6 +59,3 @@ conda deactivate # make symbolic link to az cli mkdir -p "$HOME/.local/bin" ln -sf "$HOME/miniconda3/envs/azurecli/bin/az" "$HOME/.local/bin/" - -# restore working directory -popd >/dev/null diff --git a/.assets/provision/install_terraform.sh b/.assets/provision/install_terraform.sh index f2f30d5a..90e4c35a 100755 --- a/.assets/provision/install_terraform.sh +++ b/.assets/provision/install_terraform.sh @@ -37,8 +37,8 @@ retry_count=0 # return latest release echo $REL -if type $APP &>/dev/null; then - VER=$($APP --version | sed -En 's/Terraform v([0-9\.]+)/\1/p') +if [ -x /usr/bin/terraform ]; then + VER=$(/usr/bin/terraform --version | sed -En 's/Terraform v([0-9\.]+)/\1/p') if [ "$REL" = "$VER" ]; then printf "\e[32m$APP v$VER is already latest\e[0m\n" >&2 exit 0 diff --git a/.assets/provision/setup_profile_user.ps1 b/.assets/provision/setup_profile_user.ps1 index 1734d6de..8c7f7fd0 100755 --- a/.assets/provision/setup_profile_user.ps1 +++ b/.assets/provision/setup_profile_user.ps1 @@ -31,7 +31,7 @@ if (Get-Module -Name Microsoft.PowerShell.PSResourceGet -ListAvailable) { } # disable oh-my-posh update notice if (Get-Command oh-my-posh -CommandType Application) { - oh-my-posh disable notice + oh-my-posh disable notice | Out-Null } # install PSReadLine for ($i = 0; ((Get-Module PSReadLine -ListAvailable).Count -eq 1) -and $i -lt 5; $i++) { @@ -43,7 +43,13 @@ for ($i = 0; ((Get-Module PSReadLine -ListAvailable).Count -eq 1) -and $i -lt 5; $kubectlSet = try { Select-String '__kubectl_debug' -Path $PROFILE -Quiet } catch { $false } if ((Test-Path /usr/bin/kubectl) -and -not $kubectlSet) { Write-Host 'adding kubectl auto-completion...' - (/usr/bin/kubectl completion powershell).Replace("'kubectl'", "'k'") >$PROFILE + # build completer text + $completer = [string]::Join("`n", + (/usr/bin/kubectl completion powershell) -join "`n", + "Register-ArgumentCompleter -CommandName 'k' -ScriptBlock `${__kubectlCompleterBlock}" + ) + # add additional ArgumentCompleter at the end of the profile + [System.IO.File]::WriteAllText($PROFILE, $completer) } # setup conda initialization diff --git a/.assets/provision/setup_profile_user.sh b/.assets/provision/setup_profile_user.sh index 21caec61..03ba1304 100755 --- a/.assets/provision/setup_profile_user.sh +++ b/.assets/provision/setup_profile_user.sh @@ -50,15 +50,6 @@ fi EOF fi -# add terraform using tfswitch -if [ -f /usr/local/bin/tfswitch ] && ! command -v terraform &>/dev/null; then - LOCAL_BIN="$HOME/.local/bin" - # create local bin directory if it does not exist - [ -d $LOCAL_BIN ] && true || mkdir -p $LOCAL_BIN - printf '\e[92minstalling Terraform using tfswitch\e[0m\n' >&2 - tfswitch --bin="$LOCAL_BIN/terraform" --latest -fi - # add conda initialization if ! grep -qw '__conda_setup' ~/.bashrc 2>/dev/null && [ -f $HOME/miniconda3/bin/conda ]; then $HOME/miniconda3/bin/conda init bash >/dev/null diff --git a/.assets/scripts/cascadia_code_install.ps1 b/.assets/scripts/fonts_install_cascadia_code.ps1 similarity index 79% rename from .assets/scripts/cascadia_code_install.ps1 rename to .assets/scripts/fonts_install_cascadia_code.ps1 index 8b0d3652..46dc403b 100644 --- a/.assets/scripts/cascadia_code_install.ps1 +++ b/.assets/scripts/fonts_install_cascadia_code.ps1 @@ -6,10 +6,11 @@ Install latest CascadaCode fonts. https://github.com/microsoft/cascadia-code .EXAMPLE -.assets/scripts/cascadia_code_install.ps1 +.assets/scripts/fonts_install_cascadia_code.ps1 # :check installed fonts [Drawing.Text.InstalledFontCollection]::new().Families | Select-String 'cascadia' -Raw #> +[CmdletBinding()] param () begin { @@ -17,11 +18,14 @@ begin { $tmp = New-Item "tmp.$(Get-Random)" -ItemType Directory $fontArchive = [IO.Path]::Combine($tmp, 'CascadiaCode.zip') + + # latest release api endpoint for the cascadia-code repo + $urlGHRel = 'https://api.github.com/repos/microsoft/cascadia-code/releases/latest' } process { # get latest version - $rel = (Invoke-RestMethod https://api.github.com/repos/microsoft/cascadia-code/releases/latest).tag_name -replace '^v' + $rel = (Invoke-RestMethod $urlGHRel).tag_name -replace '^v' # download font try { $uri = "https://github.com/microsoft/cascadia-code/releases/download/v${REL}/CascadiaCode-${REL}.zip" diff --git a/.assets/scripts/nerd_fonts_install.ps1 b/.assets/scripts/fonts_install_nerd.ps1 similarity index 97% rename from .assets/scripts/nerd_fonts_install.ps1 rename to .assets/scripts/fonts_install_nerd.ps1 index 872227ca..b5be5778 100644 --- a/.assets/scripts/nerd_fonts_install.ps1 +++ b/.assets/scripts/fonts_install_nerd.ps1 @@ -12,7 +12,7 @@ Specified font extension. .EXAMPLE $Font = 'FiraCode' -.assets/scripts/nerd_fonts_install.ps1 $Font +.assets/scripts/fonts_install_nerd.ps1 $Font # :check installed fonts [Drawing.Text.InstalledFontCollection]::new().Families | Select-String $Font #> diff --git a/docs/wsl_setup.md b/docs/wsl_setup.md index f29f2e96..f1abe097 100644 --- a/docs/wsl_setup.md +++ b/docs/wsl_setup.md @@ -85,7 +85,7 @@ There are three themes included in the repository: ![omp_base.png](images/omp_base.png) - `powerline` - using extended, powerline fonts, e.g. **Cascadia Code PL** fonts, to be downloaded from [microsoft/cascadia-code](https://github.com/microsoft/cascadia-code) ![omp_base.png](images/omp_powerline.png) -- `nerd` - using nerd fonts - can be downloaded manually from [ryanoasis/nerd-fonts](https://github.com/ryanoasis/nerd-fonts) or installed using the script [install_fonts_nerd.ps1](../.assets/scripts/nerd_fonts_install.ps1) +- `nerd` - using nerd fonts - can be downloaded manually from [ryanoasis/nerd-fonts](https://github.com/ryanoasis/nerd-fonts) or installed using the script [install_fonts_nerd.ps1](../.assets/scripts/fonts_install_nerd.ps1) ![omp_base.png](images/omp_nerd.png) You can also specify any other theme name from [Themes | Oh My Posh](https://ohmyposh.dev/docs/themes) - it will be downloaded and installed automatically during the provisioning. diff --git a/wsl/wsl_setup.ps1 b/wsl/wsl_setup.ps1 index 2fd6ffe7..464b4e23 100644 --- a/wsl/wsl_setup.ps1 +++ b/wsl/wsl_setup.ps1 @@ -414,12 +414,18 @@ process { $rel_bat = wsl.exe --distribution $Distro --user root --exec .assets/provision/install_bat.sh $Script:rel_bat $rel_rg = wsl.exe --distribution $Distro --user root --exec .assets/provision/install_ripgrep.sh $Script:rel_rg $rel_yq = wsl.exe --distribution $Distro --user root --exec .assets/provision/install_yq.sh $Script:rel_yq + # *setup bash profiles + Write-Host 'setting up profile for all users...' -ForegroundColor Cyan + wsl.exe --distribution $Distro --user root --exec .assets/provision/setup_profile_allusers.sh $chk.user + Write-Host 'setting up profile for current user...' -ForegroundColor Cyan + wsl.exe --distribution $Distro --exec .assets/provision/setup_profile_user.sh continue } terraform { Write-Host 'installing terraform utils...' -ForegroundColor Cyan - $rel_tfs = wsl.exe --distribution $Distro --user root --exec .assets/provision/install_tfswitch.sh $Script:rel_tfs + $rel_tf = wsl.exe --distribution $Distro --user root --exec .assets/provision/install_terraform.sh $Script:rel_tf $rel_trs = wsl.exe --distribution $Distro --user root --exec .assets/provision/install_terrascan.sh $Script:rel_trs + $rel_tfs = wsl.exe --distribution $Distro --user root --exec .assets/provision/install_tfswitch.sh $Script:rel_tfs continue } zsh { @@ -431,11 +437,6 @@ process { continue } } - # *setup bash profiles - Write-Host 'setting up profile for all users...' -ForegroundColor Cyan - wsl.exe --distribution $Distro --user root --exec .assets/provision/setup_profile_allusers.sh $chk.user - Write-Host 'setting up profile for current user...' -ForegroundColor Cyan - wsl.exe --distribution $Distro --exec .assets/provision/setup_profile_user.sh # *set gtk theme for wslg if ($lx.Version -eq 2 -and $chk.wslg) { $GTK_THEME = if ($GtkTheme -eq 'light') {