Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .assets/provision/distro_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ declare -A state=(
["git_email"]=$([ -n "$(git config --global --get user.email 2>/dev/null)" ] && echo "true" || echo "false")
["gtkd"]=$(grep -Fqw "dark" /etc/profile.d/gtk_theme.sh 2>/dev/null && echo "true" || echo "false")
["k8s_base"]=$([ -f /usr/bin/kubectl ] && echo "true" || echo "false")
["k8s_dev"]=$([ -f /usr/local/bin/helm ] && echo "true" || echo "false")
["k8s_ext"]=$([ -f /usr/local/bin/k3d ] && echo "true" || echo "false")
["oh_my_posh"]=$([ -f /usr/bin/oh-my-posh ] && echo "true" || echo "false")
["python"]=$([ -f $HOME/.local/bin/uv ] && echo "true" || echo "false")
Expand Down
1 change: 1 addition & 0 deletions .assets/provision/install_flux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ if type $APP &>/dev/null; then
fi
fi

printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2
__install="curl -sk https://fluxcd.io/install.sh | bash"
if type $APP &>/dev/null; then
eval $__install
Expand Down
47 changes: 16 additions & 31 deletions .assets/provision/install_gh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ if [ $EUID -ne 0 ]; then
exit 1
fi

# dotsource file with common functions
. .assets/provision/source.sh

# determine system id
SYS_ID="$(sed -En '/^ID.*(alpine|arch|fedora|debian|ubuntu|opensuse).*/{s//\1/;p;q}' /etc/os-release)"
# check if package installed already using package manager
APP='gh'
case $SYS_ID in
alpine)
apk -e info github-cli &>/dev/null && exit 0 || true
Expand All @@ -19,42 +21,25 @@ arch)
pacman -Qqe github-cli &>/dev/null && exit 0 || true
;;
fedora | opensuse)
rpm -q $APP &>/dev/null && exit 0 || true
rpm -q gh &>/dev/null && exit 0 || true
;;
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 2>/dev/null
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" >/etc/apt/sources.list.d/github-cli.list
dpkg -s $APP &>/dev/null && exit 0 || true
# create temporary dir for the downloaded binary
TMP_DIR=$(mktemp -dp "$HOME")
if download_file --uri "https://cli.github.com/packages/githubcli-archive-keyring.gpg" --target_dir "$TMP_DIR"; then
mkdir -p -m 755 /etc/apt/keyrings
install -m 0644 "$TMP_DIR/githubcli-archive-keyring.gpg" /etc/apt/keyrings
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" >/etc/apt/sources.list.d/github-cli.list
fi
# remove temporary dir
rm -fr "$TMP_DIR"
# check if installed already
dpkg -s gh &>/dev/null && exit 0 || true
;;
esac

# dotsource file with common functions
. .assets/provision/source.sh

# define variables
REL=$1
# get latest release if not provided as a parameter
if [ -z "$REL" ]; then
REL="$(get_gh_release_latest --owner 'cli' --repo 'cli')"
if [ -z "$REL" ]; then
printf "\e[31mFailed to get the latest version of $APP.\e[0m\n" >&2
exit 1
fi
fi
# return the release
echo $REL

if type $APP &>/dev/null; then
VER=$(gh --version | sed -En 's/.*\s([0-9\.]+)\s.*/\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
printf "\e[92minstalling \e[1mgithub-cli\e[0m\n" >&2
case $SYS_ID in
alpine)
apk add --no-cache github-cli >&2 2>/dev/null
Expand Down
49 changes: 49 additions & 0 deletions .assets/provision/install_kind.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
: '
sudo .assets/provision/install_kind.sh >/dev/null
'
if [ $EUID -ne 0 ]; then
printf '\e[31;1mRun the script as root.\e[0m\n' >&2
exit 1
fi

# dotsource file with common functions
. .assets/provision/source.sh

# define variables
APP='kind'
REL=$1
OWNER='kubernetes-sigs'
REPO='kind'
# get latest release if not provided as a parameter
if [ -z "$REL" ]; then
REL="$(get_gh_release_latest --owner $OWNER --repo $REPO)"
if [ -z "$REL" ]; then
printf "\e[31mFailed to get the latest version of $APP.\e[0m\n" >&2
exit 1
fi
fi
# return the release
echo $REL

