#!/bin/bash # Save this file as ~/.config/yadm/bootstrap and make it executable. It will # execute all executable files (excluding templates and editor backups) in the # ~/.config/yadm/bootstrap.d directory when run. _repeat() { local start=1 local end=${1:-80} local str="${2:-=}" local range=$(seq $start $end) for i in $range; do echo -n "${str}"; done } display() { local value="$1" echo -n "/=" _repeat ${#value} "=" echo "=\\" echo -n "| " echo -n ${value} echo " |" echo -n "\\=" _repeat ${#value} "=" echo "=/" } set -eu # Directory to look for bootstrap executables in BOOTSTRAP_D="${BASH_SOURCE[0]}.d" if [[ ! -d "$BOOTSTRAP_D" ]]; then echo "Error: bootstrap directory '$BOOTSTRAP_D' not found" >&2 exit 1 fi declare -a bootstraps while IFS= read -r bootstrap; do if [[ -x "$bootstrap" && ! "$bootstrap" =~ "##" && ! "$bootstrap" =~ ~$ ]]; then bootstraps+=("$bootstrap") fi done < <(find -L "$BOOTSTRAP_D" -type f | sort) for bootstrap in "${bootstraps[@]}"; do display "Executing $bootstrap" if ! "$bootstrap"; then echo "Error: bootstrap '$bootstrap' failed" >&2 exit 1 fi done display "Bootstrap completed"