View raw

1 #!/bin/sh 2 # Symlink every skill and steering module of this repo into ~/.kiro. 3 # 4 # The script is idempotent. A link that already points at this repo is 5 # left alone. A link that points elsewhere, or a real directory with the 6 # same name, is reported and skipped, so the script never overwrites work 7 # that this repo does not own. 8 # 9 # Usage: 10 # ./install.sh Install into ~/.kiro. 11 # KIRO_HOME=/x ./install.sh Install into /x instead. 12 # 13 # Exit status: 0 when every asset is linked, 1 when at least one was skipped. 14 15 set -eu 16 17 repo=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) 18 kiro=${KIRO_HOME:-"$HOME/.kiro"} 19 status=0 20 21 link_asset() { 22 # $1: asset type directory (skills or steering) 23 # $2: asset directory inside the repo 24 type=$1 25 src=$2 26 name=$(basename -- "$src") 27 dest_dir="$kiro/$type" 28 dest="$dest_dir/$name" 29 30 mkdir -p -- "$dest_dir" 31 32 if [ -L "$dest" ]; then 33 target=$(readlink -- "$dest") 34 if [ "$target" = "$src" ]; then 35 echo "ok $dest" 36 else 37 echo "skip $dest -> $target (not this repo)" >&2 38 status=1 39 fi 40 elif [ -e "$dest" ]; then 41 echo "skip $dest exists and is not a symlink" >&2 42 status=1 43 else 44 ln -s -- "$src" "$dest" 45 echo "linked $dest" 46 fi 47 } 48 49 for type in skills steering; do 50 for src in "$repo/$type"/*/; do 51 [ -d "$src" ] || continue 52 link_asset "$type" "${src%/}" 53 done 54 done 55 56 exit "$status" 57