if type $APP &>/dev/null; then
VER=$(kind version | sed -En 's/.*v([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
# create temporary dir for the downloaded binary
TMP_DIR=$(mktemp -dp "$HOME")
# calculate download uri
URL="https://github.com/$OWNER/$REPO/releases/download/v${REL}/kind-linux-amd64"
# download and install file
if download_file --uri "$URL" --target_dir "$TMP_DIR"; then
mkdir -p /opt/kind
install -m 0755 "$TMP_DIR/kind-linux-amd64" /opt/kind/kind
[ -f /usr/bin/kind ] || ln -s /opt/kind/kind /usr/bin/kind
fi
# remove temporary dir
rm -fr "$TMP_DIR"
1 change: 1 addition & 0 deletions .assets/provision/install_kustomize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ if type $APP &>/dev/null; then
fi
fi

printf "\e[92minstalling \e[1m$APP\e[22m v$REL\e[0m\n" >&2
# create temporary dir for the downloaded binary
TMP_DIR=$(mktemp -dp "$HOME")
# calculate download uri
Expand Down
15 changes: 10 additions & 5 deletions .assets/scripts/linux_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ while IFS= read -r line; do
done <<<"$distro_check"
# add corresponding scopes
grep -qw 'az' <<<${array[@]} && array+=(python) || true
grep -qw 'k8s_ext' <<<${array[@]} && array+=(docker) && array+=(k8s_base) || true
grep -qw 'k8s_ext' <<<${array[@]} && array+=(docker) && array+=(k8s_base) && array+=(k8s_dev) || true
grep -qw 'pwsh' <<<${array[@]} && array+=(shell) || true
grep -qw 'zsh' <<<${array[@]} && array+=(shell) || true
# add oh_my_posh scope if necessary
Expand All @@ -67,6 +67,7 @@ fi
order=(
docker
k8s_base
k8s_dev
k8s_ext
python
conda
Expand Down Expand Up @@ -149,19 +150,23 @@ for sc in ${scope_arr[@]}; do
printf "\e[96minstalling kubernetes base packages...\e[0m\n"
sudo .assets/provision/install_kubectl.sh >/dev/null
sudo .assets/provision/install_kubelogin.sh >/dev/null
sudo .assets/provision/install_cilium.sh >/dev/null
sudo .assets/provision/install_helm.sh >/dev/null
sudo .assets/provision/install_k9s.sh >/dev/null
sudo .assets/provision/install_kubecolor.sh >/dev/null
sudo .assets/provision/install_kubectx.sh >/dev/null
;;
k8s_dev)
printf "\e[96minstalling kubernetes dev packages...\e[0m\n"
sudo .assets/provision/install_argorolloutscli.sh >/dev/null
sudo .assets/provision/install_cilium.sh >/dev/null
sudo .assets/provision/install_flux.sh
sudo .assets/provision/install_helm.sh >/dev/null
sudo .assets/provision/install_kustomize.sh
;;
k8s_ext)
printf "\e[96minstalling kubernetes additional packages...\e[0m\n"
printf "\e[96minstalling local kubernetes tools...\e[0m\n"
sudo .assets/provision/install_minikube.sh >/dev/null
sudo .assets/provision/install_k3d.sh >/dev/null
sudo .assets/provision/install_argorolloutscli.sh >/dev/null
sudo .assets/provision/install_kind.sh >/dev/null
;;
nodejs)
printf "\e[96minstalling Node.js...\e[0m\n"
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
/console/
/tmp.*/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# vagrant
**/.vagrant/

Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
repos:
- repo: local
hooks:
- id: gremlins-check
name: Detect gremlins / unwanted Unicode characters
entry: python3 -m tests.hooks.gremlins
language: system
types: [text]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
Expand Down
89 changes: 89 additions & 0 deletions tests/hooks/gremlins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
"""
Scan staged text files for unwanted Unicode characters and fail if found.

# :example
python3 -m tests.gremlins wsl/wsl_setup.ps1
"""

import os
import sys
import unicodedata
from typing import Iterable, List, Tuple

