From 388b8d14b5971ac244603e143f569370da73ff57 Mon Sep 17 00:00:00 2001 From: Szymon Osiecki Date: Fri, 14 Jun 2024 10:45:21 +0200 Subject: [PATCH 01/13] refactor: SetupUtils v0.3.1 Throw error on issues getting list of distros. --- modules/SetupUtils/Functions/wsl.ps1 | 3 +++ modules/SetupUtils/SetupUtils.psd1 | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/SetupUtils/Functions/wsl.ps1 b/modules/SetupUtils/Functions/wsl.ps1 index 9a2e2288..c73e8fc3 100644 --- a/modules/SetupUtils/Functions/wsl.ps1 +++ b/modules/SetupUtils/Functions/wsl.ps1 @@ -53,6 +53,9 @@ function Get-WslDistro { if ($Online) { # get list of online WSL distros [string[]]$result = wsl.exe --list --online | Where-Object { $_ } + if (-not $?) { + Write-Error -Message 'Cannot get list of valid distributions.' -Category ConnectionError + } # get distros header [string]$head = $result | Select-String 'NAME\s+FRIENDLY' -CaseSensitive | Select-Object -ExpandProperty Line # calculate header line index diff --git a/modules/SetupUtils/SetupUtils.psd1 b/modules/SetupUtils/SetupUtils.psd1 index 298c6b62..b8ce486b 100644 --- a/modules/SetupUtils/SetupUtils.psd1 +++ b/modules/SetupUtils/SetupUtils.psd1 @@ -12,7 +12,7 @@ RootModule = 'SetupUtils.psm1' # Version number of this module. - ModuleVersion = '0.3.0' + ModuleVersion = '0.3.1' # Supported PSEditions CompatiblePSEditions = @('Core') From 4391d55c86610c1b2dd8a6bc751f3e84af6cf5c4 Mon Sep 17 00:00:00 2001 From: Szymon Osiecki Date: Sun, 16 Jun 2024 09:48:26 +0200 Subject: [PATCH 02/13] refactor(sh): redirect message to run the script as (non)root to error stream --- .assets/provision/fix_azcli_certs.sh | 2 +- .assets/provision/fix_certifi_certs.sh | 2 +- .assets/provision/fix_secure_path.sh | 2 +- .assets/provision/install_argorolloutscli.sh | 2 +- .assets/provision/install_azurecli.sh | 2 +- .assets/provision/install_base.sh | 2 +- .assets/provision/install_bat.sh | 2 +- .assets/provision/install_brew.sh | 2 +- .assets/provision/install_btop.sh | 2 +- .assets/provision/install_cmatrix.sh | 2 +- .assets/provision/install_cowsay.sh | 2 +- .assets/provision/install_distrobox.sh | 2 +- .assets/provision/install_docker.sh | 2 +- .assets/provision/install_edge.sh | 2 +- .assets/provision/install_etcdctl.sh | 2 +- .assets/provision/install_exa.sh | 2 +- .assets/provision/install_fastfetch.sh | 2 +- .assets/provision/install_flux.sh | 2 +- .assets/provision/install_fonts_cascadiacode.sh | 2 +- .assets/provision/install_gh.sh | 2 +- .assets/provision/install_gnome.sh | 2 +- .assets/provision/install_helm.sh | 2 +- .assets/provision/install_k3d.sh | 2 +- .assets/provision/install_k9s.sh | 2 +- .assets/provision/install_kubectl-convert.sh | 2 +- .assets/provision/install_kubectl.sh | 2 +- .assets/provision/install_kubelogin.sh | 2 +- .assets/provision/install_kubeseal.sh | 2 +- .assets/provision/install_kustomize.sh | 2 +- .assets/provision/install_miniconda.sh | 2 +- .assets/provision/install_miniforge.sh | 2 +- .assets/provision/install_minikube.sh | 2 +- .assets/provision/install_npm.sh | 2 +- .assets/provision/install_omp.sh | 2 +- .assets/provision/install_podman.sh | 2 +- .assets/provision/install_pwsh.sh | 2 +- .assets/provision/install_ripgrep.sh | 2 +- .assets/provision/install_smee.sh | 2 +- .assets/provision/install_terraform.sh | 2 +- .assets/provision/install_terrascan.sh | 2 +- .assets/provision/install_tfswitch.sh | 2 +- .assets/provision/install_xrdp.sh | 2 +- .assets/provision/install_yq.sh | 2 +- .assets/provision/install_zsh.sh | 2 +- .assets/provision/set_ulimits.sh | 2 +- .assets/provision/setup_docker_mount.sh | 2 +- .assets/provision/setup_omp.sh | 2 +- .assets/provision/setup_profile_allusers.sh | 2 +- .assets/provision/setup_python.sh | 2 +- .assets/provision/upgrade_system.sh | 2 +- 50 files changed, 50 insertions(+), 50 deletions(-) diff --git a/.assets/provision/fix_azcli_certs.sh b/.assets/provision/fix_azcli_certs.sh index 28d90deb..45b4a7e4 100755 --- a/.assets/provision/fix_azcli_certs.sh +++ b/.assets/provision/fix_azcli_certs.sh @@ -3,7 +3,7 @@ .assets/provision/fix_azcli_certs.sh ' if [ $EUID -eq 0 ]; then - printf '\e[31;1mDo not run the script as root.\e[0m\n' + printf '\e[31;1mDo not run the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/fix_certifi_certs.sh b/.assets/provision/fix_certifi_certs.sh index 197ea0f1..30009b0d 100755 --- a/.assets/provision/fix_certifi_certs.sh +++ b/.assets/provision/fix_certifi_certs.sh @@ -3,7 +3,7 @@ .assets/provision/fix_certifi_certs.sh ' if [ $EUID -eq 0 ]; then - printf '\e[31;1mDo not run the script as root.\e[0m\n' + printf '\e[31;1mDo not run the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/fix_secure_path.sh b/.assets/provision/fix_secure_path.sh index 485f1fd0..22225b4e 100755 --- a/.assets/provision/fix_secure_path.sh +++ b/.assets/provision/fix_secure_path.sh @@ -3,7 +3,7 @@ sudo .assets/provision/fix_secure_path.sh ' if [ $(id -u) -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_argorolloutscli.sh b/.assets/provision/install_argorolloutscli.sh index 9b2142a7..905866f4 100755 --- a/.assets/provision/install_argorolloutscli.sh +++ b/.assets/provision/install_argorolloutscli.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_argorolloutscli.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_azurecli.sh b/.assets/provision/install_azurecli.sh index 881560ca..ac4fb048 100755 --- a/.assets/provision/install_azurecli.sh +++ b/.assets/provision/install_azurecli.sh @@ -4,7 +4,7 @@ .assets/provision/install_azurecli.sh --fix_certify true ' if [ $EUID -eq 0 ]; then - printf '\e[31;1mDo not run the script as root.\e[0m\n' + printf '\e[31;1mDo not run the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_base.sh b/.assets/provision/install_base.sh index 81ac81c3..dbb046ca 100755 --- a/.assets/provision/install_base.sh +++ b/.assets/provision/install_base.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_base.sh $(id -un) ' if [ $(id -u) -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_bat.sh b/.assets/provision/install_bat.sh index 2941b01c..c6fd08de 100755 --- a/.assets/provision/install_bat.sh +++ b/.assets/provision/install_bat.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_bat.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_brew.sh b/.assets/provision/install_brew.sh index 4924ca59..f9ce7bf3 100755 --- a/.assets/provision/install_brew.sh +++ b/.assets/provision/install_brew.sh @@ -4,7 +4,7 @@ .assets/provision/install_brew.sh >/dev/null ' if [ $EUID -eq 0 ]; then - printf '\e[31;1mDo not run the script as root.\e[0m\n' + printf '\e[31;1mDo not run the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_btop.sh b/.assets/provision/install_btop.sh index e5dd87b8..93efa132 100755 --- a/.assets/provision/install_btop.sh +++ b/.assets/provision/install_btop.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_btop.sh ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_cmatrix.sh b/.assets/provision/install_cmatrix.sh index f0843492..0de8fbc7 100755 --- a/.assets/provision/install_cmatrix.sh +++ b/.assets/provision/install_cmatrix.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_cmatrix.sh ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_cowsay.sh b/.assets/provision/install_cowsay.sh index 16a54ebd..6c8a3c6e 100755 --- a/.assets/provision/install_cowsay.sh +++ b/.assets/provision/install_cowsay.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_cowsay.sh ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_distrobox.sh b/.assets/provision/install_distrobox.sh index 1428bfa8..577ba97d 100755 --- a/.assets/provision/install_distrobox.sh +++ b/.assets/provision/install_distrobox.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_distrobox.sh $(id -un) ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_docker.sh b/.assets/provision/install_docker.sh index 294d335c..58d96060 100755 --- a/.assets/provision/install_docker.sh +++ b/.assets/provision/install_docker.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_docker.sh $(id -un) ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_edge.sh b/.assets/provision/install_edge.sh index 44eddafe..6dfedeac 100755 --- a/.assets/provision/install_edge.sh +++ b/.assets/provision/install_edge.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_edge.sh $(id -un) ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_etcdctl.sh b/.assets/provision/install_etcdctl.sh index 71a4e56a..f6f9a7ad 100755 --- a/.assets/provision/install_etcdctl.sh +++ b/.assets/provision/install_etcdctl.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_etcdctl.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_exa.sh b/.assets/provision/install_exa.sh index 700ef490..00b7a3f9 100755 --- a/.assets/provision/install_exa.sh +++ b/.assets/provision/install_exa.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_exa.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_fastfetch.sh b/.assets/provision/install_fastfetch.sh index 2fc49d58..8fd521cd 100755 --- a/.assets/provision/install_fastfetch.sh +++ b/.assets/provision/install_fastfetch.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_fastfetch.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_flux.sh b/.assets/provision/install_flux.sh index 14726a45..867f5566 100755 --- a/.assets/provision/install_flux.sh +++ b/.assets/provision/install_flux.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_flux.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_fonts_cascadiacode.sh b/.assets/provision/install_fonts_cascadiacode.sh index 0e9270dd..cdf10cb4 100755 --- a/.assets/provision/install_fonts_cascadiacode.sh +++ b/.assets/provision/install_fonts_cascadiacode.sh @@ -4,7 +4,7 @@ sudo .assets/provision/install_fonts_cascadiacode.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_gh.sh b/.assets/provision/install_gh.sh index 5a9a5aef..5bdeaa26 100755 --- a/.assets/provision/install_gh.sh +++ b/.assets/provision/install_gh.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_gh.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_gnome.sh b/.assets/provision/install_gnome.sh index 07a9cbfb..0a8a7809 100755 --- a/.assets/provision/install_gnome.sh +++ b/.assets/provision/install_gnome.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_gnome.sh ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_helm.sh b/.assets/provision/install_helm.sh index 8fb2c1e3..7efae976 100755 --- a/.assets/provision/install_helm.sh +++ b/.assets/provision/install_helm.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_helm.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_k3d.sh b/.assets/provision/install_k3d.sh index 1b6cb80b..96be2e49 100755 --- a/.assets/provision/install_k3d.sh +++ b/.assets/provision/install_k3d.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_k3d.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_k9s.sh b/.assets/provision/install_k9s.sh index a12ac9da..3ae9f5c3 100755 --- a/.assets/provision/install_k9s.sh +++ b/.assets/provision/install_k9s.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_k9s.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_kubectl-convert.sh b/.assets/provision/install_kubectl-convert.sh index 7d65219e..ae2e9d4a 100755 --- a/.assets/provision/install_kubectl-convert.sh +++ b/.assets/provision/install_kubectl-convert.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_kubectl-convert.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_kubectl.sh b/.assets/provision/install_kubectl.sh index ba91fbda..3d36e270 100755 --- a/.assets/provision/install_kubectl.sh +++ b/.assets/provision/install_kubectl.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_kubectl.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_kubelogin.sh b/.assets/provision/install_kubelogin.sh index 486fc410..5fad3782 100755 --- a/.assets/provision/install_kubelogin.sh +++ b/.assets/provision/install_kubelogin.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_kubelogin.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_kubeseal.sh b/.assets/provision/install_kubeseal.sh index 40e2f164..0e715f94 100755 --- a/.assets/provision/install_kubeseal.sh +++ b/.assets/provision/install_kubeseal.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_kubeseal.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_kustomize.sh b/.assets/provision/install_kustomize.sh index 2b6fb787..bcf79b9c 100755 --- a/.assets/provision/install_kustomize.sh +++ b/.assets/provision/install_kustomize.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_kustomize.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_miniconda.sh b/.assets/provision/install_miniconda.sh index eeb621da..473ddb84 100755 --- a/.assets/provision/install_miniconda.sh +++ b/.assets/provision/install_miniconda.sh @@ -4,7 +4,7 @@ .assets/provision/install_miniconda.sh --fix_certify true ' if [ $EUID -eq 0 ]; then - printf '\e[31;1mDo not run the script as root.\e[0m\n' + printf '\e[31;1mDo not run the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_miniforge.sh b/.assets/provision/install_miniforge.sh index acd17889..3935fe0b 100755 --- a/.assets/provision/install_miniforge.sh +++ b/.assets/provision/install_miniforge.sh @@ -4,7 +4,7 @@ .assets/provision/install_miniforge.sh --fix_certify true ' if [ $EUID -eq 0 ]; then - printf '\e[31;1mDo not run the script as root.\e[0m\n' + printf '\e[31;1mDo not run the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_minikube.sh b/.assets/provision/install_minikube.sh index 5dffdecb..2385083f 100755 --- a/.assets/provision/install_minikube.sh +++ b/.assets/provision/install_minikube.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_minikube.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_npm.sh b/.assets/provision/install_npm.sh index 2f4668cb..73398e84 100755 --- a/.assets/provision/install_npm.sh +++ b/.assets/provision/install_npm.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_npm.sh ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_omp.sh b/.assets/provision/install_omp.sh index e7e95f17..de387af1 100755 --- a/.assets/provision/install_omp.sh +++ b/.assets/provision/install_omp.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_omp.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_podman.sh b/.assets/provision/install_podman.sh index 31424830..afa0fbb7 100755 --- a/.assets/provision/install_podman.sh +++ b/.assets/provision/install_podman.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_podman.sh ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_pwsh.sh b/.assets/provision/install_pwsh.sh index db2214de..081850d2 100755 --- a/.assets/provision/install_pwsh.sh +++ b/.assets/provision/install_pwsh.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_pwsh.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_ripgrep.sh b/.assets/provision/install_ripgrep.sh index 0661d5a6..c94efd9d 100755 --- a/.assets/provision/install_ripgrep.sh +++ b/.assets/provision/install_ripgrep.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_ripgrep.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_smee.sh b/.assets/provision/install_smee.sh index 24c0cdfc..c2c63d12 100755 --- a/.assets/provision/install_smee.sh +++ b/.assets/provision/install_smee.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_smee.sh ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_terraform.sh b/.assets/provision/install_terraform.sh index aa94cce2..775bc86d 100755 --- a/.assets/provision/install_terraform.sh +++ b/.assets/provision/install_terraform.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_terraform.sh ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_terrascan.sh b/.assets/provision/install_terrascan.sh index dc64a433..4a1fcd38 100755 --- a/.assets/provision/install_terrascan.sh +++ b/.assets/provision/install_terrascan.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_terrascan.sh ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_tfswitch.sh b/.assets/provision/install_tfswitch.sh index 1a61971f..f31e764d 100755 --- a/.assets/provision/install_tfswitch.sh +++ b/.assets/provision/install_tfswitch.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_tfswitch.sh ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_xrdp.sh b/.assets/provision/install_xrdp.sh index e68c9f82..ae128f43 100755 --- a/.assets/provision/install_xrdp.sh +++ b/.assets/provision/install_xrdp.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_xrdp.sh $(id -un) ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_yq.sh b/.assets/provision/install_yq.sh index 75306c5b..95795793 100755 --- a/.assets/provision/install_yq.sh +++ b/.assets/provision/install_yq.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_yq.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/install_zsh.sh b/.assets/provision/install_zsh.sh index 671c81f6..d5e51a8c 100755 --- a/.assets/provision/install_zsh.sh +++ b/.assets/provision/install_zsh.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_zsh.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/set_ulimits.sh b/.assets/provision/set_ulimits.sh index 3ab1208e..27b95934 100755 --- a/.assets/provision/set_ulimits.sh +++ b/.assets/provision/set_ulimits.sh @@ -3,7 +3,7 @@ sudo .assets/provision/set_ulimits.sh ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/setup_docker_mount.sh b/.assets/provision/setup_docker_mount.sh index 5826f24f..cdac9eea 100755 --- a/.assets/provision/setup_docker_mount.sh +++ b/.assets/provision/setup_docker_mount.sh @@ -3,7 +3,7 @@ sudo .assets\provision\setup_docker_mount.sh ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/setup_omp.sh b/.assets/provision/setup_omp.sh index 95ff3f0f..a0f1f875 100755 --- a/.assets/provision/setup_omp.sh +++ b/.assets/provision/setup_omp.sh @@ -10,7 +10,7 @@ sudo .assets/provision/setup_omp.sh --user $(id -un) --theme nerd sudo .assets/provision/setup_omp.sh --user $(id -un) --theme atomic ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/setup_profile_allusers.sh b/.assets/provision/setup_profile_allusers.sh index de1ffb1b..901e0a18 100755 --- a/.assets/provision/setup_profile_allusers.sh +++ b/.assets/provision/setup_profile_allusers.sh @@ -3,7 +3,7 @@ sudo .assets/provision/setup_profile_allusers.sh $(id -un) ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/setup_python.sh b/.assets/provision/setup_python.sh index 899f6b99..3aa7efbe 100755 --- a/.assets/provision/setup_python.sh +++ b/.assets/provision/setup_python.sh @@ -3,7 +3,7 @@ sudo .assets/provision/setup_python.sh ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi diff --git a/.assets/provision/upgrade_system.sh b/.assets/provision/upgrade_system.sh index a17ceb7a..8bbae421 100755 --- a/.assets/provision/upgrade_system.sh +++ b/.assets/provision/upgrade_system.sh @@ -3,7 +3,7 @@ sudo .assets/provision/upgrade_system.sh ' if [ $(id -u) -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi From cba7f9d7084f200b2496880daea4e06b3de7c050 Mon Sep 17 00:00:00 2001 From: Szymon Osiecki Date: Sun, 16 Jun 2024 23:02:45 +0200 Subject: [PATCH 03/13] feat(sh): source file with common functions --- .assets/provision/source.sh | 84 +++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 .assets/provision/source.sh diff --git a/.assets/provision/source.sh b/.assets/provision/source.sh new file mode 100644 index 00000000..6b933413 --- /dev/null +++ b/.assets/provision/source.sh @@ -0,0 +1,84 @@ +#!/usr/bin/env bash +: ' +. .assets/provision/source.sh +' +# function to download file from specified uri +download_file() { + # parse named parameters + local uri=${uri} + local target_dir=${target_dir:-'.'} + while [ $# -gt 0 ]; do + if [[ $1 == *"--"* ]]; then + param="${1/--/}" + declare $param="$2" + fi + shift + done + + if [ -z "$uri" ]; then + printf "\e[31mError: The \e[4muri\e[24m parameter is required.\e[0m\n" + return 1 + fi + + # define local variables + local file_name="$(basename $uri)" + local max_retries=10 + local retry_count=0 + + while [[ $retry_count -lt $max_retries ]]; do + # download file + status_code=$(curl -w %{http_code} -#Lko "$target_dir/$file_name" "$uri") + + # check the HTTP status code + case $status_code in + 200) + echo "Download successful. Ready to install." >&2 + return 0 + ;; + 404) + printf "\e[31mError: The file at the specified URL does not exist or is inaccessible:\n\e[0;4m${uri}\e[0m\n" >&2 + return 1 + ;; + *) + ((retry_count++)) + ;; + esac + done + + echo "Failed to download file after $max_retries attempts." >&2 + return 1 +} + +get_gh_release_latest() { + # parse named parameters + local owner=${owner} + local repo=${repo} + while [ $# -gt 0 ]; do + if [[ $1 == *"--"* ]]; then + param="${1/--/}" + declare $param="$2" + fi + shift + done + + if [[ -z "$owner" || -z "$repo" ]]; then + printf "\e[31mError: The \e[4mowner\e[24m and \e[4mrepo\e[24m parameters are required.\e[0m\n" + return 1 + fi + + # define local variables + local gh_api="https://api.github.com/repos/${owner}/${repo}/releases/latest" + + while [ -z "$rel" ]; do + rel=$(curl -sk "$gh_api" | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') + ((retry_count++)) + if [ $retry_count -eq 10 ]; then + printf "\e[33mLatest \e[4m${owner}/${repo}\e[24m version couldn't be retrieved.\e[0m\n" >&2 + return 1 + fi + [[ "$rel" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo 'retrying...' >&2 + done + + echo $rel + return 0 +} From e04f044d7b60910cbf1a64b6fc9ef04aa003f063 Mon Sep 17 00:00:00 2001 From: Szymon Osiecki Date: Sat, 15 Jun 2024 17:20:48 +0200 Subject: [PATCH 04/13] refactor(sh): use download_file function --- .assets/provision/install_argorolloutscli.sh | 16 +++-- .assets/provision/install_bat.sh | 37 +++++++----- .assets/provision/install_brew.sh | 18 ++++-- .assets/provision/install_etcdctl.sh | 19 +++--- .assets/provision/install_exa.sh | 24 ++++---- .assets/provision/install_eza.sh | 22 ++++--- .assets/provision/install_fastfetch.sh | 17 +++--- .../provision/install_fonts_cascadiacode.sh | 24 ++++---- .assets/provision/install_fonts_nerd.sh | 24 ++++---- .assets/provision/install_k9s.sh | 22 ++++--- .assets/provision/install_kubectl-convert.sh | 18 +++--- .assets/provision/install_kubectl.sh | 17 +++--- .assets/provision/install_kubelogin.sh | 18 +++--- .assets/provision/install_kubeseal.sh | 17 ++++-- .assets/provision/install_kustomize.sh | 22 ++++--- .assets/provision/install_miniconda.sh | 18 ++++-- .assets/provision/install_miniforge.sh | 16 +++-- .assets/provision/install_minikube.sh | 32 ++++++---- .assets/provision/install_omp.sh | 16 +++-- .assets/provision/install_pwsh.sh | 58 ++++++++++++------- .assets/provision/install_ripgrep.sh | 21 ++++--- .assets/provision/install_terrascan.sh | 19 +++--- .assets/provision/install_yq.sh | 19 +++--- 23 files changed, 312 insertions(+), 202 deletions(-) diff --git a/.assets/provision/install_argorolloutscli.sh b/.assets/provision/install_argorolloutscli.sh index 905866f4..608bcc3c 100755 --- a/.assets/provision/install_argorolloutscli.sh +++ b/.assets/provision/install_argorolloutscli.sh @@ -32,11 +32,15 @@ if type $APP &>/dev/null; then fi printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2 +# dotsource file with common functions +. .assets/provision/source.sh +# create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") -retry_count=0 -while [[ ! -f "$TMP_DIR/$APP" && $retry_count -lt 10 ]]; do - curl -#Lko "$TMP_DIR/$APP" "https://github.com/argoproj/argo-rollouts/releases/download/v${REL}/kubectl-argo-rollouts-linux-amd64" - ((retry_count++)) -done -install -m 0755 "$TMP_DIR/$APP" /usr/local/bin/kubectl-argo-rollouts +# calculate download uri +URL="https://github.com/argoproj/argo-rollouts/releases/download/v${REL}/kubectl-argo-rollouts-linux-amd64" +# download and install file +if download_file --uri $URL --target_dir $TMP_DIR; then + install -m 0755 "$TMP_DIR/$(basename $URL)" /usr/local/bin/kubectl-argo-rollouts +fi +# remove temporary dir rm -fr "$TMP_DIR" diff --git a/.assets/provision/install_bat.sh b/.assets/provision/install_bat.sh index c6fd08de..30aa53fe 100755 --- a/.assets/provision/install_bat.sh +++ b/.assets/provision/install_bat.sh @@ -62,13 +62,17 @@ fedora) ;; debian | ubuntu) export DEBIAN_FRONTEND=noninteractive + # dotsource file with common functions + . .assets/provision/source.sh + # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") - retry_count=0 - while [[ ! -f "$TMP_DIR/$APP.deb" && $retry_count -lt 10 ]]; do - curl -#Lko "$TMP_DIR/$APP.deb" "https://github.com/sharkdp/bat/releases/download/v${REL}/bat_${REL}_amd64.deb" - ((retry_count++)) - done - dpkg -i "$TMP_DIR/$APP.deb" >&2 2>/dev/null || binary=true + # calculate download uri + URL="https://github.com/sharkdp/bat/releases/download/v${REL}/bat_${REL}_amd64.deb" + # download and install file + if download_file --uri $URL --target_dir $TMP_DIR; then + dpkg -i "$TMP_DIR/$(basename $URL)" >&2 2>/dev/null || binary=true + fi + # remove temporary dir rm -fr "$TMP_DIR" ;; opensuse) @@ -81,14 +85,19 @@ esac if [ "$binary" = true ]; then echo 'Installing from binary.' >&2 + # dotsource file with common functions + . .assets/provision/source.sh + # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") - retry_count=0 - while [[ ! -f "$TMP_DIR/bat" && $retry_count -lt 10 ]]; do - curl -Lk "https://github.com/sharkdp/bat/releases/download/v${REL}/bat-v${REL}-x86_64-unknown-linux-gnu.tar.gz" | tar -zx --strip-components=1 -C "$TMP_DIR" - ((retry_count++)) - done - install -m 0755 "$TMP_DIR/bat" /usr/bin/ - install -m 0644 "$TMP_DIR/bat.1" "$(manpath | cut -d : -f 1)/man1/" - install -m 0644 "$TMP_DIR/autocomplete/bat.bash" /etc/bash_completion.d/ + # calculate download uri + URL="https://github.com/sharkdp/bat/releases/download/v${REL}/bat-v${REL}-x86_64-unknown-linux-gnu.tar.gz" + # download and install file + if download_file --uri $URL --target_dir $TMP_DIR; then + tar -zxf "$TMP_DIR/$(basename $URL)" --strip-components=1 -C "$TMP_DIR" + install -m 0755 "$TMP_DIR/bat" /usr/bin/ + install -m 0644 "$TMP_DIR/bat.1" "$(manpath | cut -d : -f 1)/man1/" + install -m 0644 "$TMP_DIR/autocomplete/bat.bash" /etc/bash_completion.d/ + fi + # remove temporary dir rm -fr "$TMP_DIR" fi diff --git a/.assets/provision/install_brew.sh b/.assets/provision/install_brew.sh index f9ce7bf3..aa999662 100755 --- a/.assets/provision/install_brew.sh +++ b/.assets/provision/install_brew.sh @@ -38,10 +38,16 @@ else export NONINTERACTIVE=1 # skip tap cloning export HOMEBREW_INSTALL_FROM_API=1 - # install Homebrew in the loop - retry_count=0 - while [[ ! -f /home/linuxbrew/.linuxbrew/bin/brew && $retry_count -lt 10 ]]; do - bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" - ((retry_count++)) - done + # dotsource file with common functions + . .assets/provision/source.sh + # create temporary dir for the downloaded binary + TMP_DIR=$(mktemp -dp "$PWD") + # calculate download uri + URL="https://raw.githubusercontent.com/Homebrew/install/master/install.sh" + # download and install homebrew + if download_file --uri $URL --target_dir $TMP_DIR; then + bash -c "$TMP_DIR/$(basename $URL)" + fi + # remove temporary dir + rm -fr "$TMP_DIR" fi diff --git a/.assets/provision/install_etcdctl.sh b/.assets/provision/install_etcdctl.sh index f6f9a7ad..5745ab9f 100755 --- a/.assets/provision/install_etcdctl.sh +++ b/.assets/provision/install_etcdctl.sh @@ -25,18 +25,23 @@ echo $REL if type $APP &>/dev/null; then VER=$(etcdctl version | sed -En 's/etcdctl version: ([0-9\.]+).*/\1/p') -if [ "$REL" = "$VER" ]; then + if [ "$REL" = "$VER" ]; then printf "\e[32m$APP v$VER is already latest\e[0m\n" >&2 exit 0 fi fi printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2 +# dotsource file with common functions +. .assets/provision/source.sh +# create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") -retry_count=0 -while [[ ! -f "$TMP_DIR/etcdctl" && $retry_count -lt 10 ]]; do - curl -#Lk "https://github.com/etcd-io/etcd/releases/download/v${REL}/etcd-v${REL}-linux-amd64.tar.gz" | tar -zx --strip-components=1 --no-same-owner -C "$TMP_DIR" - ((retry_count++)) -done -install -m 0755 "$TMP_DIR/etcdctl" /usr/local/bin/ +# calculate download uri +URL="https://github.com/etcd-io/etcd/releases/download/v${REL}/etcd-v${REL}-linux-amd64.tar.gz" +# download and install file +if download_file --uri $URL --target_dir $TMP_DIR; then + tar -zxf "$TMP_DIR/$(basename $URL)" --strip-components=1 --no-same-owner -C "$TMP_DIR" + install -m 0755 "$TMP_DIR/$(basename $URL)" /usr/local/bin/ +fi +# remove temporary dir rm -fr "$TMP_DIR" diff --git a/.assets/provision/install_exa.sh b/.assets/provision/install_exa.sh index 00b7a3f9..9cfc0576 100755 --- a/.assets/provision/install_exa.sh +++ b/.assets/provision/install_exa.sh @@ -74,16 +74,20 @@ esac if [ "$binary" = true ]; then echo 'Installing from binary.' >&2 + # dotsource file with common functions + . .assets/provision/source.sh + # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") - retry_count=0 - while [[ ! -f "$TMP_DIR/$APP.zip" && $retry_count -lt 10 ]]; do - curl -#Lko "$TMP_DIR/$APP.zip" "https://github.com/ogham/exa/releases/download/v${REL}/exa-linux-x86_64-v${REL}.zip" - ((retry_count++)) - done - unzip -q "$TMP_DIR/$APP.zip" -d "$TMP_DIR" - install -m 0755 "$TMP_DIR/bin/exa" /usr/bin/ - install -m 0644 "$TMP_DIR/man/exa.1" "$(manpath | cut -d : -f 1)/man1/" - install -m 0644 "$TMP_DIR/man/exa_colors.5" "$(manpath | cut -d : -f 1)/man5/" - install -m 0644 "$TMP_DIR/completions/exa.bash" /etc/bash_completion.d/ + # calculate download uri + URL="https://github.com/ogham/exa/releases/download/v${REL}/exa-linux-x86_64-v${REL}.zip" + # download and install file + if download_file --uri $URL --target_dir $TMP_DIR; then + unzip -q "$TMP_DIR/$(basename $URL)" -d "$TMP_DIR" + install -m 0755 "$TMP_DIR/bin/exa" /usr/bin/ + install -m 0644 "$TMP_DIR/man/exa.1" "$(manpath | cut -d : -f 1)/man1/" + install -m 0644 "$TMP_DIR/man/exa_colors.5" "$(manpath | cut -d : -f 1)/man5/" + install -m 0644 "$TMP_DIR/completions/exa.bash" /etc/bash_completion.d/ + fi + # remove temporary dir rm -fr "$TMP_DIR" fi diff --git a/.assets/provision/install_eza.sh b/.assets/provision/install_eza.sh index c18bf15f..033fdbe5 100755 --- a/.assets/provision/install_eza.sh +++ b/.assets/provision/install_eza.sh @@ -3,7 +3,7 @@ sudo .assets/provision/install_eza.sh >/dev/null ' if [ $EUID -ne 0 ]; then - printf '\e[31;1mRun the script as root.\e[0m\n' + printf '\e[31;1mRun the script as root.\e[0m\n' >&2 exit 1 fi @@ -76,7 +76,7 @@ debian | ubuntu) if [ ! -f /etc/apt/keyrings/gierens.gpg ]; then wget -qO- https://raw.githubusercontent.com/eza-community/eza/main/deb.asc | gpg --dearmor -o /etc/apt/keyrings/gierens.gpg fi - echo "deb [signed-by=/etc/apt/keyrings/gierens.gpg] http://deb.gierens.de stable main" | tee /etc/apt/sources.list.d/gierens.list + echo "deb [signed-by=/etc/apt/keyrings/gierens.gpg] http://deb.gierens.de stable main" >/etc/apt/sources.list.d/gierens.list chmod 644 /etc/apt/keyrings/gierens.gpg /etc/apt/sources.list.d/gierens.list apt-get update >&2 && apt-get install -y $APP >&2 2>/dev/null || binary=true ;; @@ -90,13 +90,17 @@ esac if [ "$binary" = true ]; then echo 'Installing from binary.' >&2 + # dotsource file with common functions + . .assets/provision/source.sh + # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") - retry_count=0 - while [[ ! -f "$TMP_DIR/$APP.tar.gz" && $retry_count -lt 10 ]]; do - curl -#Lko "$TMP_DIR/$APP.tar.gz" "https://github.com/eza-community/eza/releases/download/v${REL}/eza_x86_64-unknown-linux-${lib}.tar.gz" - ((retry_count++)) - done - tar -zxf "$TMP_DIR/$APP.tar.gz" -C "$TMP_DIR" - install -m 0755 "$TMP_DIR/eza" /usr/bin/ + # calculate download uri + URL="https://github.com/eza-community/eza/releases/download/v${REL}/eza_x86_64-unknown-linux-${lib}.tar.gz" + # download and install file + if download_file --uri $URL --target_dir $TMP_DIR; then + tar -zxf "$TMP_DIR/$(basename $URL)" -C "$TMP_DIR" + install -m 0755 "$TMP_DIR/eza" /usr/bin/ + fi + # remove temporary dir rm -fr "$TMP_DIR" fi diff --git a/.assets/provision/install_fastfetch.sh b/.assets/provision/install_fastfetch.sh index 8fd521cd..41a6e7cb 100755 --- a/.assets/provision/install_fastfetch.sh +++ b/.assets/provision/install_fastfetch.sh @@ -69,15 +69,18 @@ fedora) ;; debian | ubuntu) export DEBIAN_FRONTEND=noninteractive + # dotsource file with common functions + . .assets/provision/source.sh + # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") - retry_count=0 - while [[ ! -f "$TMP_DIR/$APP.deb" && $retry_count -lt 10 ]]; do - curl -#Lko "$TMP_DIR/$APP.deb" "https://github.com/fastfetch-cli/fastfetch/releases/download/${REL}/fastfetch-linux-amd64.deb" - ((retry_count++)) - done - dpkg -i "$TMP_DIR/$APP.deb" >&2 2>/dev/null + # calculate download uri + URL="https://github.com/fastfetch-cli/fastfetch/releases/download/${REL}/fastfetch-linux-amd64.deb" + # download and install file + if download_file --uri $URL --target_dir $TMP_DIR; then + dpkg -i "$TMP_DIR/$(basename $URL)" >&2 2>/dev/null + fi + # remove temporary dir rm -fr "$TMP_DIR" - ;; opensuse) zypper in -y $APP >&2 2>/dev/null ;; diff --git a/.assets/provision/install_fonts_cascadiacode.sh b/.assets/provision/install_fonts_cascadiacode.sh index cdf10cb4..661a1a24 100755 --- a/.assets/provision/install_fonts_cascadiacode.sh +++ b/.assets/provision/install_fonts_cascadiacode.sh @@ -25,15 +25,19 @@ done echo $REL echo "Install CascadiaCode v$REL" >&2 +# dotsource file with common functions +. .assets/provision/source.sh +# create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") -retry_count=0 -while [[ ! -f "$TMP_DIR/CascadiaCode.zip" && $retry_count -lt 10 ]]; do - curl -#Lko "$TMP_DIR/CascadiaCode.zip" "https://github.com/microsoft/cascadia-code/releases/download/v${REL}/CascadiaCode-${REL}.zip" - ((retry_count++)) -done -unzip -q "$TMP_DIR/CascadiaCode.zip" -d "$TMP_DIR" -mkdir -p /usr/share/fonts/cascadia-code -find "$TMP_DIR/ttf" -type f -name "*.ttf" -exec cp {} /usr/share/fonts/cascadia-code/ \; +# calculate download uri +URL="https://github.com/microsoft/cascadia-code/releases/download/v${REL}/CascadiaCode-${REL}.zip" +# download and install file +if download_file --uri $URL --target_dir $TMP_DIR; then + unzip -q "$TMP_DIR/$(basename $URL)" -d "$TMP_DIR" + mkdir -p /usr/share/fonts/cascadia-code + find "$TMP_DIR/ttf" -type f -name "*.ttf" -exec cp {} /usr/share/fonts/cascadia-code/ \; + # build font information caches + fc-cache -f /usr/share/fonts/cascadia-code/ +fi +# remove temporary dir rm -fr "$TMP_DIR" -# build font information caches -fc-cache -f /usr/share/fonts/cascadia-code/ diff --git a/.assets/provision/install_fonts_nerd.sh b/.assets/provision/install_fonts_nerd.sh index 051eb4aa..0240fe75 100755 --- a/.assets/provision/install_fonts_nerd.sh +++ b/.assets/provision/install_fonts_nerd.sh @@ -85,25 +85,23 @@ if [ -n "$1" ]; then fc-cache -f /usr/share/fonts else echo "installing '$font' font..." >&2 - http_code=$(curl -Lo /dev/null --silent -Iw '%{http_code}' "https://github.com/ryanoasis/nerd-fonts/releases/latest/download/${font}.zip") - if [ $http_code -eq 200 ]; then - TMP_DIR=$(mktemp -dp "$PWD") - retry_count=0 - while [[ ! -f "$TMP_DIR/$font.zip" && $retry_count -lt 10 ]]; do - curl -#Lko "$TMP_DIR/$font.zip" "https://github.com/ryanoasis/nerd-fonts/releases/latest/download/${font}.zip" - ((retry_count++)) - done - unzip -q "$TMP_DIR/$font.zip" -d "$TMP_DIR" + # dotsource file with common functions + . .assets/provision/source.sh + # create temporary dir for the downloaded binary + TMP_DIR=$(mktemp -dp "$PWD") + # calculate download uri + URL="https://github.com/ryanoasis/nerd-fonts/releases/latest/download/${font}.zip" + # download and install file + if download_file --uri $URL --target_dir $TMP_DIR; then + unzip -q "$TMP_DIR/$(basename $URL)" -d "$TMP_DIR" rm -f "$TMP_DIR/*Compatible.ttf" mkdir -p /usr/share/fonts/${font,,}-nf find "$TMP_DIR" -type f -name "*.ttf" -exec cp {} /usr/share/fonts/${font,,}-nf/ \; - rm -fr "$TMP_DIR" # build font information caches fc-cache -f /usr/share/fonts/${font,,}-nf - else - printf '\e[31;1mFont "'$font'" not found on GitHub.\e[0m\n' >&2 - exit 1 fi + # remove temporary dir + rm -fr "$TMP_DIR" fi else printf '\e[31;1mProvide font name.\e[0m\n' >&2 diff --git a/.assets/provision/install_k9s.sh b/.assets/provision/install_k9s.sh index 3ae9f5c3..e0ad73ef 100755 --- a/.assets/provision/install_k9s.sh +++ b/.assets/provision/install_k9s.sh @@ -32,14 +32,18 @@ if type $APP &>/dev/null; then fi printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2 +# dotsource file with common functions +. .assets/provision/source.sh +# create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") -retry_count=0 -while [[ ! -f "$TMP_DIR/k9s.tar.gz" && $retry_count -lt 10 ]]; do - curl -#Lko "$TMP_DIR/k9s.tar.gz" "https://github.com/derailed/k9s/releases/download/v${REL}/k9s_Linux_amd64.tar.gz" - ((retry_count++)) -done -tar -zxvf "$TMP_DIR/k9s.tar.gz" -C "$TMP_DIR" -mkdir -p /opt/k9s -install -m 0755 "$TMP_DIR/k9s" /opt/k9s/ -[ -f /usr/bin/k9s ] || ln -s /opt/k9s/k9s /usr/bin/k9s +# calculate download uri +URL="https://github.com/derailed/k9s/releases/download/v${REL}/k9s_Linux_amd64.tar.gz" +# download and install file +if download_file --uri $URL --target_dir $TMP_DIR; then + tar -zxf "$TMP_DIR/$(basename $URL)" -C "$TMP_DIR" + mkdir -p /opt/k9s + install -m 0755 "$TMP_DIR/k9s" /opt/k9s/ + [ -f /usr/bin/k9s ] || ln -s /opt/k9s/k9s /usr/bin/k9s +fi +# remove temporary dir rm -fr "$TMP_DIR" diff --git a/.assets/provision/install_kubectl-convert.sh b/.assets/provision/install_kubectl-convert.sh index ae2e9d4a..4112f7cf 100755 --- a/.assets/provision/install_kubectl-convert.sh +++ b/.assets/provision/install_kubectl-convert.sh @@ -9,12 +9,16 @@ fi APP='kubectl-convert' +# dotsource file with common functions +. .assets/provision/source.sh +# create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") -retry_count=0 -while [[ ! -f "$TMP_DIR/$APP" && $retry_count -lt 10 ]]; do - curl -#Lko "$TMP_DIR/$APP" "https://dl.k8s.io/release/$(curl -sLk https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl-convert" - ((retry_count++)) -done -# install -install -m 0755 "$TMP_DIR/$APP" /usr/bin/ +# calculate download uri +URL="https://dl.k8s.io/release/$(curl -sLk https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl-convert" +# download and install file +if download_file --uri $URL --target_dir $TMP_DIR; then + tar -zxf "$TMP_DIR/$(basename $URL)" -C "$TMP_DIR" + install -m 0755 "$TMP_DIR/$(basename $URL)" /usr/bin/ +fi +# remove temporary dir rm -fr "$TMP_DIR" diff --git a/.assets/provision/install_kubectl.sh b/.assets/provision/install_kubectl.sh index 3d36e270..3c3d17ec 100755 --- a/.assets/provision/install_kubectl.sh +++ b/.assets/provision/install_kubectl.sh @@ -52,13 +52,16 @@ esac if [ "$binary" = true ]; then echo 'Installing from binary.' >&2 + # dotsource file with common functions + . .assets/provision/source.sh + # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") - retry_count=0 - while [[ ! -f "$TMP_DIR/$APP" && $retry_count -lt 10 ]]; do - curl -#Lko "$TMP_DIR/$APP" "https://dl.k8s.io/release/$(curl -sLk https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" - ((retry_count++)) - done - # install - install -m 0755 "$TMP_DIR/$APP" /usr/bin/ + # calculate download uri + URL="https://dl.k8s.io/release/$(curl -sLk https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" + # download and install file + if download_file --uri $URL --target_dir $TMP_DIR; then + install -m 0755 "$TMP_DIR/$(basename $URL)" /usr/bin/ + fi + # remove temporary dir rm -fr "$TMP_DIR" fi diff --git a/.assets/provision/install_kubelogin.sh b/.assets/provision/install_kubelogin.sh index 5fad3782..a850886b 100755 --- a/.assets/provision/install_kubelogin.sh +++ b/.assets/provision/install_kubelogin.sh @@ -32,12 +32,16 @@ if type $APP &>/dev/null; then fi printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2 +# dotsource file with common functions +. .assets/provision/source.sh +# create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") -retry_count=0 -while [[ ! -f "$TMP_DIR/$APP.zip" && $retry_count -lt 10 ]]; do - curl -#Lko "$TMP_DIR/$APP.zip" "https://github.com/Azure/kubelogin/releases/download/v${REL}/kubelogin-linux-amd64.zip" - ((retry_count++)) -done -unzip -q "$TMP_DIR/$APP.zip" -d "$TMP_DIR" -install -m 0755 "$TMP_DIR/bin/linux_amd64/kubelogin" /usr/local/bin/ +# calculate download uri +URL="https://github.com/Azure/kubelogin/releases/download/v${REL}/kubelogin-linux-amd64.zip" +# download and install file +if download_file --uri $URL --target_dir $TMP_DIR; then + unzip -q "$TMP_DIR/$(basename $URL)" -d "$TMP_DIR" + install -m 0755 "$TMP_DIR/bin/linux_amd64/kubelogin" /usr/local/bin/ +fi +# remove temporary dir rm -fr "$TMP_DIR" diff --git a/.assets/provision/install_kubeseal.sh b/.assets/provision/install_kubeseal.sh index 0e715f94..feb31610 100755 --- a/.assets/provision/install_kubeseal.sh +++ b/.assets/provision/install_kubeseal.sh @@ -32,11 +32,16 @@ if type $APP &>/dev/null; then fi printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2 +# dotsource file with common functions +. .assets/provision/source.sh +# create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") -retry_count=0 -while [[ ! -f "$TMP_DIR/$APP" && $retry_count -lt 10 ]]; do - curl -#Lk "https://github.com/bitnami-labs/sealed-secrets/releases/download/v${REL:?}/kubeseal-${REL:?}-linux-amd64.tar.gz" | tar -zx -C "$TMP_DIR" - ((retry_count++)) -done -install -m 0755 "$TMP_DIR/$APP" /usr/local/bin/ +# calculate download uri +URL="https://github.com/bitnami-labs/sealed-secrets/releases/download/v${REL:?}/kubeseal-${REL:?}-linux-amd64.tar.gz" +# download and install file +if download_file --uri $URL --target_dir $TMP_DIR; then + tar -zxf "$TMP_DIR/$(basename $URL)" -C "$TMP_DIR" + install -m 0755 "$TMP_DIR/$APP" /usr/local/bin/ +fi +# remove temporary dir rm -fr "$TMP_DIR" diff --git a/.assets/provision/install_kustomize.sh b/.assets/provision/install_kustomize.sh index bcf79b9c..86a45768 100755 --- a/.assets/provision/install_kustomize.sh +++ b/.assets/provision/install_kustomize.sh @@ -31,12 +31,16 @@ if type $APP &>/dev/null; then fi fi -retry_count=0 -while [[ ! -f kustomize && $retry_count -lt 10 ]]; do - curl -sk 'https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh' | bash - ((retry_count++)) -done -install -m 0755 kustomize /usr/local/bin/ -rm -f kustomize - -exit 0 +# dotsource file with common functions +. .assets/provision/source.sh +# create temporary dir for the downloaded binary +TMP_DIR=$(mktemp -dp "$PWD") +# calculate download uri +URL='https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh' +# download and install file +if download_file --uri $URL --target_dir $TMP_DIR; then + bash -C "$TMP_DIR/$(basename $URL)" + install -m 0755 kustomize /usr/bin/ +fi +# remove temporary dir +rm -fr kustomizell "$TMP_DIR" diff --git a/.assets/provision/install_miniconda.sh b/.assets/provision/install_miniconda.sh index 473ddb84..9b88404a 100755 --- a/.assets/provision/install_miniconda.sh +++ b/.assets/provision/install_miniconda.sh @@ -42,14 +42,20 @@ if [ -d "$HOME/miniconda3" ]; then conda_init else printf "\e[92minstalling \e[1mminiconda\e[0m\n" + # dotsource file with common functions + . .assets/provision/source.sh + # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") - retry_count=0 - while [[ ! -f "$TMP_DIR/miniconda.sh" && $retry_count -lt 10 ]]; do - curl -#Lko "$TMP_DIR/miniconda.sh" https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh - ((retry_count++)) - done - bash $TMP_DIR/miniconda.sh -b -p "$HOME/miniconda3" >/dev/null + # calculate download uri + URL="https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh" + # download and install file + if download_file --uri $URL --target_dir $TMP_DIR; then + bash -C "$TMP_DIR/$(basename $URL)" -b -p "$HOME/miniconda3" >/dev/null + install -m 0755 "$TMP_DIR/eza" /usr/bin/ + fi + # remove temporary dir rm -fr "$TMP_DIR" + # disable auto activation of the base conda environment conda_init conda config --set auto_activate_base false diff --git a/.assets/provision/install_miniforge.sh b/.assets/provision/install_miniforge.sh index 3935fe0b..b7c0d1c3 100755 --- a/.assets/provision/install_miniforge.sh +++ b/.assets/provision/install_miniforge.sh @@ -42,13 +42,17 @@ if [ -d "$HOME/miniforge3" ]; then conda_init else printf "\e[92minstalling \e[1mminiforge\e[0m\n" + # dotsource file with common functions + . .assets/provision/source.sh + # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") - retry_count=0 - while [[ ! -f "$TMP_DIR/miniforge.sh" && $retry_count -lt 10 ]]; do - curl -#Lko "$TMP_DIR/miniforge.sh" "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh" - ((retry_count++)) - done - bash $TMP_DIR/miniforge.sh -b -p "$HOME/miniforge3" >/dev/null + # calculate download uri + URL="https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh" + # download and install file + if download_file --uri $URL --target_dir $TMP_DIR; then + bash -C "$TMP_DIR/$(basename $URL)" -b -p "$HOME/miniforge3" >/dev/null + fi + # remove temporary dir rm -fr "$TMP_DIR" # disable auto activation of the base conda environment conda_init diff --git a/.assets/provision/install_minikube.sh b/.assets/provision/install_minikube.sh index 2385083f..d4acb665 100755 --- a/.assets/provision/install_minikube.sh +++ b/.assets/provision/install_minikube.sh @@ -53,13 +53,17 @@ fedora) ;; debian | ubuntu) export DEBIAN_FRONTEND=noninteractive + # dotsource file with common functions + . .assets/provision/source.sh + # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") - retry_count=0 - while [[ ! -f "$TMP_DIR/$APP.deb" && $retry_count -lt 10 ]]; do - curl -#Lko "$TMP_DIR/$APP.deb" "https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb" - ((retry_count++)) - done - dpkg -i "$TMP_DIR/$APP.deb" >&2 2>/dev/null || binary=true + # calculate download uri + URL="https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb" + # download and install file + if download_file --uri $URL --target_dir $TMP_DIR; then + dpkg -i "$TMP_DIR/$(basename $URL)" >&2 2>/dev/null || binary=true + fi + # remove temporary dir rm -fr "$TMP_DIR" ;; opensuse) @@ -72,12 +76,16 @@ esac if [ "$binary" = true ]; then echo 'Installing from binary.' >&2 + # dotsource file with common functions + . .assets/provision/source.sh + # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") - retry_count=0 - while [[ ! -f "$TMP_DIR/$APP" && $retry_count -lt 10 ]]; do - curl -#Lko "$TMP_DIR/$APP" "https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64" - ((retry_count++)) - done - install -m 0755 "$TMP_DIR/$APP" /usr/local/bin/minikube + # calculate download uri + URL="https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64" + # download and install file + if download_file --uri $URL --target_dir $TMP_DIR; then + install -m 0755 "$TMP_DIR/$(basename $URL)" /usr/local/bin/minikube + fi + # remove temporary dir rm -fr "$TMP_DIR" fi diff --git a/.assets/provision/install_omp.sh b/.assets/provision/install_omp.sh index de387af1..e7de4de4 100755 --- a/.assets/provision/install_omp.sh +++ b/.assets/provision/install_omp.sh @@ -32,11 +32,15 @@ if type $APP &>/dev/null; then fi printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2 +# dotsource file with common functions +. .assets/provision/source.sh +# create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") -retry_count=0 -while [[ ! -f "$TMP_DIR/$APP" && $retry_count -lt 10 ]]; do - curl -#Lko "$TMP_DIR/$APP" "https://github.com/JanDeDobbeleer/oh-my-posh/releases/download/v${REL}/posh-linux-amd64" - ((retry_count++)) -done -install -m 0755 "$TMP_DIR/$APP" /usr/bin/oh-my-posh +# calculate download uri +URL="https://github.com/JanDeDobbeleer/oh-my-posh/releases/download/v${REL}/posh-linux-amd64" +# download and install file +if download_file --uri $URL --target_dir $TMP_DIR; then + install -m 0755 "$TMP_DIR/$(basename $URL)" /usr/bin/oh-my-posh +fi +# remove temporary dir rm -fr "$TMP_DIR" diff --git a/.assets/provision/install_pwsh.sh b/.assets/provision/install_pwsh.sh index 081850d2..7af49582 100755 --- a/.assets/provision/install_pwsh.sh +++ b/.assets/provision/install_pwsh.sh @@ -39,15 +39,21 @@ case $SYS_ID in alpine) apk add --no-cache ncurses-terminfo-base krb5-libs libgcc libintl libssl1.1 libstdc++ tzdata userspace-rcu zlib icu-libs >&2 2>/dev/null apk -X https://dl-cdn.alpinelinux.org/alpine/edge/main add --no-cache lttng-ust >&2 2>/dev/null + # dotsource file with common functions + . .assets/provision/source.sh + # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") - retry_count=0 - while [[ ! -f "$TMP_DIR/$APP.tar.gz" && $retry_count -lt 10 ]]; do - curl -#Lko "$TMP_DIR/$APP.tar.gz" "https://github.com/PowerShell/PowerShell/releases/download/v${REL}/powershell-${REL}-linux-alpine-x64.tar.gz" - ((retry_count++)) - done - mkdir -p /opt/microsoft/powershell/7 && tar -zxf "$TMP_DIR/$APP.tar.gz" -C /opt/microsoft/powershell/7 + # calculate download uri + URL="https://github.com/PowerShell/PowerShell/releases/download/v${REL}/powershell-${REL}-linux-alpine-x64.tar.gz" + # download and install file + if download_file --uri $URL --target_dir $TMP_DIR; then + mkdir -p /opt/microsoft/powershell/7 + tar -zxf "$TMP_DIR/$(basename $URL)" -C /opt/microsoft/powershell/7 + chmod +x /opt/microsoft/powershell/7/pwsh + ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh + fi + # remove temporary dir rm -fr "$TMP_DIR" - chmod +x /opt/microsoft/powershell/7/pwsh && ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh ;; arch) if pacman -Qqe paru &>/dev/null; then @@ -76,13 +82,17 @@ debian | ubuntu) else export DEBIAN_FRONTEND=noninteractive [ "$SYS_ID" = 'debian' ] && apt-get update >&2 && apt-get install -y libicu67 >&2 2>/dev/null || true + # dotsource file with common functions + . .assets/provision/source.sh + # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") - retry_count=0 - while [[ ! -f "$TMP_DIR/$APP.deb" && $retry_count -lt 10 ]]; do - curl -#Lko "$TMP_DIR/$APP.deb" "https://github.com/PowerShell/PowerShell/releases/download/v${REL}/powershell_${REL}-1.deb_amd64.deb" - ((retry_count++)) - done - dpkg -i "$TMP_DIR/$APP.deb" >&2 2>/dev/null || binary=true + # calculate download uri + URL="https://github.com/PowerShell/PowerShell/releases/download/v${REL}/powershell_${REL}-1.deb_amd64.deb" + # download and install file + if download_file --uri $URL --target_dir $TMP_DIR; then + dpkg -i "$TMP_DIR/$(basename $URL)" >&2 2>/dev/null || binary=true + fi + # remove temporary dir rm -fr "$TMP_DIR" fi ;; @@ -94,15 +104,19 @@ esac if [ "$binary" = true ]; then echo 'Installing from binary.' >&2 [ "$SYS_ID" = 'opensuse' ] && zypper in -y libicu >&2 2>/dev/null || true + # dotsource file with common functions + . .assets/provision/source.sh + # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") - retry_count=0 - while [[ ! -f "$TMP_DIR/$APP.tar.gz" && $retry_count -lt 10 ]]; do - curl -#Lko "$TMP_DIR/$APP.tar.gz" "https://github.com/PowerShell/PowerShell/releases/download/v${REL}/powershell-${REL}-linux-x64.tar.gz" - ((retry_count++)) - done - mkdir -p /opt/microsoft/powershell/7 - tar -zxf "$TMP_DIR/$APP.tar.gz" -C /opt/microsoft/powershell/7 + # calculate download uri + URL="https://github.com/PowerShell/PowerShell/releases/download/v${REL}/powershell-${REL}-linux-x64.tar.gz" + # download and install file + if download_file --uri $URL --target_dir $TMP_DIR; then + mkdir -p /opt/microsoft/powershell/7 + tar -zxf "$TMP_DIR/$(basename $URL)" -C /opt/microsoft/powershell/7 + chmod +x /opt/microsoft/powershell/7/pwsh + [ -f /usr/bin/pwsh ] || ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh + fi + # remove temporary dir rm -fr "$TMP_DIR" - chmod +x /opt/microsoft/powershell/7/pwsh - [ -f /usr/bin/pwsh ] || ln -s /opt/microsoft/powershell/7/pwsh /usr/bin/pwsh fi diff --git a/.assets/provision/install_ripgrep.sh b/.assets/provision/install_ripgrep.sh index c94efd9d..a5b549b5 100755 --- a/.assets/provision/install_ripgrep.sh +++ b/.assets/provision/install_ripgrep.sh @@ -74,14 +74,19 @@ esac if [ "$binary" = true ]; then echo 'Installing from binary.' >&2 + # dotsource file with common functions + . .assets/provision/source.sh + # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") - retry_count=0 - while [[ ! -f "$TMP_DIR/rg" && $retry_count -lt 10 ]]; do - curl -#Lk "https://github.com/BurntSushi/ripgrep/releases/download/${REL}/ripgrep-${REL}-x86_64-unknown-linux-musl.tar.gz" | tar -zx --strip-components=1 -C "$TMP_DIR" - ((retry_count++)) - done - install -m 0755 "$TMP_DIR/rg" /usr/bin/ - install -m 0644 "$TMP_DIR/doc/rg.1" "$(manpath | cut -d : -f 1)/man1/" - install -m 0644 "$TMP_DIR/complete/rg.bash" /etc/bash_completion.d/ + # calculate download uri + URL="https://github.com/BurntSushi/ripgrep/releases/download/${REL}/ripgrep-${REL}-aarch64-unknown-linux-gnu.tar.gz" + # download and install file + if download_file --uri $URL --target_dir $TMP_DIR; then + tar -zxf "$TMP_DIR/$(basename $URL)" --strip-components=1 -C "$TMP_DIR" + install -m 0755 "$TMP_DIR/rg" /usr/bin/ + install -m 0644 "$TMP_DIR/doc/rg.1" "$(manpath | cut -d : -f 1)/man1/" + install -m 0644 "$TMP_DIR/complete/rg.bash" /etc/bash_completion.d/ + fi + # remove temporary dir rm -fr "$TMP_DIR" fi diff --git a/.assets/provision/install_terrascan.sh b/.assets/provision/install_terrascan.sh index 4a1fcd38..3671d9b8 100755 --- a/.assets/provision/install_terrascan.sh +++ b/.assets/provision/install_terrascan.sh @@ -29,13 +29,16 @@ if type $APP &>/dev/null; then fi printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2 +# dotsource file with common functions +. .assets/provision/source.sh +# create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") -retry_count=0 -while [[ ! -f "$TMP_DIR/terrascan" && $retry_count -lt 10 ]]; do - curl -#Lk "https://github.com/tenable/terrascan/releases/download/v${REL}/terrascan_${REL}_Linux_x86_64.tar.gz" | tar -zx -C "$TMP_DIR" - ((retry_count++)) -done -install -m 0755 "$TMP_DIR/terrascan" /usr/bin/ +# calculate download uri +URL="https://github.com/tenable/terrascan/releases/download/v${REL}/terrascan_${REL}_Linux_x86_64.tar.gz" +# download and install file +if download_file --uri $URL --target_dir $TMP_DIR; then + tar -zxf "$TMP_DIR/$(basename $URL)" -C "$TMP_DIR" + install -m 0755 "$TMP_DIR/terrascan" /usr/bin/ +fi +# remove temporary dir rm -fr "$TMP_DIR" - -exit 0 diff --git a/.assets/provision/install_yq.sh b/.assets/provision/install_yq.sh index 95795793..50a19fd5 100755 --- a/.assets/provision/install_yq.sh +++ b/.assets/provision/install_yq.sh @@ -32,12 +32,17 @@ if type $APP &>/dev/null; then fi printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2 +# dotsource file with common functions +. .assets/provision/source.sh +# create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") -retry_count=0 -while [[ ! -f "$TMP_DIR/yq_linux_amd64" && $retry_count -lt 10 ]]; do - curl -#Lk "https://github.com/mikefarah/yq/releases/download/v${REL}/yq_linux_amd64.tar.gz" | tar -zx -C "$TMP_DIR" - ((retry_count++)) -done -install -m 0755 "$TMP_DIR/yq_linux_amd64" /usr/local/bin/yq -pushd "$TMP_DIR" >/dev/null && bash ./install-man-page.sh && popd >/dev/null +# calculate download uri +URL="https://github.com/mikefarah/yq/releases/download/v${REL}/yq_linux_amd64.tar.gz" +# download and install file +if download_file --uri $URL --target_dir $TMP_DIR; then + tar -zxf "$TMP_DIR/$(basename $URL)" -C "$TMP_DIR" + install -m 0755 "$TMP_DIR/yq_linux_amd64" /usr/local/bin/yq + pushd "$TMP_DIR" >/dev/null && bash ./install-man-page.sh && popd >/dev/null +fi +# remove temporary dir rm -fr "$TMP_DIR" From 9e227f7c501635efd6dc067809b683dee1007f2a Mon Sep 17 00:00:00 2001 From: Szymon Osiecki Date: Mon, 17 Jun 2024 08:50:32 +0200 Subject: [PATCH 05/13] refactor(sh): get GH latest release using function --- .assets/provision/install_argorolloutscli.sh | 25 ++++--- .assets/provision/install_azurecli.sh | 2 +- .assets/provision/install_bat.sh | 20 ++---- .assets/provision/install_brew.sh | 18 ++--- .assets/provision/install_docker.sh | 2 +- .assets/provision/install_etcdctl.sh | 25 ++++--- .assets/provision/install_exa.sh | 20 ++---- .assets/provision/install_eza.sh | 41 ++++------- .assets/provision/install_fastfetch.sh | 19 ++--- .assets/provision/install_flux.sh | 16 ++--- .../provision/install_fonts_cascadiacode.sh | 24 +++---- .assets/provision/install_gh.sh | 20 +++--- .assets/provision/install_helm.sh | 16 ++--- .assets/provision/install_k3d.sh | 16 ++--- .assets/provision/install_k9s.sh | 25 ++++--- .assets/provision/install_kubelogin.sh | 25 ++++--- .assets/provision/install_kubeseal.sh | 25 ++++--- .assets/provision/install_kustomize.sh | 22 +++--- .assets/provision/install_minikube.sh | 20 ++---- .assets/provision/install_omp.sh | 25 ++++--- .assets/provision/install_pwsh.sh | 24 ++----- .assets/provision/install_ripgrep.sh | 20 ++---- .assets/provision/install_terraform.sh | 18 ++--- .assets/provision/install_terrascan.sh | 23 +++--- .assets/provision/install_tfswitch.sh | 18 +++-- .assets/provision/install_xrdp.sh | 2 +- .assets/provision/install_yq.sh | 25 ++++--- .assets/provision/source.sh | 70 +++++++++++++++---- 28 files changed, 275 insertions(+), 331 deletions(-) diff --git a/.assets/provision/install_argorolloutscli.sh b/.assets/provision/install_argorolloutscli.sh index 608bcc3c..a5ae5d57 100755 --- a/.assets/provision/install_argorolloutscli.sh +++ b/.assets/provision/install_argorolloutscli.sh @@ -7,21 +7,22 @@ if [ $EUID -ne 0 ]; then exit 1 fi +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables APP='kubectl-argo-rollouts' REL=$1 retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/argoproj/argo-rollouts/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 +# get latest release if not provided as a parameter +if [ -z "$REL" ]; then + if REL="$(get_gh_release_latest --owner 'argoproj' --repo 'argo-rollouts')"; then + # return latest release + echo $REL + else + exit 1 fi - [[ "$REL" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo 'retrying...' >&2 -done -# return latest release -echo $REL +fi if type $APP &>/dev/null; then VER=$(kubectl-argo-rollouts version --short | sed -En 's/.*v([0-9\.]+).*/\1/p') @@ -32,8 +33,6 @@ if type $APP &>/dev/null; then fi printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2 -# dotsource file with common functions -. .assets/provision/source.sh # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri diff --git a/.assets/provision/install_azurecli.sh b/.assets/provision/install_azurecli.sh index ac4fb048..420867a7 100755 --- a/.assets/provision/install_azurecli.sh +++ b/.assets/provision/install_azurecli.sh @@ -45,7 +45,7 @@ if ! conda env list | grep -qw '^azurecli'; then conda create --name azurecli --yes python=3.11 pip else # https://github.com/conda/conda/issues/12051 - conda create --name azurecli --yes python=3.11 pip numpy-base + conda create --name azurecli --yes python=3.11 pip numpy==1.26.4 fonttools==4.53.0 fi fi conda activate azurecli diff --git a/.assets/provision/install_bat.sh b/.assets/provision/install_bat.sh index 30aa53fe..6f3caaa5 100755 --- a/.assets/provision/install_bat.sh +++ b/.assets/provision/install_bat.sh @@ -26,18 +26,14 @@ debian | ubuntu) ;; esac +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables REL=$1 retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/sharkdp/bat/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 - fi - [[ "$REL" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo 'retrying...' >&2 -done +# get latest release if not provided as a parameter +[ -z "$REL" ] && REL="$(get_gh_release_latest --owner 'sharkdp' --repo 'bat')" # return latest release echo $REL @@ -62,8 +58,6 @@ fedora) ;; debian | ubuntu) export DEBIAN_FRONTEND=noninteractive - # dotsource file with common functions - . .assets/provision/source.sh # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri @@ -85,8 +79,6 @@ esac if [ "$binary" = true ]; then echo 'Installing from binary.' >&2 - # dotsource file with common functions - . .assets/provision/source.sh # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri diff --git a/.assets/provision/install_brew.sh b/.assets/provision/install_brew.sh index aa999662..155f85a9 100755 --- a/.assets/provision/install_brew.sh +++ b/.assets/provision/install_brew.sh @@ -8,19 +8,15 @@ if [ $EUID -eq 0 ]; then exit 1 fi +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables APP='brew' REL=$1 retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/Homebrew/brew/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 - fi - [[ "$REL" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo 'retrying...' >&2 -done +# get latest release if not provided as a parameter +[ -z "$REL" ] && REL="$(get_gh_release_latest --owner 'Homebrew' --repo 'brew')" # return latest release echo $REL @@ -38,8 +34,6 @@ else export NONINTERACTIVE=1 # skip tap cloning export HOMEBREW_INSTALL_FROM_API=1 - # dotsource file with common functions - . .assets/provision/source.sh # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri diff --git a/.assets/provision/install_docker.sh b/.assets/provision/install_docker.sh index 58d96060..4041f515 100755 --- a/.assets/provision/install_docker.sh +++ b/.assets/provision/install_docker.sh @@ -52,7 +52,7 @@ debian | ubuntu) curl -fsSLk "https://download.docker.com/linux/$SYS_ID/gpg" | gpg --dearmor -o /etc/apt/keyrings/docker.gpg echo \ "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/$SYS_ID \ - "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | tee /etc/apt/sources.list.d/docker.list >/dev/null + "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" >/etc/apt/sources.list.d/docker.list fi apt-get update && apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-compose ;; diff --git a/.assets/provision/install_etcdctl.sh b/.assets/provision/install_etcdctl.sh index 5745ab9f..06c30016 100755 --- a/.assets/provision/install_etcdctl.sh +++ b/.assets/provision/install_etcdctl.sh @@ -7,21 +7,22 @@ if [ $EUID -ne 0 ]; then exit 1 fi +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables APP='etcdctl' REL=$1 retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/etcd-io/etcd/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 +# get latest release if not provided as a parameter +if [ -z "$REL" ]; then + if REL="$(get_gh_release_latest --owner 'etcd-io' --repo 'etcd')"; then + # return latest release + echo $REL + else + exit 1 fi - [[ "$REL" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo 'retrying...' >&2 -done -# return latest release -echo $REL +fi if type $APP &>/dev/null; then VER=$(etcdctl version | sed -En 's/etcdctl version: ([0-9\.]+).*/\1/p') @@ -32,8 +33,6 @@ if type $APP &>/dev/null; then fi printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2 -# dotsource file with common functions -. .assets/provision/source.sh # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri diff --git a/.assets/provision/install_exa.sh b/.assets/provision/install_exa.sh index 9cfc0576..97c2f1e3 100755 --- a/.assets/provision/install_exa.sh +++ b/.assets/provision/install_exa.sh @@ -26,18 +26,14 @@ debian | ubuntu) ;; esac +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables REL=$1 retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/ogham/exa/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 - fi - [[ -n "$REL" || $i -eq 10 ]] || echo 'retrying...' >&2 -done +# get latest release if not provided as a parameter +[ -z "$REL" ] && REL="$(get_gh_release_latest --owner 'ogham' --repo 'exa')" # return latest release echo $REL @@ -72,10 +68,8 @@ opensuse) ;; esac -if [ "$binary" = true ]; then +if [ "$binary" = true ] && [ -n "$REL" ]; then echo 'Installing from binary.' >&2 - # dotsource file with common functions - . .assets/provision/source.sh # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri diff --git a/.assets/provision/install_eza.sh b/.assets/provision/install_eza.sh index 033fdbe5..a5705655 100755 --- a/.assets/provision/install_eza.sh +++ b/.assets/provision/install_eza.sh @@ -13,17 +13,13 @@ SYS_ID="$(sed -En '/^ID.*(alpine|arch|fedora|debian|ubuntu|opensuse).*/{s//\1/;p APP='eza' case $SYS_ID in alpine) - true - # TODO replace after eza will be added to Alpine repos - # apk -e info $APP &>/dev/null && exit 0 || true + apk -e info $APP &>/dev/null && exit 0 || true ;; arch) pacman -Qqe $APP &>/dev/null && exit 0 || true ;; fedora) - true - # TODO replace after eza will be added to Fedora repos - # rpm -q $APP &>/dev/null && exit 0 || true + rpm -q $APP &>/dev/null && exit 0 || true ;; debian | ubuntu) dpkg -s $APP &>/dev/null && exit 0 || true @@ -33,18 +29,14 @@ opensuse) ;; esac +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables REL=$1 retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/eza-community/eza/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 - fi - [[ -n "$REL" || $i -eq 10 ]] || echo 'retrying...' >&2 -done +# get latest release if not provided as a parameter +[ -z "$REL" ] && REL="$(get_gh_release_latest --owner 'eza-community' --repo 'eza')" # return latest release echo $REL @@ -56,19 +48,16 @@ if type $APP &>/dev/null; then fi fi -printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2 +printf "\e[92minstalling \e[1m$APP\e[0m\n" >&2 case $SYS_ID in alpine) - binary=true - lib='musl' - # apk add --no-cache eza >&2 2>/dev/null + apk add --no-cache $APP >&2 2>/dev/null ;; arch) pacman -Sy --needed --noconfirm $APP >&2 2>/dev/null || binary=true ;; fedora) - binary=true - lib='gnu' + dnf install -y $APP >&2 2>/dev/null || binary=true ;; debian | ubuntu) export DEBIAN_FRONTEND=noninteractive @@ -81,17 +70,15 @@ debian | ubuntu) apt-get update >&2 && apt-get install -y $APP >&2 2>/dev/null || binary=true ;; opensuse) - zypper in -y eza >&2 2>/dev/null || binary=true + zypper in -y $APP >&2 2>/dev/null || binary=true ;; *) binary=true ;; esac -if [ "$binary" = true ]; then - echo 'Installing from binary.' >&2 - # dotsource file with common functions - . .assets/provision/source.sh +if [ "$binary" = true ] && [ -n "$REL" ]; then + printf "Installing $APP \e[1mv$REL\e[22m from binary.\n" >&2 # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri diff --git a/.assets/provision/install_fastfetch.sh b/.assets/provision/install_fastfetch.sh index 41a6e7cb..89de0b75 100755 --- a/.assets/provision/install_fastfetch.sh +++ b/.assets/provision/install_fastfetch.sh @@ -23,18 +23,14 @@ fedora | opensuse) ;; esac +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables REL=$1 retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/fastfetch-cli/fastfetch/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 - fi - [[ -n "$REL" || $i -eq 10 ]] || echo 'retrying...' >&2 -done +# get latest release if not provided as a parameter +[ -z "$REL" ] && REL="$(get_gh_release_latest --owner 'fastfetch-cli' --repo 'fastfetch')" # return latest release echo $REL @@ -69,8 +65,6 @@ fedora) ;; debian | ubuntu) export DEBIAN_FRONTEND=noninteractive - # dotsource file with common functions - . .assets/provision/source.sh # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri @@ -81,6 +75,7 @@ debian | ubuntu) fi # remove temporary dir rm -fr "$TMP_DIR" + ;; opensuse) zypper in -y $APP >&2 2>/dev/null ;; diff --git a/.assets/provision/install_flux.sh b/.assets/provision/install_flux.sh index 867f5566..d009dfa5 100755 --- a/.assets/provision/install_flux.sh +++ b/.assets/provision/install_flux.sh @@ -7,19 +7,15 @@ if [ $EUID -ne 0 ]; then exit 1 fi +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables APP='flux' REL=$1 retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/fluxcd/flux2/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 - fi - [[ -n "$REL" || $i -eq 10 ]] || echo 'retrying...' >&2 -done +# get latest release if not provided as a parameter +[ -z "$REL" ] && REL="$(get_gh_release_latest --owner 'fluxcd' --repo 'flux2')" # return latest release echo $REL diff --git a/.assets/provision/install_fonts_cascadiacode.sh b/.assets/provision/install_fonts_cascadiacode.sh index 661a1a24..d3561de4 100755 --- a/.assets/provision/install_fonts_cascadiacode.sh +++ b/.assets/provision/install_fonts_cascadiacode.sh @@ -8,25 +8,23 @@ if [ $EUID -ne 0 ]; then exit 1 fi -# variables +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables REL=$1 retry_count=0 # get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/microsoft/cascadia-code/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 +if [ -z "$REL" ]; then + if REL="$(get_gh_release_latest --owner 'microsoft' --repo 'cascadia-code')"; then + # return latest release + echo $REL + else + exit 1 fi - [[ "$REL" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo 'retrying...' >&2 -done -# return latest release -echo $REL +fi echo "Install CascadiaCode v$REL" >&2 -# dotsource file with common functions -. .assets/provision/source.sh # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri diff --git a/.assets/provision/install_gh.sh b/.assets/provision/install_gh.sh index 5bdeaa26..de6bea46 100755 --- a/.assets/provision/install_gh.sh +++ b/.assets/provision/install_gh.sh @@ -26,18 +26,16 @@ debian | ubuntu) ;; esac +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables REL=$1 retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/cli/cli/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 - fi - [[ "$REL" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo 'retrying...' >&2 -done +# get latest release if not provided as a parameter +[ -z "$REL" ] && REL="$(get_gh_release_latest --owner 'cli' --repo 'cli')" +# return latest release +echo $REL if type $APP &>/dev/null; then VER=$(gh --version | sed -En 's/.*\s([0-9\.]+)\s.*/\1/p') @@ -63,7 +61,7 @@ debian | ubuntu) export DEBIAN_FRONTEND=noninteractive curl -fsSLk https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg - echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list >/dev/null + echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" >/etc/apt/sources.list.d/github-cli.list apt-get update && apt-get install -y gh >&2 2>/dev/null ;; opensuse) diff --git a/.assets/provision/install_helm.sh b/.assets/provision/install_helm.sh index 7efae976..ae6eb9a7 100755 --- a/.assets/provision/install_helm.sh +++ b/.assets/provision/install_helm.sh @@ -7,19 +7,15 @@ if [ $EUID -ne 0 ]; then exit 1 fi +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables APP='helm' REL=$1 retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/helm/helm/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 - fi - [[ "$REL" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo 'retrying...' >&2 -done +# get latest release if not provided as a parameter +[ -z "$REL" ] && REL="$(get_gh_release_latest --owner 'helm' --repo 'helm')" # return latest release echo $REL diff --git a/.assets/provision/install_k3d.sh b/.assets/provision/install_k3d.sh index 96be2e49..96c8e675 100755 --- a/.assets/provision/install_k3d.sh +++ b/.assets/provision/install_k3d.sh @@ -7,19 +7,15 @@ if [ $EUID -ne 0 ]; then exit 1 fi +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables APP='k3d' REL=$1 retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/k3d-io/k3d/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 - fi - [[ "$REL" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo 'retrying...' >&2 -done +# get latest release if not provided as a parameter +[ -z "$REL" ] && REL="$(get_gh_release_latest --owner 'k3d-io' --repo 'k3d')" # return latest release echo $REL diff --git a/.assets/provision/install_k9s.sh b/.assets/provision/install_k9s.sh index e0ad73ef..125c7540 100755 --- a/.assets/provision/install_k9s.sh +++ b/.assets/provision/install_k9s.sh @@ -7,21 +7,22 @@ if [ $EUID -ne 0 ]; then exit 1 fi +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables APP='k9s' REL=$1 retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/derailed/k9s/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 +# get latest release if not provided as a parameter +if [ -z "$REL" ]; then + if REL="$(get_gh_release_latest --owner 'derailed' --repo 'k9s')"; then + # return latest release + echo $REL + else + exit 1 fi - [[ "$REL" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo 'retrying...' >&2 -done -# return latest release -echo $REL +fi if type $APP &>/dev/null; then VER=$(k9s version -s | sed -En 's/.*v([0-9\.]+)$/\1/p') @@ -32,8 +33,6 @@ if type $APP &>/dev/null; then fi printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2 -# dotsource file with common functions -. .assets/provision/source.sh # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri diff --git a/.assets/provision/install_kubelogin.sh b/.assets/provision/install_kubelogin.sh index a850886b..1a6a29a9 100755 --- a/.assets/provision/install_kubelogin.sh +++ b/.assets/provision/install_kubelogin.sh @@ -7,21 +7,22 @@ if [ $EUID -ne 0 ]; then exit 1 fi +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables APP='kubelogin' REL=$1 retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/Azure/kubelogin/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 +# get latest release if not provided as a parameter +if [ -z "$REL" ]; then + if REL="$(get_gh_release_latest --owner 'Azure' --repo 'kubelogin')"; then + # return latest release + echo $REL + else + exit 1 fi - [[ "$REL" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo 'retrying...' >&2 -done -# return latest release -echo $REL +fi if type $APP &>/dev/null; then VER=$(kubelogin --version | sed -En 's/.*v([0-9\.]+).*/\1/p') @@ -32,8 +33,6 @@ if type $APP &>/dev/null; then fi printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2 -# dotsource file with common functions -. .assets/provision/source.sh # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri diff --git a/.assets/provision/install_kubeseal.sh b/.assets/provision/install_kubeseal.sh index feb31610..0d992501 100755 --- a/.assets/provision/install_kubeseal.sh +++ b/.assets/provision/install_kubeseal.sh @@ -7,21 +7,22 @@ if [ $EUID -ne 0 ]; then exit 1 fi +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables APP='kubeseal' REL=$1 retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -s https://api.github.com/repos/bitnami-labs/sealed-secrets/tags | jq -r '.[0].name' | cut -c 2-) - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 +# get latest release if not provided as a parameter +if [ -z "$REL" ]; then + if REL="$(get_gh_release_latest --owner 'bitnami-labs' --repo 'sealed-secrets')"; then + # return latest release + echo $REL + else + exit 1 fi - [[ "$REL" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo 'retrying...' >&2 -done -# return latest release -echo $REL +fi if type $APP &>/dev/null; then VER=$(kubeseal --version | sed -En 's/.*\s([0-9\.]+)/\1/p') @@ -32,8 +33,6 @@ if type $APP &>/dev/null; then fi printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2 -# dotsource file with common functions -. .assets/provision/source.sh # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri diff --git a/.assets/provision/install_kustomize.sh b/.assets/provision/install_kustomize.sh index 86a45768..255f443c 100755 --- a/.assets/provision/install_kustomize.sh +++ b/.assets/provision/install_kustomize.sh @@ -7,32 +7,26 @@ if [ $EUID -ne 0 ]; then exit 1 fi +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables APP='kustomize' REL=$1 retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/kubernetes-sigs/kustomize/releases/latest | sed -En 's/.*"tag_name": "kustomize\/([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 - fi - [[ -n "$REL" || $i -eq 10 ]] || echo 'retrying...' >&2 -done +# get latest release if not provided as a parameter +[ -z "$REL" ] && REL="$(get_gh_release_latest --owner 'kubernetes-sigs' --repo 'kustomize')" # return latest release echo $REL if type $APP &>/dev/null; then - VER="$(kustomize version)" + VER="$(kustomize version | sed -En 's/.*v([0-9\.]+)$/\1/p')" if [ "$REL" = "$VER" ]; then printf "\e[32m$APP $VER is already latest\e[0m\n" >&2 exit 0 fi fi -# dotsource file with common functions -. .assets/provision/source.sh # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri @@ -43,4 +37,4 @@ if download_file --uri $URL --target_dir $TMP_DIR; then install -m 0755 kustomize /usr/bin/ fi # remove temporary dir -rm -fr kustomizell "$TMP_DIR" +rm -fr kustomize "$TMP_DIR" diff --git a/.assets/provision/install_minikube.sh b/.assets/provision/install_minikube.sh index d4acb665..929ca690 100755 --- a/.assets/provision/install_minikube.sh +++ b/.assets/provision/install_minikube.sh @@ -20,18 +20,14 @@ arch) ;; esac +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables REL=$1 retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/kubernetes/minikube/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 - fi - [[ "$REL" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo 'retrying...' >&2 -done +# get latest release if not provided as a parameter +[ -z "$REL" ] && REL="$(get_gh_release_latest --owner 'kubernetes' --repo 'minikube')" # return latest release echo $REL @@ -53,8 +49,6 @@ fedora) ;; debian | ubuntu) export DEBIAN_FRONTEND=noninteractive - # dotsource file with common functions - . .assets/provision/source.sh # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri @@ -76,8 +70,6 @@ esac if [ "$binary" = true ]; then echo 'Installing from binary.' >&2 - # dotsource file with common functions - . .assets/provision/source.sh # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri diff --git a/.assets/provision/install_omp.sh b/.assets/provision/install_omp.sh index e7de4de4..bee092eb 100755 --- a/.assets/provision/install_omp.sh +++ b/.assets/provision/install_omp.sh @@ -7,21 +7,22 @@ if [ $EUID -ne 0 ]; then exit 1 fi +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables APP='oh-my-posh' REL=$1 retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/JanDeDobbeleer/oh-my-posh/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 +# get latest release if not provided as a parameter +if [ -z "$REL" ]; then + if REL="$(get_gh_release_latest --owner 'JanDeDobbeleer' --repo 'oh-my-posh')"; then + # return latest release + echo $REL + else + exit 1 fi - [[ "$REL" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo 'retrying...' >&2 -done -# return latest release -echo $REL +fi if type $APP &>/dev/null; then VER=$(oh-my-posh version) @@ -32,8 +33,6 @@ if type $APP &>/dev/null; then fi printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2 -# dotsource file with common functions -. .assets/provision/source.sh # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri diff --git a/.assets/provision/install_pwsh.sh b/.assets/provision/install_pwsh.sh index 7af49582..e4ea61ce 100755 --- a/.assets/provision/install_pwsh.sh +++ b/.assets/provision/install_pwsh.sh @@ -7,19 +7,15 @@ if [ $EUID -ne 0 ]; then exit 1 fi +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables APP='pwsh' REL=$1 retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/PowerShell/PowerShell/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 - fi - [[ "$REL" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo 'retrying...' >&2 -done +# get latest release if not provided as a parameter +[ -z "$REL" ] && REL="$(get_gh_release_latest --owner 'PowerShell' --repo 'PowerShell')" # return latest release echo $REL @@ -39,8 +35,6 @@ case $SYS_ID in alpine) apk add --no-cache ncurses-terminfo-base krb5-libs libgcc libintl libssl1.1 libstdc++ tzdata userspace-rcu zlib icu-libs >&2 2>/dev/null apk -X https://dl-cdn.alpinelinux.org/alpine/edge/main add --no-cache lttng-ust >&2 2>/dev/null - # dotsource file with common functions - . .assets/provision/source.sh # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri @@ -82,8 +76,6 @@ debian | ubuntu) else export DEBIAN_FRONTEND=noninteractive [ "$SYS_ID" = 'debian' ] && apt-get update >&2 && apt-get install -y libicu67 >&2 2>/dev/null || true - # dotsource file with common functions - . .assets/provision/source.sh # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri @@ -101,11 +93,9 @@ debian | ubuntu) ;; esac -if [ "$binary" = true ]; then +if [ "$binary" = true ] && [ -n "$REL" ]; then echo 'Installing from binary.' >&2 [ "$SYS_ID" = 'opensuse' ] && zypper in -y libicu >&2 2>/dev/null || true - # dotsource file with common functions - . .assets/provision/source.sh # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri diff --git a/.assets/provision/install_ripgrep.sh b/.assets/provision/install_ripgrep.sh index a5b549b5..e0d0ea02 100755 --- a/.assets/provision/install_ripgrep.sh +++ b/.assets/provision/install_ripgrep.sh @@ -26,18 +26,14 @@ debian | ubuntu) ;; esac +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables REL=$1 retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/BurntSushi/ripgrep/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 - fi - [[ "$REL" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo 'retrying...' >&2 -done +# get latest release if not provided as a parameter +[ -z "$REL" ] && REL="$(get_gh_release_latest --owner 'BurntSushi' --repo 'ripgrep')" # return latest release echo $REL @@ -72,10 +68,8 @@ opensuse) ;; esac -if [ "$binary" = true ]; then +if [ "$binary" = true ] && [ -n "$REL" ]; then echo 'Installing from binary.' >&2 - # dotsource file with common functions - . .assets/provision/source.sh # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri diff --git a/.assets/provision/install_terraform.sh b/.assets/provision/install_terraform.sh index 775bc86d..a3874a98 100755 --- a/.assets/provision/install_terraform.sh +++ b/.assets/provision/install_terraform.sh @@ -26,18 +26,14 @@ debian | ubuntu) ;; esac +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables REL=$1 retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/hashicorp/terraform/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 - fi - [[ -n "$REL" || $i -eq 10 ]] || echo 'retrying...' >&2 -done +# get latest release if not provided as a parameter +[ -z "$REL" ] && REL="$(get_gh_release_latest --owner 'hashicorp' --repo 'terraform')" # return latest release echo $REL @@ -62,7 +58,7 @@ debian | ubuntu) export DEBIAN_FRONTEND=noninteractive wget -O- https://apt.releases.hashicorp.com/gpg 2>/dev/null | gpg --dearmor > /usr/share/keyrings/hashicorp-archive-keyring.gpg gpg --no-default-keyring --keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg --fingerprint - echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" > /etc/apt/sources.list.d/hashicorp.list + echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" >/etc/apt/sources.list.d/hashicorp.list apt-get update && apt-get install terraform ;; opensuse) diff --git a/.assets/provision/install_terrascan.sh b/.assets/provision/install_terrascan.sh index 3671d9b8..d40d9501 100755 --- a/.assets/provision/install_terrascan.sh +++ b/.assets/provision/install_terrascan.sh @@ -7,18 +7,21 @@ if [ $EUID -ne 0 ]; then exit 1 fi +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables APP='terrascan' retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/tenable/terrascan/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 +# get latest release if not provided as a parameter +if [ -z "$REL" ]; then + if REL="$(get_gh_release_latest --owner 'tenable' --repo 'terrascan')"; then + # return latest release + echo $REL + else + exit 1 fi - [[ -n "$REL" || $i -eq 10 ]] || echo 'retrying...' >&2 -done +fi if type $APP &>/dev/null; then VER=$($APP version | sed -En 's/.*\sv([0-9\.]+)/\1/p') @@ -29,8 +32,6 @@ if type $APP &>/dev/null; then fi printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2 -# dotsource file with common functions -. .assets/provision/source.sh # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri diff --git a/.assets/provision/install_tfswitch.sh b/.assets/provision/install_tfswitch.sh index f31e764d..55e74c36 100755 --- a/.assets/provision/install_tfswitch.sh +++ b/.assets/provision/install_tfswitch.sh @@ -7,18 +7,16 @@ if [ $EUID -ne 0 ]; then exit 1 fi +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables APP='tfswitch' retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/warrensbox/terraform-switcher/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 - fi - [[ -n "$REL" || $i -eq 10 ]] || echo 'retrying...' >&2 -done +# get latest release if not provided as a parameter +[ -z "$REL" ] && REL="$(get_gh_release_latest --owner 'warrensbox' --repo 'terraform-switcher')" +# return latest release +echo $REL if type $APP &>/dev/null; then VER=$($APP --version | sed -En 's/.*\s([0-9\.]+)/\1/p') diff --git a/.assets/provision/install_xrdp.sh b/.assets/provision/install_xrdp.sh index ae128f43..f266be75 100755 --- a/.assets/provision/install_xrdp.sh +++ b/.assets/provision/install_xrdp.sh @@ -30,7 +30,7 @@ arch) fedora) # Load the Hyper-V kernel module if ! [ -f "/etc/modules-load.d/hv_sock.conf" ] || [ "$(cat /etc/modules-load.d/hv_sock.conf | grep hv_sock)" = "" ]; then - echo "hv_sock" | tee -a /etc/modules-load.d/hv_sock.conf &>/dev/null + echo "hv_sock" >>/etc/modules-load.d/hv_sock.conf fi dnf -y install xrdp tigervnc-server # enable firewall rules diff --git a/.assets/provision/install_yq.sh b/.assets/provision/install_yq.sh index 50a19fd5..de20fbf9 100755 --- a/.assets/provision/install_yq.sh +++ b/.assets/provision/install_yq.sh @@ -7,21 +7,22 @@ if [ $EUID -ne 0 ]; then exit 1 fi +# dotsource file with common functions +. .assets/provision/source.sh + +# define variables APP='yq' REL=$1 retry_count=0 -# try 10 times to get latest release if not provided as a parameter -while [ -z "$REL" ]; do - REL=$(curl -sk https://api.github.com/repos/mikefarah/yq/releases/latest | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33m$APP version couldn't be retrieved\e[0m\n" >&2 - exit 0 +# get latest release if not provided as a parameter +if [ -z "$REL" ]; then + if REL="$(get_gh_release_latest --owner 'mikefarah' --repo 'yq')"; then + # return latest release + echo $REL + else + exit 1 fi - [[ "$REL" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo 'retrying...' >&2 -done -# return latest release -echo $REL +fi if type $APP &>/dev/null; then VER=$(yq --version | sed -En 's/.*v([0-9\.]+)$/\1/p') @@ -32,8 +33,6 @@ if type $APP &>/dev/null; then fi printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2 -# dotsource file with common functions -. .assets/provision/source.sh # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri diff --git a/.assets/provision/source.sh b/.assets/provision/source.sh index 6b933413..7d4d347f 100644 --- a/.assets/provision/source.sh +++ b/.assets/provision/source.sh @@ -2,7 +2,7 @@ : ' . .assets/provision/source.sh ' -# function to download file from specified uri +# *function to download file from specified uri download_file() { # parse named parameters local uri=${uri} @@ -16,7 +16,10 @@ download_file() { done if [ -z "$uri" ]; then - printf "\e[31mError: The \e[4muri\e[24m parameter is required.\e[0m\n" + printf "\e[31mError: The \e[4muri\e[24m parameter is required.\e[0m\n" >&2 + return 1 + elif ! type curl &>/dev/null; then + printf "\e[31mError: The \e[4mcurl\e[24m command is required.\e[0m\n" >&2 return 1 fi @@ -49,6 +52,7 @@ download_file() { return 1 } +# *function to get the latest release from the specified GitHub repo get_gh_release_latest() { # parse named parameters local owner=${owner} @@ -61,24 +65,60 @@ get_gh_release_latest() { shift done + # define local variables + local max_retries=1 + local retry_count=0 + local api_response + local rate_limit_message="API rate limit exceeded" + if [[ -z "$owner" || -z "$repo" ]]; then - printf "\e[31mError: The \e[4mowner\e[24m and \e[4mrepo\e[24m parameters are required.\e[0m\n" + printf "\e[31mError: The \e[4mowner\e[24m and \e[4mrepo\e[24m parameters are required.\e[0m\n" >&2 + return 1 + elif ! type curl &>/dev/null; then + printf "\e[31mError: The \e[4mcurl\e[24m command is required.\e[0m\n" >&2 + return 1 + elif ! type jq &>/dev/null; then + printf "\e[31mError: The \e[4mjq\e[24m command is required.\e[0m\n" >&2 return 1 fi - # define local variables - local gh_api="https://api.github.com/repos/${owner}/${repo}/releases/latest" - - while [ -z "$rel" ]; do - rel=$(curl -sk "$gh_api" | sed -En 's/.*"tag_name": "v?([^"]*)".*/\1/p') - ((retry_count++)) - if [ $retry_count -eq 10 ]; then - printf "\e[33mLatest \e[4m${owner}/${repo}\e[24m version couldn't be retrieved.\e[0m\n" >&2 - return 1 + # send API request to GitHub + while [ $retry_count -lt $max_retries ]; do + api_response=$(curl -sk https://api.github.com/repos/$owner/$repo/releases/latest) + # check for API rate limit exceeded + if echo "$api_response" | jq -e '.message' | grep -q "API rate limit exceeded"; then + type gh &>/dev/null && token="$(gh auth token 2>/dev/null)" + if [ -n "$token" ]; then + header="Authorization: Bearer ${token}" + api_response=$(curl -H "$header" -sk https://api.github.com/repos/$owner/$repo/releases/latest) + # check for bad credentials + if echo "$api_response" | jq -e '.message' | grep -q "Bad credentials"; then + printf "\e[31mError: Bad credentials, run the \e[4mgh auth login\e[24m command.\e[0m\n" >&2 + return 1 + fi + else + printf "\e[31mError: API rate limit exceeded. Please try again later.\e[0m\n" >&2 + return 1 + fi + fi + # get the tag_name from the API response + tag_name=$(echo "$api_response" | jq -r '.tag_name') + if [ -n "$tag_name" ]; then + rel="$(echo $tag_name | sed -E 's/.*[^0-9]?([0-9]+\.[0-9]+\.[0-9]+).*/\1/')" + if [ -n "$rel" ]; then + echo "$rel" + return 0 + else + printf "\e[31mError: Returned tag_name doesn't conform to the semantic versioning.\e[0m\n" >&2 + return 1 + fi + else + # increment the retry count + ((retry_count++)) + echo "retrying... $(($retry_count + 1))/$max_retries" >&2 fi - [[ "$rel" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo 'retrying...' >&2 done - echo $rel - return 0 + printf "\e[31mFailed to get latest release after $max_retries attempts.\e[0m\n" >&2 + return 1 } From 0a42de593d448bb60a31b3fbd3d7ac5ccd9d00fa Mon Sep 17 00:00:00 2001 From: Szymon Osiecki Date: Mon, 24 Jun 2024 08:15:25 +0200 Subject: [PATCH 06/13] fix(sh): install_tfswitch version check --- .assets/provision/install_tfswitch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.assets/provision/install_tfswitch.sh b/.assets/provision/install_tfswitch.sh index 55e74c36..d4b7310f 100755 --- a/.assets/provision/install_tfswitch.sh +++ b/.assets/provision/install_tfswitch.sh @@ -19,7 +19,7 @@ retry_count=0 echo $REL if type $APP &>/dev/null; then - VER=$($APP --version | sed -En 's/.*\s([0-9\.]+)/\1/p') + VER=$($APP --version | sed -En 's/.*\sv?([0-9\.]+)/\1/p') if [ "$REL" = "$VER" ]; then printf "\e[32m$APP v$VER is already latest\e[0m\n" >&2 exit 0 From 8db124d93a5dbf8ad1eae1e8a354ca614dc3c8ef Mon Sep 17 00:00:00 2001 From: Szymon Osiecki Date: Mon, 24 Jun 2024 08:57:16 +0200 Subject: [PATCH 07/13] fix(sh): install_kubectl --- .assets/provision/install_kubectl.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.assets/provision/install_kubectl.sh b/.assets/provision/install_kubectl.sh index 3c3d17ec..ac61477e 100755 --- a/.assets/provision/install_kubectl.sh +++ b/.assets/provision/install_kubectl.sh @@ -57,7 +57,7 @@ if [ "$binary" = true ]; then # create temporary dir for the downloaded binary TMP_DIR=$(mktemp -dp "$PWD") # calculate download uri - URL="https://dl.k8s.io/release/$(curl -sLk https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" + URL="https://dl.k8s.io/release/${REL}/bin/linux/amd64/kubectl" # download and install file if download_file --uri $URL --target_dir $TMP_DIR; then install -m 0755 "$TMP_DIR/$(basename $URL)" /usr/bin/ From 12899830090a486e42b0fca2ac70487bb9615220 Mon Sep 17 00:00:00 2001 From: Szymon Osiecki Date: Mon, 24 Jun 2024 12:38:07 +0200 Subject: [PATCH 08/13] fix(ps): wsl_setup - installing Az modules --- wsl/wsl_setup.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wsl/wsl_setup.ps1 b/wsl/wsl_setup.ps1 index 2cec400e..96e159e0 100644 --- a/wsl/wsl_setup.ps1 +++ b/wsl/wsl_setup.ps1 @@ -406,10 +406,10 @@ process { $cmd = [string]::Join("`n", 'if (-not (Get-Module -ListAvailable "Az")) {', "`tWrite-Host 'installing Az...'", - "`tInvoke-CommandRetry { Install-PSResource Az -WarningAction SilentlyContinue }`n}", + "`tInvoke-CommandRetry { Install-PSResource Az -WarningAction SilentlyContinue -ErrorAction Stop }`n}", 'if (-not (Get-Module -ListAvailable "Az.ResourceGraph")) {', "`tWrite-Host 'installing Az.ResourceGraph...'", - "`tInvoke-CommandRetry { Install-PSResource Az.ResourceGraph }`n}" + "`tInvoke-CommandRetry { Install-PSResource Az.ResourceGraph -ErrorAction Stop }`n}" ) wsl.exe --distribution $Distro -- pwsh -nop -c $cmd } @@ -555,4 +555,5 @@ process { end { Pop-Location + Write-Host "`n<< WSL setup completed >>`n" -ForegroundColor Green } From 6a6003c3c3d25be192b221b6cfc72bbfcc6ed576 Mon Sep 17 00:00:00 2001 From: Szymon Osiecki Date: Mon, 24 Jun 2024 13:24:57 +0200 Subject: [PATCH 09/13] refactor(sh): setup_gh_repos Write info about already cloned repos. Check if gh-cli is installed. --- .assets/provision/setup_gh_repos.sh | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/.assets/provision/setup_gh_repos.sh b/.assets/provision/setup_gh_repos.sh index 3391e04d..bc5cb21e 100755 --- a/.assets/provision/setup_gh_repos.sh +++ b/.assets/provision/setup_gh_repos.sh @@ -33,12 +33,14 @@ if ! grep -qw 'github.com' ~/.ssh/known_hosts 2>/dev/null; then fi # *check gh authentication status and login to GitHub if necessary -retry_count=0 -while [[ true && $retry_count -lt 5 ]]; do - gh auth status 2>&1 | grep -qw 'Token:' && github='https://github.com/' && break || true - gh auth login - ((retry_count++)) -done +if type gh &>/dev/null; then + retry_count=0 + while [[ $retry_count -lt 5 ]]; do + gh auth status 2>&1 | grep -qw 'Token:' && github='https://github.com/' && break || true + gh auth login + ((retry_count++)) + done +fi # *setup source folder # create folders @@ -51,15 +53,18 @@ fi # *clone repositories and add them to workspace file cd ~/source/repos -printf "\e[32mcloning repos\e[0m\n" for repo in ${gh_repos[@]}; do - IFS='/' read -ra gh_path <<< "$repo" + IFS='/' read -ra gh_path <<<"$repo" mkdir -p "${gh_path[0]}" pushd "${gh_path[0]}" >/dev/null - git clone "${github}${repo}.git" 2>/dev/null && echo $repo || true + git clone "${github}${repo}.git" 2>/dev/null && echo $repo && cloned=true || true if ! grep -qw "$repo" "$ws_path" && [ -d "${gh_path[1]}" ]; then folder="\t{\n\t\t\t\"name\": \"${gh_path[1]}\",\n\t\t\t\"path\": \"..\/repos\/${repo/\//\\\/}\"\n\t\t},\n\t" sed -i "s/\(\]\)/$folder\1/" "$ws_path" fi popd >/dev/null done + +if [ -z "$cloned" ]; then + printf "\e[32mall repos already cloned\e[0m\n" +fi From de7abb3108ab740aa1fd4fa69952d694f382fa78 Mon Sep 17 00:00:00 2001 From: Szymon Osiecki Date: Mon, 24 Jun 2024 14:43:34 +0200 Subject: [PATCH 10/13] refactor: SetupUtils v0.3.2 git fetch with retry. --- modules/InstallUtils/Functions/git.ps1 | 13 ++++++++++++- modules/InstallUtils/InstallUtils.psd1 | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/InstallUtils/Functions/git.ps1 b/modules/InstallUtils/Functions/git.ps1 index 094b76f8..ddc992d9 100644 --- a/modules/InstallUtils/Functions/git.ps1 +++ b/modules/InstallUtils/Functions/git.ps1 @@ -84,7 +84,18 @@ function Update-GitRepository { if ($remote) { # fetch updates from remote Write-Verbose "fetching $remote..." - git fetch --tags --prune --prune-tags --force $remote + for ($i = 1; $i -le 10; $i++) { + Write-Verbose "attempt No. $i..." + git fetch --tags --prune --prune-tags --force $remote 2>$null + if ($?) { + $fetched = $true + break + } + } + if (-not $fetched) { + Write-Warning 'Fetching from remote failed.' + return 0 + } # check if current branch is behind remote $branch = git branch --show-current if ((git rev-parse HEAD) -ne (git rev-parse "$remote/$branch")) { diff --git a/modules/InstallUtils/InstallUtils.psd1 b/modules/InstallUtils/InstallUtils.psd1 index b76f5218..1a5ff9db 100644 --- a/modules/InstallUtils/InstallUtils.psd1 +++ b/modules/InstallUtils/InstallUtils.psd1 @@ -12,7 +12,7 @@ RootModule = 'InstallUtils.psm1' # Version number of this module. - ModuleVersion = '0.3.1' + ModuleVersion = '0.3.2' # Supported PSEditions CompatiblePSEditions = @('Core', 'Desk') From 1d699e469c451c88b7e64d789c2fc4521f726c1d Mon Sep 17 00:00:00 2001 From: Szymon Osiecki Date: Mon, 24 Jun 2024 20:58:06 +0200 Subject: [PATCH 11/13] refactor: pass releases between distro iterations --- .assets/provision/install_terraform.sh | 6 +++--- .assets/provision/install_terrascan.sh | 3 ++- .assets/provision/install_tfswitch.sh | 3 ++- wsl/wsl_setup.ps1 | 8 ++++---- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.assets/provision/install_terraform.sh b/.assets/provision/install_terraform.sh index a3874a98..f2f30d5a 100755 --- a/.assets/provision/install_terraform.sh +++ b/.assets/provision/install_terraform.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash : ' -sudo .assets/provision/install_terraform.sh +sudo .assets/provision/install_terraform.sh >/dev/null ' if [ $EUID -ne 0 ]; then printf '\e[31;1mRun the script as root.\e[0m\n' >&2 @@ -56,8 +56,8 @@ fedora) ;; debian | ubuntu) export DEBIAN_FRONTEND=noninteractive - wget -O- https://apt.releases.hashicorp.com/gpg 2>/dev/null | gpg --dearmor > /usr/share/keyrings/hashicorp-archive-keyring.gpg - gpg --no-default-keyring --keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg --fingerprint + wget -O- https://apt.releases.hashicorp.com/gpg 2>/dev/null | gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg + gpg --no-default-keyring --keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg --fingerprint 2>/dev/null && rm -fr $HOME/.gnupg echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" >/etc/apt/sources.list.d/hashicorp.list apt-get update && apt-get install terraform ;; diff --git a/.assets/provision/install_terrascan.sh b/.assets/provision/install_terrascan.sh index d40d9501..834151fa 100755 --- a/.assets/provision/install_terrascan.sh +++ b/.assets/provision/install_terrascan.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash : ' -sudo .assets/provision/install_terrascan.sh +sudo .assets/provision/install_terrascan.sh >/dev/null ' if [ $EUID -ne 0 ]; then printf '\e[31;1mRun the script as root.\e[0m\n' >&2 @@ -12,6 +12,7 @@ fi # define variables APP='terrascan' +REL=$1 retry_count=0 # get latest release if not provided as a parameter if [ -z "$REL" ]; then diff --git a/.assets/provision/install_tfswitch.sh b/.assets/provision/install_tfswitch.sh index d4b7310f..e693a715 100755 --- a/.assets/provision/install_tfswitch.sh +++ b/.assets/provision/install_tfswitch.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash : ' -sudo .assets/provision/install_tfswitch.sh +sudo .assets/provision/install_tfswitch.sh >/dev/null ' if [ $EUID -ne 0 ]; then printf '\e[31;1mRun the script as root.\e[0m\n' >&2 @@ -12,6 +12,7 @@ fi # define variables APP='tfswitch' +REL=$1 retry_count=0 # get latest release if not provided as a parameter [ -z "$REL" ] && REL="$(get_gh_release_latest --owner 'warrensbox' --repo 'terraform-switcher')" diff --git a/wsl/wsl_setup.ps1 b/wsl/wsl_setup.ps1 index 96e159e0..8e7fbe6f 100644 --- a/wsl/wsl_setup.ps1 +++ b/wsl/wsl_setup.ps1 @@ -438,9 +438,9 @@ process { } terraform { Write-Host 'installing terraform utils...' -ForegroundColor Cyan - wsl.exe --distribution $Distro --user root --exec .assets/provision/install_terraform.sh - wsl.exe --distribution $Distro --user root --exec .assets/provision/install_terrascan.sh - wsl.exe --distribution $Distro --user root --exec .assets/provision/install_tfswitch.sh + $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 { @@ -546,7 +546,7 @@ process { if ($PsCmdlet.ParameterSetName -eq 'GitHub') { # *install GitHub CLI - wsl.exe --distribution $Distro --user root --exec .assets/provision/install_gh.sh + wsl.exe --distribution $Distro --user root --exec .assets/provision/install_gh.sh | Out-Null # *clone GitHub repositories Write-Host 'cloning GitHub repositories...' -ForegroundColor Cyan wsl.exe --distribution $Distro --exec .assets/provision/setup_gh_repos.sh --repos "$Repos" From 4450e8ec8b06b44fb73c2b419da19e4e9ac91a70 Mon Sep 17 00:00:00 2001 From: Szymon Osiecki Date: Tue, 25 Jun 2024 00:36:34 +0200 Subject: [PATCH 12/13] refactor(sh): bash common functions --- .assets/provision/source.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.assets/provision/source.sh b/.assets/provision/source.sh index 7d4d347f..bdec1593 100644 --- a/.assets/provision/source.sh +++ b/.assets/provision/source.sh @@ -25,12 +25,12 @@ download_file() { # define local variables local file_name="$(basename $uri)" - local max_retries=10 + local max_retries=8 local retry_count=0 - while [[ $retry_count -lt $max_retries ]]; do + while [[ $retry_count -le $max_retries ]]; do # download file - status_code=$(curl -w %{http_code} -#Lko "$target_dir/$file_name" "$uri") + status_code=$(curl -w %{http_code} -#Lko "$target_dir/$file_name" "$uri" 2>/dev/null) # check the HTTP status code case $status_code in @@ -44,6 +44,7 @@ download_file() { ;; *) ((retry_count++)) + echo "retrying... $retry_count/$max_retries" >&2 ;; esac done @@ -66,7 +67,7 @@ get_gh_release_latest() { done # define local variables - local max_retries=1 + local max_retries=8 local retry_count=0 local api_response local rate_limit_message="API rate limit exceeded" @@ -83,7 +84,7 @@ get_gh_release_latest() { fi # send API request to GitHub - while [ $retry_count -lt $max_retries ]; do + while [ $retry_count -le $max_retries ]; do api_response=$(curl -sk https://api.github.com/repos/$owner/$repo/releases/latest) # check for API rate limit exceeded if echo "$api_response" | jq -e '.message' | grep -q "API rate limit exceeded"; then @@ -104,7 +105,7 @@ get_gh_release_latest() { # get the tag_name from the API response tag_name=$(echo "$api_response" | jq -r '.tag_name') if [ -n "$tag_name" ]; then - rel="$(echo $tag_name | sed -E 's/.*[^0-9]?([0-9]+\.[0-9]+\.[0-9]+).*/\1/')" + rel="$(echo $tag_name | sed -E 's/[^0-9]*([0-9]+\.[0-9]+\.[0-9]+)/\1/')" if [ -n "$rel" ]; then echo "$rel" return 0 @@ -115,7 +116,7 @@ get_gh_release_latest() { else # increment the retry count ((retry_count++)) - echo "retrying... $(($retry_count + 1))/$max_retries" >&2 + echo "retrying... $retry_count/$max_retries" >&2 fi done From 9f0acbbffe9390e5507a01bbc378a21b66ad55e0 Mon Sep 17 00:00:00 2001 From: Szymon Osiecki Date: Thu, 27 Jun 2024 07:22:21 +0200 Subject: [PATCH 13/13] refactor: messages coloring --- .assets/provision/update_psresources.ps1 | 2 +- wsl/wsl_setup.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.assets/provision/update_psresources.ps1 b/.assets/provision/update_psresources.ps1 index e3a45ec0..68b9611d 100755 --- a/.assets/provision/update_psresources.ps1 +++ b/.assets/provision/update_psresources.ps1 @@ -32,7 +32,7 @@ foreach ($mod in $dupedModules) { Write-Host "`n`e[4m$($mod)`e[24m - $($allVersions.Count) versions of the module found, latest: `e[1mv$latestVersion`e[22m" -ForegroundColor DarkYellow Write-Host 'uninstalling...' foreach ($v in $allVersions.Where({ $_.Version -ne $latestVersion })) { - Write-Host "- `e[95mv$($v.Version)`e[0m" + Write-Host "- `e[0;90mv$($v.Version)`e[0m" Uninstall-PSResource @param -Name $v.Name -Version ($v.Prerelease ? "$($v.Version)-$($v.Prerelease)" : "$($v.Version)") -SkipDependencyCheck } } diff --git a/wsl/wsl_setup.ps1 b/wsl/wsl_setup.ps1 index 8e7fbe6f..dc501f74 100644 --- a/wsl/wsl_setup.ps1 +++ b/wsl/wsl_setup.ps1 @@ -555,5 +555,5 @@ process { end { Pop-Location - Write-Host "`n<< WSL setup completed >>`n" -ForegroundColor Green + Write-Host "`n`e[1;95m<< WSL setup completed >>`e[0m`n" }