commit 46b6bea1005de40a10cd124119e659cb77a26c55 Author: Repo Maintainer Date: Mon May 18 10:17:44 2026 +1200 Initial commit: Debian setup script diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..54db9be --- /dev/null +++ b/.gitignore @@ -0,0 +1,28 @@ +# OS and editor files +.DS_Store +Thumbs.db +*~ +*.swp +*.swo + +# IDE settings +.vscode/ +.idea/ + +# Logs and temp files +*.log +*.tmp +*.temp + +# Environment and local config +.env +.env.* +*.local + +# Runtime caches +.cache/ + +# Script download artifacts (if interrupted) +kubectl +velero-*-linux-amd64/ +velero-*-linux-amd64.tar.gz diff --git a/README_SETUP_DEBIAN.md b/README_SETUP_DEBIAN.md new file mode 100644 index 0000000..ef624fe --- /dev/null +++ b/README_SETUP_DEBIAN.md @@ -0,0 +1,39 @@ +Debian setup script + +This repository contains a simple idempotent-ish script to provision a Debian-based machine after a rebuild. + +Files +- setup-debian.sh: main script to run (creates/updates ~/.bashrc entries) + +Usage +1. Make the script executable and run it as your user (it will use sudo when needed): + +```bash +chmod +x ~/setup-debian.sh +~/setup-debian.sh +``` + +Optional: set your global Git identity during setup: + +```bash +GIT_USER_NAME="Your Name" GIT_USER_EMAIL="you@example.com" ~/setup-debian.sh +``` + +or run with sudo: + +```bash +sudo bash ~/setup-debian.sh +``` + +What the script does +- Updates apt and installs requested packages (curl, net-tools, ncdu, tmux, htop, nala, neofetch, nfs-common, git, neovim, etc.) +- Installs `snapd` and installs Bitwarden via snap +- Attempts to detect a unix socket (ssh/bitwarden) and export `SSH_AUTH_SOCK` to `~/.bashrc` +- Installs VS Code via snap +- Installs latest `kubectl` binary and enables bash completion + aliases (`k`) +- Adds a `fgk` alias for `flux get kustomizations all` +- Adds arrow-key history search (type prefix then Up/Down) + +Notes +- The script attempts to detect a Bitwarden SSH agent socket but may not find it automatically depending on how Bitwarden exposes it; if needed, manually set `SSH_AUTH_SOCK` in your shell to the socket path. +- `flux` must be installed separately if you need `fgk` to work. diff --git a/setup-debian.sh b/setup-debian.sh new file mode 100755 index 0000000..0d711cb --- /dev/null +++ b/setup-debian.sh @@ -0,0 +1,106 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Debian setup script - idempotent-ish +# Run as your user; the script will use sudo where needed. + +SUDO='' +if [ "$EUID" -ne 0 ]; then + SUDO='sudo' +fi + +echo "Starting Debian setup..." + +${SUDO} apt update +${SUDO} apt upgrade -y + +PKGS=(curl net-tools ncdu tmux htop nala neofetch nfs-common git neovim bash-completion ca-certificates gnupg lsb-release software-properties-common) +echo "Installing packages: ${PKGS[*]}" +${SUDO} apt install -y "${PKGS[@]}" + +# Configure global git identity when explicitly provided by caller. +# Example: +# GIT_USER_NAME="Your Name" GIT_USER_EMAIL="you@example.com" ./setup-debian.sh +if [ -n "${GIT_USER_NAME:-}" ] && [ -n "${GIT_USER_EMAIL:-}" ]; then + git config --global user.name "${GIT_USER_NAME}" + git config --global user.email "${GIT_USER_EMAIL}" +fi + +# snapd + Bitwarden +if ! command -v snap >/dev/null 2>&1; then + echo "Installing snapd..." + ${SUDO} apt install -y snapd + ${SUDO} systemctl enable --now snapd.socket || true +fi + +echo "Installing Bitwarden (snap)..." +${SUDO} snap install bitwarden || true + +# Set SSH_AUTH_SOCK to Bitwarden snap socket path +# This uses the predictable snap path for the current user. +ssh_sock="/home/$(whoami)/snap/bitwarden/current/.bitwarden-ssh-agent.sock" +if ! grep -q "export SSH_AUTH_SOCK=${ssh_sock}" "$HOME/.bashrc" 2>/dev/null; then + echo "Adding Bitwarden SSH_AUTH_SOCK to ~/.bashrc" + printf "\n# Bitwarden SSH agent socket\nexport SSH_AUTH_SOCK=%s\n" "$ssh_sock" >> "$HOME/.bashrc" +fi + +# Install VS Code via snap (classic) +if ! command -v code >/dev/null 2>&1; then + echo "Installing VS Code (snap)..." + ${SUDO} snap install --classic code || true +fi + +# kubectl installation (latest stable binary) +if ! command -v kubectl >/dev/null 2>&1; then + echo "Installing kubectl..." + curl -fsSLO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" + ${SUDO} install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl + rm -f kubectl +fi + +# flux CLI installation (latest release) +if ! command -v flux >/dev/null 2>&1; then + echo "Installing flux CLI..." + curl -s https://fluxcd.io/install.sh | ${SUDO} bash +fi + +# velero CLI installation (latest release) +if ! command -v velero >/dev/null 2>&1; then + echo "Installing velero CLI..." + velero_version="$(curl -fsSL https://api.github.com/repos/vmware-tanzu/velero/releases/latest | grep -m1 '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')" + curl -fsSLO "https://github.com/vmware-tanzu/velero/releases/download/${velero_version}/velero-${velero_version}-linux-amd64.tar.gz" + tar -xzf "velero-${velero_version}-linux-amd64.tar.gz" + ${SUDO} install -o root -g root -m 0755 "velero-${velero_version}-linux-amd64/velero" /usr/local/bin/velero + rm -rf "velero-${velero_version}-linux-amd64" "velero-${velero_version}-linux-amd64.tar.gz" +fi + +# Enable kubectl bash completion and add aliases to ~/.bashrc if missing +ensure_bashrc_snippet() { + file="$HOME/.bashrc" + grep -q 'kubectl completion bash' "$file" || cat >> "$file" <<'BASH_SNIPPET' + +# kubectl completion + aliases +if command -v kubectl >/dev/null 2>&1; then + source <(kubectl completion bash) + alias k=kubectl + complete -F __start_kubectl k +fi + +# alias for flux get kustomizations +alias fgk='flux get kustomizations all' +BASH_SNIPPET + + grep -q 'history-search-backward' "$file" || cat >> "$file" <<'HIST_SNIPPET' + +# History search with arrow keys: type start then Up/Down to search +bind '"\e[A": history-search-backward' +bind '"\e[B": history-search-forward' +HIST_SNIPPET +} + +ensure_bashrc_snippet + +echo "Setup complete. Open a new shell or run 'source ~/.bashrc' to load changes." +echo "If Bitwarden provides an SSH agent, ensure SSH_AUTH_SOCK points to its socket." + +exit 0