#!/usr/bin/env bash # Install the addons the configuration asks for (ADDONS), in the order listed. # One idempotent script per addon: the overlay's addons/.sh first, then rig's ctrl/addons/. # Usage: addons.sh install | list # Notes: docs/notes/addons.md set -euo pipefail cd "$(dirname "$0")" source ./lib/config.sh load_config # Every addon runs from here, wherever its file lives, so it can source ./lib/config.sh. export RIG_CTRL="$PWD" # The script for one addon name: the overlay's, else rig's; empty if neither. addon_path() { local ov="" if [ -n "$OVERLAY_DIR" ]; then ov="$(_from_ctrl "$OVERLAY_DIR")/addons/$1.sh"; fi if [ -n "$ov" ] && [ -f "$ov" ]; then echo "$ov" elif [ -f "addons/$1.sh" ]; then echo "addons/$1.sh" fi } install() { if [ -z "${ADDONS// /}" ]; then echo "no addons asked for (ADDONS is empty)" return fi local a p for a in $ADDONS; do p=$(addon_path "$a") if [ -z "$p" ]; then echo "no such addon: $a (looked in the overlay's addons/ and ctrl/addons/)" >&2 exit 1 fi echo "addon: $a" bash "$p" done } list() { echo "wanted: ${ADDONS:-none}" echo "available:" local f if [ -n "$OVERLAY_DIR" ]; then for f in "$(_from_ctrl "$OVERLAY_DIR")"/addons/*.sh; do [ -e "$f" ] || continue printf ' %-16s overlay\n' "$(basename "$f" .sh)" done fi for f in addons/*.sh; do [ -e "$f" ] || continue printf ' %-16s rig\n' "$(basename "$f" .sh)" done } case "${1:-list}" in install) install ;; list) list ;; *) echo "usage: $0 [install|list]" >&2; exit 1 ;; esac