-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·100 lines (86 loc) · 2.79 KB
/
install.sh
File metadata and controls
executable file
·100 lines (86 loc) · 2.79 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
#!/usr/bin/env bash
set -euo pipefail
AGENTS_DIR="$HOME/.cursor"
UPDATE_SCRIPT="$AGENTS_DIR/update-usergenerated.sh"
CRON_MARKER="# usergenerated-agents-update"
REPOS=(
"rules:https://github.com/UserGeneratedLLC/agent-rules.git"
"skills:https://github.com/UserGeneratedLLC/agent-skills.git"
"docs:https://github.com/UserGeneratedLLC/agent-docs.git"
"commands:https://github.com/UserGeneratedLLC/agent-commands.git"
)
install() {
command -v git >/dev/null 2>&1 || { echo "Error: git is required but not installed." >&2; exit 1; }
mkdir -p "$AGENTS_DIR"
local failed=0
for entry in "${REPOS[@]}"; do
name="${entry%%:*}"
url="${entry#*:}"
dest="$AGENTS_DIR/$name/usergenerated"
if [ -d "$dest/.git" ]; then
echo "Updating $name..."
(git -C "$dest" fetch --depth 1 2>/dev/null && git -C "$dest" reset --hard origin/HEAD 2>/dev/null) || echo " Warning: pull failed for $name, skipping"
else
if [ -d "$dest" ]; then
echo "Repairing $name (removing incomplete clone)..."
rm -rf "$dest"
fi
echo "Cloning $name..."
mkdir -p "$(dirname "$dest")"
if ! git clone --quiet --depth 1 "$url" "$dest"; then
echo " Warning: clone failed for $name, skipping" >&2
failed=1
continue
fi
fi
done
cat > "$UPDATE_SCRIPT" << 'EOF'
#!/usr/bin/env bash
set -euo pipefail
for dir in "$HOME/.cursor/rules/usergenerated" \
"$HOME/.cursor/skills/usergenerated" \
"$HOME/.cursor/docs/usergenerated" \
"$HOME/.cursor/commands/usergenerated"; do
[ -d "$dir/.git" ] && git -C "$dir" fetch --depth 1 2>/dev/null && git -C "$dir" reset --hard origin/HEAD 2>/dev/null || true
done
EOF
chmod +x "$UPDATE_SCRIPT"
local cron_line="0 * * * * $UPDATE_SCRIPT $CRON_MARKER"
local existing
existing="$(crontab -l 2>/dev/null | grep -vF "$CRON_MARKER" || true)"
if [ -n "$existing" ]; then
printf '%s\n%s\n' "$existing" "$cron_line" | crontab -
else
echo "$cron_line" | crontab -
fi
echo "Installed hourly cron job."
echo "Installed to $AGENTS_DIR"
}
uninstall() {
for entry in "${REPOS[@]}"; do
name="${entry%%:*}"
dest="$AGENTS_DIR/$name/usergenerated"
if [ -d "$dest" ]; then
echo "Removing $dest..."
rm -rf "$dest"
fi
rmdir "$AGENTS_DIR/$name" 2>/dev/null || true
done
rm -f "$UPDATE_SCRIPT"
if crontab -l 2>/dev/null | grep -qF "$CRON_MARKER"; then
local remaining
remaining="$(crontab -l 2>/dev/null | grep -vF "$CRON_MARKER" || true)"
if [ -n "$remaining" ]; then
echo "$remaining" | crontab -
else
crontab -r 2>/dev/null || true
fi
echo "Removed cron job."
fi
rmdir "$AGENTS_DIR" 2>/dev/null || true
echo "Uninstalled."
}
case "${1:-install}" in
uninstall) uninstall ;;
*) install ;;
esac