FORBIDDEN_CHARS: Tuple[str, ...] = (
# Zero-width / joiner
"\u200b", # U+200B ZERO WIDTH SPACE
"\u200c", # U+200C ZERO WIDTH NON-JOINER
"\u200d", # U+200D ZERO WIDTH JOINER
# Spaces / breaks
"\u00a0", # U+00A0 NO-BREAK SPACE
"\u202f", # U+202F NARROW NO-BREAK SPACE
"\u2009", # U+2009 THIN SPACE
"\u200a", # U+200A HAIR SPACE
# Control / formatting
"\u000c", # U+000C FORM FEED
"\u00ad", # U+00AD SOFT HYPHEN
# Dashes / hyphens
"\u2013", # U+2013 EN DASH
"\u2014", # U+2014 EM DASH
"\u2010", # U+2010 HYPHEN
# Quotes / punctuation that look like ASCII
"\u2018", # U+2018 LEFT SINGLE QUOTATION MARK
"\u2019", # U+2019 RIGHT SINGLE QUOTATION MARK
"\u201c", # U+201C LEFT DOUBLE QUOTATION MARK
"\u201d", # U+201D RIGHT DOUBLE QUOTATION MARK
"\u2026", # U+2026 HORIZONTAL ELLIPSIS
)


def find_forbidden_in_text(content: str, filename: str) -> List[str]:
"""Return list of human readable reports for forbidden characters in content."""
reports: List[str] = []
for lineno, line in enumerate(content.splitlines(), start=1):
for ch in FORBIDDEN_CHARS:
if ch in line:
code = f"U+{ord(ch):04X}"
try:
name = unicodedata.name(ch)
except ValueError:
name = "<unknown>"
reports.append(f"{filename}:{lineno}: contains {name} ({code})")
return reports


def is_text_file(path: str) -> bool:
"""Quick heuristic to skip binary files."""
try:
with open(path, "rb") as fh:
chunk = fh.read(4096)
# if NUL bytes present it's likely binary
return b"\x00" not in chunk
except OSError:
return False


def check_gremlins(argv: Iterable[str]) -> int:
"""Entry point: argv should be list of filenames to check."""
files = list(argv)
problems: List[str] = []
for path in files:
if not os.path.exists(path) or not is_text_file(path):
continue
try:
with open(path, "r", encoding="utf-8", errors="replace") as fh:
content = fh.read()
except OSError:
continue
problems.extend(find_forbidden_in_text(content, path))

if problems:
print("Gremlin characters found:", file=sys.stderr)
for p in problems:
print(p, file=sys.stderr)
print("Remove or replace gremlin characters", file=sys.stderr)
return 1
return 0


if __name__ == "__main__":
raise SystemExit(check_gremlins(sys.argv[1:]))
11 changes: 6 additions & 5 deletions wsl/wsl_install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ The script will perform the following:
Name of the WSL distro to install and set up.
.PARAMETER Scope
List of installation scopes. Valid values:
- az: azure-cli, Az PowerShell module if pwsh scope specified; autoselects python scope
- az: azure-cli, azcopy, Az PowerShell module if pwsh scope specified; autoselects python scope
- conda: miniforge
- distrobox: (WSL2 only) - podman and distrobox
- docker: (WSL2 only) - docker, containerd buildx docker-compose
- k8s_base: kubectl, kubelogin, cilium-cli, helm, k9s, flux, kustomize, kubecolor, kubectx, kubens
- k8s_ext: (WSL2 only) - minikube, k3d, argorollouts-cli; autoselects docker and k8s_base scopes
- k8s_base: kubectl, kubelogin, k9s, kubecolor, kubectx, kubens
- k8s_dev: argorollouts, cilium, helm, flux, kustomize cli tools
- k8s_ext: (WSL2 only) - minikube, k3d, kind local kubernetes tools; autoselects docker, k8s_base and k8s_dev scopes
- nodejs: Node.js JavaScript runtime environment
- pwsh: PowerShell Core and corresponding PS modules; autoselects shell scope
- python: uv, pip, venv
- python: uv, prek, pip, venv
- rice: btop, cmatrix, cowsay, fastfetch
- shell: bat, eza, oh-my-posh, ripgrep, yq
- terraform: terraform, terrascan, tfswitch
Expand Down Expand Up @@ -68,7 +69,7 @@ param (
[Parameter(Mandatory, Position = 0)]
[string]$Distro,

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

[ValidateScript({ $_.ForEach({ $_ -match '^[\w-]+/[\w-]+$' }) -notcontains $false })]
Expand Down
Loading