From 6a99575c9f20842691371cb2a5b56bea150e08de Mon Sep 17 00:00:00 2001 From: 1jamesthompson1 <1jamesthompson1@gmail.com> Date: Mon, 23 Mar 2026 10:05:38 +1300 Subject: [PATCH] Add tool config system to setup.sh - Add .dotfiles-tools config file with tool definitions - setup.sh now parses config and installs by priority - Add --with-optional/-w flag to auto-install optional tools - Includes: bash, kitty, vim, git, curl (required), rust, opencode, dua (optional) --- .dotfiles-tools | 15 ++++++++++ setup.sh | 78 +++++++++++++++++++++++++++++++++++-------------- 2 files changed, 71 insertions(+), 22 deletions(-) create mode 100644 .dotfiles-tools diff --git a/.dotfiles-tools b/.dotfiles-tools new file mode 100644 index 0000000..bfb4e83 --- /dev/null +++ b/.dotfiles-tools @@ -0,0 +1,15 @@ +# Tool configurations for dotfiles setup +# Format: name|command_to_check_installed|install_command|priority +# priority: required (install always), optional (ask user), extra (skip by default) + +# Required - core tools +bash|/usr/bin/bash|sudo apt install -y bash|required +kitty|/usr/bin/kitty|sudo apt install -y kitty|required +vim|/usr/bin/vim|sudo apt install -y vim-gtk3|required +git|/usr/bin/git|sudo apt install -y git|required +curl|/usr/bin/curl|sudo apt install -y curl|required + +# Optional - additional tools +rust|/usr/bin/cargo|curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y|optional +opencode|/usr/bin/opencode|curl -fsSL https://opencode.ai/install | sh|optional + dua|/usr/bin/dua|curl -LSfs https://raw.githubusercontent.com/Byron/dua-cli/master/ci/install.sh | sh -s -- --git Byron/dua-cli --target x86_64-unknown-linux-musl --crate dua --tag v2.29.0|optional \ No newline at end of file diff --git a/setup.sh b/setup.sh index b88b782..e257afb 100644 --- a/setup.sh +++ b/setup.sh @@ -1,7 +1,10 @@ set -euo pipefail +TOOLS_FILE="$HOME/.dotfiles-tools" + # CLI: parse flags PROMPT_DELETE=1 +INSTALL_OPTIONAL=0 while [[ $# -gt 0 ]]; do case "$1" in --no-prompt|-n) @@ -12,38 +15,70 @@ while [[ $# -gt 0 ]]; do PROMPT_DELETE=1 shift ;; + --with-optional|-w) + INSTALL_OPTIONAL=1 + shift + ;; *) break esac done echo ">>> Bootstrapping new Debian-like machine..." -# 1. Update package list and install essentials -echo ">>> Installing bash, kitty, and vim..." +# Parse tools from config file +parse_tools() { + local priority="$1" + while IFS='|' read -r name check_cmd install_cmd prio; do + [[ "$name" =~ ^#.*$ ]] && continue + [[ -z "$name" ]] && continue + [[ "$prio" == "$priority" ]] && echo "$name|$check_cmd|$install_cmd" + done < "$TOOLS_FILE" +} + +# Install required tools +echo ">>> Installing required tools..." sudo apt update -sudo apt install -y bash kitty vim-gtk3 git curl +while IFS='|' read -r name check_cmd install_cmd prio; do + [[ "$prio" != "required" ]] && continue + if ! command -v "$name" &> /dev/null && [[ "$prio" == "required" ]]; then + echo ">>> Installing $name..." + eval "$install_cmd" + fi +done < "$TOOLS_FILE" -# Install Rust -echo ">>> Installing Rust..." -if ! command -v rustc &> /dev/null; then - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y +# Ask about optional tools +if [[ "$INSTALL_OPTIONAL" == "1" ]] || [[ "$PROMPT_DELETE" == "1" ]]; then + echo "" + echo ">>> Optional tools available:" + while IFS='|' read -r name check_cmd install_cmd prio; do + [[ "$prio" != "optional" ]] && continue + if ! command -v "$name" &> /dev/null; then + echo " - $name" + fi + done < "$TOOLS_FILE" + echo "" + + if [[ "$PROMPT_DELETE" == "1" ]] && [[ -t 1 ]]; then + read -r -p "Install optional tools? (y/N): " resp + case "$resp" in + [Yy]* ) INSTALL_OPTIONAL=1 ;; + * ) INSTALL_OPTIONAL=0 ;; + esac + fi fi -# Install opencode -echo ">>> Installing OpenCode..." -if ! command -v opencode &> /dev/null; then - curl -fsSL https://opencode.ai/install | sh +if [[ "$INSTALL_OPTIONAL" == "1" ]]; then + echo ">>> Installing optional tools..." + while IFS='|' read -r name check_cmd install_cmd prio; do + [[ "$prio" != "optional" ]] && continue + if ! command -v "$name" &> /dev/null; then + echo ">>> Installing $name..." + eval "$install_cmd" + fi + done < "$TOOLS_FILE" fi -# Install dua-cli (disk usage) -echo ">>> Installing dua-cli..." -if ! command -v dua &> /dev/null; then - curl -fsSL https://github.com/Byron/dua-cli/releases/download/v*/dua-*-x86_64-unknown-linux-gnu.tar.gz | tar -xz -C /tmp - sudo mv /tmp/dua-*/dua /usr/local/bin/ - rm -rf /tmp/dua-* -fi - -# 2. Clone your dotfiles (bare repo style) +# Clone dotfiles if [ ! -d "$HOME/.dotfiles" ]; then echo ">>> Cloning dotfiles repo..." git clone --bare https://gitea.sjhl.nz/james/dotfiles $HOME/.dotfiles @@ -51,7 +86,6 @@ else echo ">>> Dotfiles repo already exists." fi -# 3. Checkout dotfiles dotfiles() { /usr/bin/git --git-dir="$HOME/.dotfiles/" --work-tree="$HOME" "$@" } @@ -87,4 +121,4 @@ fi dotfiles config --local status.showUntrackedFiles no -echo ">>> Done! Bash, kitty, vim, and dotfiles are ready." +echo ">>> Done! Bash, kitty, vim, and dotfiles are ready." \ No newline at end of file