Skip to content

Commit

Permalink
Merge pull request #152 from szymonos/dev
Browse files Browse the repository at this point in the history
Merge dev to main
  • Loading branch information
szymonos authored Mar 19, 2024
2 parents 07af583 + f8231d5 commit 92242d4
Show file tree
Hide file tree
Showing 9 changed files with 230 additions and 48 deletions.
4 changes: 3 additions & 1 deletion .assets/provision/install_eza.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ fedora)
debian | ubuntu)
export DEBIAN_FRONTEND=noninteractive
mkdir -p /etc/apt/keyrings
wget -qO- https://raw.githubusercontent.com/eza-community/eza/main/deb.asc | gpg --dearmor -o /etc/apt/keyrings/gierens.gpg
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
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
Expand Down
14 changes: 0 additions & 14 deletions .assets/provision/install_kubectl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ case $SYS_ID in
arch)
pacman -Qqe $APP &>/dev/null && exit 0 || true
;;
fedora)
rpm -q $APP &>/dev/null && exit 0 || true
;;
esac

REL=$1
Expand Down Expand Up @@ -48,17 +45,6 @@ case $SYS_ID in
arch)
pacman -Sy --needed --noconfirm kubectl >&2 2>/dev/null || binary=true
;;
fedora)
[ -f /etc/yum.repos.d/kubernetes.repo ] || cat <<EOF | tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
dnf install -y kubectl >&2 2>/dev/null || binary=true
;;
*)
binary=true
;;
Expand Down
78 changes: 78 additions & 0 deletions .assets/provision/install_miniforge.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env bash
: '
.assets/provision/install_miniforge.sh
.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'
exit 1
fi

# parse named parameters
fix_certify=${fix_certify:-false}
while [ $# -gt 0 ]; do
if [[ $1 == *"--"* ]]; then
param="${1/--/}"
declare $param="$2"
fi
shift
done

# set script working directory to workspace folder
SCRIPT_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)
pushd "$(cd "${SCRIPT_ROOT}/../../" && pwd)" >/dev/null

# *conda init function.
function conda_init {
__conda_setup="$("$HOME/miniforge3/bin/conda" 'shell.bash' 'hook' 2>/dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "$HOME/miniforge3/etc/profile.d/conda.sh" ]; then
. "$HOME/miniforge3/etc/profile.d/conda.sh"
else
export PATH="$HOME/miniforge3/bin:$PATH"
fi
fi
unset __conda_setup
}

# *Install conda.
if [ -d "$HOME/miniforge3" ]; then
conda_init
else
printf "\e[92minstalling \e[1mminiforge\e[0m\n"
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
rm -fr "$TMP_DIR"
# disable auto activation of the base conda environment
conda_init
conda config --set auto_activate_base false
fi
# disable conda env prompt if oh-my-posh is installed
if [ -f /usr/bin/oh-my-posh ]; then
conda config --set changeps1 false
fi

# *Add certificates to conda base certifi.
if $fix_certify; then
conda activate base
.assets/provision/fix_certifi_certs.sh
conda deactivate
fi

# *Update conda.
conda update --name base --channel defaults conda --yes --update-all
conda clean --yes --all

# *Fix certificates after update.
if $fix_certify; then
conda activate base
.assets/provision/fix_certifi_certs.sh
conda deactivate
fi
4 changes: 2 additions & 2 deletions .assets/provision/install_terraform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ fedora)
;;
debian | ubuntu)
export DEBIAN_FRONTEND=noninteractive
wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
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" | tee /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)
Expand Down
41 changes: 41 additions & 0 deletions .assets/provision/install_terrascan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
: '
sudo .assets/provision/install_terrascan.sh
'
if [ $EUID -ne 0 ]; then
printf '\e[31;1mRun the script as root.\e[0m\n'
exit 1
fi

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
fi
[[ -n "$REL" || $i -eq 10 ]] || echo 'retrying...' >&2
done

if type $APP &>/dev/null; then
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
fi
fi

printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2
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/
rm -fr "$TMP_DIR"

exit 0
43 changes: 43 additions & 0 deletions .assets/provision/install_tfswitch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env bash
: '
sudo .assets/provision/install_tfswitch.sh
'
if [ $EUID -ne 0 ]; then
printf '\e[31;1mRun the script as root.\e[0m\n'
exit 1
fi

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

if type $APP &>/dev/null; then
VER=$($APP --version | sed -En 's/.*\s([0-9\.]+)/\1/p')
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
__install="curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh | bash"
if type $APP &>/dev/null; then
eval $__install
else
retry_count=0
while ! type $APP &>/dev/null && [ $retry_count -lt 10 ]; do
eval $__install
((retry_count++))
done
fi

