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)
This commit is contained in:
1jamesthompson1
2026-03-23 10:05:38 +13:00
parent a07cc04126
commit 6a99575c9f
2 changed files with 71 additions and 22 deletions

View File

@@ -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."