#!/usr/bin/env bash set -euo pipefail TOOLS_FILE="$(dirname "$0")/tools.yaml" LOGFILE="$(dirname "$0")/install.log" log() { echo "[INFO] $(date '+%F %T') $*" | tee -a "$LOGFILE"; } log_warn() { echo "[WARN] $(date '+%F %T') $*" | tee -a "$LOGFILE"; } log_err() { echo "[ERROR] $(date '+%F %T') $*" | tee -a "$LOGFILE"; } require_yq() { if ! command -v yq &>/dev/null; then log_err "This script requires 'yq'. Install it via 'sudo apt install yq'." exit 1 fi } install_category() { local category="$1" log "Processing category: $category" # Loop over all items under the category local tools tools=$(yq e ".${category}[]" "$TOOLS_FILE" | sed 's/^- //') local install_list=() while IFS= read -r item; do local tool tool=$(yq e ".${category}[] | select(.name == \"$item\") | .name // \"$item\"" "$TOOLS_FILE") local ppa ppa=$(yq e ".${category}[] | select(.name == \"$item\") | .ppa // \"\"" "$TOOLS_FILE") if command -v "$tool" &>/dev/null; then log "$tool already installed, skipping." else if [[ -n "$ppa" ]]; then log "Adding PPA: $ppa for $tool" sudo add-apt-repository -y "$ppa" fi install_list+=("$tool") fi done <<< "$tools" if [[ ${#install_list[@]} -gt 0 ]]; then log "Installing: ${install_list[*]}" sudo apt update sudo apt install -y "${install_list[@]}" else log "All tools in $category already installed." fi } main() { require_yq log "Starting tool installation from $TOOLS_FILE" # Define which categories to process local categories=("necessities" "modern" "privacy") for category in "${categories[@]}"; do install_category "$category" done log "✅ All done." } main "$@"