exit 0
20 changes: 14 additions & 6 deletions wsl/wsl_install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ Name of the WSL distro to install and set up.
List of installation scopes. Valid values:
- az: azure-cli, do-az from ps-modules if pwsh scope specified; autoselects python scope
- docker: docker, containerd buildx docker-compose (WSL2 only)
- k8s_base: kubectl, kubelogin, helm, k9s, kubeseal, flux, kustomize
- k8s_ext: minikube, k3d, argorollouts-cli (WSL2 only); autoselects docker and k8s_base scopes
- pwsh: PowerShell Core and corresponding PS modules; autoselects shell scope
- python: pip, venv, miniconda
- shell: bat, eza, oh-my-posh, ripgrep, yq
- terraform: terraform, terrascan, tfswitch
- zsh: zsh shell with plugins
.PARAMETER Repos
List of GitHub repositories in format "Owner/RepoName" to clone into the WSL.
.PARAMETER FixNetwork
Expand All @@ -31,20 +37,22 @@ wsl/wsl_install.ps1 -Distro 'Ubuntu'
wsl/wsl_install.ps1 -Distro 'Ubuntu' -FixNetwork
# :set up WSL distro with specified installation scopes
$Scope = @('python')
$Scope = @('az', 'docker')
$Scope = @('az', 'docker', 'shell')
$Scope = @('az', 'docker', 'pwsh')
$Scope = @('az', 'docker', 'k8s_base', 'pwsh')
$Scope = @('az', 'docker', 'k8s_base', 'pwsh', 'terraform')
wsl/wsl_install.ps1 -Distro 'Ubuntu' -s $Scope
# :set up WSL distro and clone specified GitHub repositories
$Repos = @('szymonos/linux-setup-scripts')
$Repos = @('procter-gamble/de-cf-wsl-setup-scripts')
wsl/wsl_install.ps1 -Distro 'Ubuntu' -r $Repos
# with the specified scope
wsl/wsl_install.ps1 -Distro 'Ubuntu' -r $Repos -s $Scope
#>
[CmdletBinding()]
param (
[Parameter(Mandatory, Position = 0)]
[string]$Distro,

[ValidateScript({ $_.ForEach({ $_ -in @('az', 'docker', 'k8s_base', 'k8s_ext', 'oh_my_posh', 'pwsh', 'python', 'shell', 'zsh') }) -notcontains $false })]
[ValidateScript({ $_.ForEach({ $_ -in @('az', 'docker', 'k8s_base', 'k8s_ext', 'oh_my_posh', 'pwsh', 'python', 'shell', 'terraform', 'zsh') }) -notcontains $false })]
[string[]]$Scope,

[ValidateScript({ $_.ForEach({ $_ -match '^[\w-]+/[\w-]+$' }) -notcontains $false })]
Expand All @@ -63,7 +71,7 @@ begin {
# import InstallUtils for the Update-SessionEnvironmentPath function
Import-Module (Resolve-Path './modules/InstallUtils')

Write-Host "checking if the repository is up to date..." -ForegroundColor Cyan
Write-Host 'checking if the repository is up to date...' -ForegroundColor Cyan
if ((Update-GitRepository) -eq 2) {
Write-Host "`nRun the script again!" -ForegroundColor Yellow
exit 0
Expand All @@ -86,7 +94,7 @@ process {
}
}

# *Check if WSL is updated
# *Perform WSL update
wsl.exe --update

# *Check the current default version
Expand Down
13 changes: 10 additions & 3 deletions wsl/wsl_restart.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
.SYNOPSIS
Restart WSL.
.DESCRIPTION
Running the script fixes issues with unresponsive WSL or user permissions issues.
The script stops all running wsl processes and then restarts the following services:
- LxssManagerUser: Linux Subsystem User Manager
- WSLService: WSL Service
- vmcompute: Hyper-V Host Compute Service
.PARAMETER StopDockerDesktop
Flag whether to stop DockerDesktop process.
Expand All @@ -27,8 +34,8 @@ if ($StopDockerDesktop) {
Get-Process docker* | Stop-Process -Force
}

# stop wsl processess
# stop WSL processess
Get-Process wsl* | Stop-Process -Force

# restart LxssManagerUser service
Get-Service LxssManagerUser*, WSLService | Restart-Service -Force
# restart services related to WSL
Get-Service LxssManagerUser*, WSLService, vmcompute | Restart-Service -Force
Loading

0 comments on commit 92242d4

Please sign in to comment.