Files
agents/install.sh
shahondin1624 a06e21e315 Restructure repo for Claude Code user-level deployment
Move agent files into agents/<name>/AGENT.md convention, add install.sh
symlink script with --uninstall support, and add placeholder directories
for skills and output-styles.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 18:30:35 +01:00

114 lines
3.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CLAUDE_HOME="${CLAUDE_HOME:-$HOME/.claude}"
UNINSTALL=false
if [[ "${1:-}" == "--uninstall" ]]; then
UNINSTALL=true
fi
# link_directory SOURCE_BASE TARGET_BASE KIND
# Symlinks each subdirectory (or file for output-styles) from source into target.
link_directory() {
local source_base="$1"
local target_base="$2"
local kind="$3"
if [[ ! -d "$source_base" ]]; then
return
fi
mkdir -p "$target_base"
for entry in "$source_base"/*/; do
# Skip if glob didn't match
[[ -d "$entry" ]] || continue
local name
name="$(basename "$entry")"
local target="$target_base/$name"
local source
source="$(cd "$entry" && pwd)"
if $UNINSTALL; then
if [[ -L "$target" ]]; then
local link_target
link_target="$(readlink -f "$target")"
if [[ "$link_target" == "$REPO_DIR"* ]]; then
rm "$target"
echo "Removed $kind symlink: $name"
else
echo "Skipped $name — symlink points outside this repo"
fi
fi
continue
fi
if [[ -L "$target" ]]; then
rm "$target"
ln -s "$source" "$target"
echo "Updated $kind symlink: $name"
elif [[ -e "$target" ]]; then
echo "Warning: $target already exists and is not a symlink — skipping"
else
ln -s "$source" "$target"
echo "Linked $kind: $name"
fi
done
# Handle plain files (for output-styles/*.md)
for entry in "$source_base"/*; do
[[ -f "$entry" ]] || continue
local name
name="$(basename "$entry")"
[[ "$name" == ".gitkeep" ]] && continue
local target="$target_base/$name"
local source
source="$(cd "$(dirname "$entry")" && pwd)/$name"
if $UNINSTALL; then
if [[ -L "$target" ]]; then
local link_target
link_target="$(readlink -f "$target")"
if [[ "$link_target" == "$REPO_DIR"* ]]; then
rm "$target"
echo "Removed $kind file symlink: $name"
else
echo "Skipped $name — symlink points outside this repo"
fi
fi
continue
fi
if [[ -L "$target" ]]; then
rm "$target"
ln -s "$source" "$target"
echo "Updated $kind file symlink: $name"
elif [[ -e "$target" ]]; then
echo "Warning: $target already exists and is not a symlink — skipping"
else
ln -s "$source" "$target"
echo "Linked $kind file: $name"
fi
done
}
if $UNINSTALL; then
echo "Uninstalling agents, skills, and output-styles from $CLAUDE_HOME ..."
else
echo "Installing agents, skills, and output-styles into $CLAUDE_HOME ..."
fi
link_directory "$REPO_DIR/agents" "$CLAUDE_HOME/agents" "agent"
link_directory "$REPO_DIR/skills" "$CLAUDE_HOME/skills" "skill"
link_directory "$REPO_DIR/output-styles" "$CLAUDE_HOME/output-styles" "output-style"
if $UNINSTALL; then
echo "Done. Symlinks pointing to this repo have been removed."
else
echo "Done. Restart Claude Code to pick up changes."
fi