-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·141 lines (108 loc) · 2.38 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·141 lines (108 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<'EOF'
Usage: ./install.sh [--dry-run]
Installs this repo's skills into:
${CODEX_HOME:-$HOME/.codex}/skills
EOF
}
DRY_RUN=0
while [[ $# -gt 0 ]]; do
case "$1" in
--dry-run)
DRY_RUN=1
;;
-h|--help)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
shift
done
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SOURCE_DIR="$REPO_ROOT/skills"
CODEX_HOME="${CODEX_HOME:-$HOME/.codex}"
TARGET_DIR="$CODEX_HOME/skills"
MANIFEST_PATH="$TARGET_DIR/.codex-elixir-phoenix-manifest"
echo "Source: $SOURCE_DIR"
echo "Target: $TARGET_DIR"
list_source_skills() {
find "$SOURCE_DIR" -mindepth 1 -maxdepth 1 -type d | sort
}
skill_in_list() {
local needle="$1"
shift
local skill_name
for skill_name in "$@"; do
if [[ "$skill_name" == "$needle" ]]; then
return 0
fi
done
return 1
}
copy_skill() {
local skill_name="$1"
local source_path="$SOURCE_DIR/$skill_name"
local target_path="$TARGET_DIR/$skill_name"
if [[ "$DRY_RUN" -eq 1 ]]; then
echo "[dry-run] sync $skill_name -> $target_path"
return
fi
rm -rf "$target_path"
cp -R "$source_path" "$target_path"
echo "installed $skill_name"
}
prune_removed_skills() {
local skill_name
local target_path
if [[ ! -f "$MANIFEST_PATH" ]]; then
return
fi
while IFS= read -r skill_name; do
[[ -z "$skill_name" ]] && continue
if skill_in_list "$skill_name" "${SOURCE_SKILLS[@]}"; then
continue
fi
target_path="$TARGET_DIR/$skill_name"
if [[ "$DRY_RUN" -eq 1 ]]; then
echo "[dry-run] prune $target_path"
continue
fi
if [[ -d "$target_path" ]]; then
rm -rf "$target_path"
echo "pruned $skill_name"
fi
done < "$MANIFEST_PATH"
}
write_manifest() {
if [[ "$DRY_RUN" -eq 1 ]]; then
return
fi
printf '%s\n' "${SOURCE_SKILLS[@]}" > "$MANIFEST_PATH"
}
SOURCE_SKILLS=()
while IFS= read -r skill_path; do
skill_name="$(basename "$skill_path")"
if [[ "$skill_name" == ".system" ]]; then
continue
fi
SOURCE_SKILLS+=("$skill_name")
done < <(list_source_skills)
if [[ "$DRY_RUN" -ne 1 ]]; then
mkdir -p "$TARGET_DIR"
fi
prune_removed_skills
for skill_name in "${SOURCE_SKILLS[@]}"; do
copy_skill "$skill_name"
done
write_manifest
if [[ "$DRY_RUN" -eq 1 ]]; then
echo "Dry run complete."
else
echo "Install complete."
fi