-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·233 lines (205 loc) · 7.15 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·233 lines (205 loc) · 7.15 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/bin/sh
# install.sh - Install patina for Claude Code and other AI agents
# Usage: curl -fsSL https://raw.githubusercontent.com/devswha/patina/main/install.sh | bash
set -e
# Agent targets (set env vars to enable; all enabled by default if none specified)
INSTALL_CLAUDE="${INSTALL_CLAUDE:-true}"
INSTALL_CODEX="${INSTALL_CODEX:-true}"
INSTALL_CURSOR="${INSTALL_CURSOR:-true}"
INSTALL_OPCODE="${INSTALL_OPCODE:-true}"
CLAUDE_SKILLS_DIR="${HOME}/.claude/skills"
CODEX_SKILLS_DIR="${HOME}/.codex/skills"
CURSOR_RULES_DIR="${HOME}/.cursor/rules"
OPCODE_SKILLS_DIR="${HOME}/.config/opencode/skills"
PATINA_DIR="${CLAUDE_SKILLS_DIR}/patina"
REPO_URL="https://github.com/devswha/patina.git"
# Pin the installed checkout to a concrete ref. If unset, resolve the current
# remote HEAD once and check out that commit instead of tracking main.
PATINA_REF="${PATINA_REF:-}"
PATINA_REPO_READY=""
# Colors (only when outputting to a terminal)
if [ -t 1 ] && [ -z "${NO_COLOR:-}" ]; then
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
BOLD='\033[1m'
RESET='\033[0m'
else
GREEN=''
YELLOW=''
RED=''
BOLD=''
RESET=''
fi
info() {
printf "%b\n" "${BOLD}$1${RESET}"
}
warn() {
printf "%b\n" "${YELLOW}$1${RESET}"
}
success() {
printf "%b\n" "${GREEN}$1${RESET}"
}
error() {
printf "%b\n" "${RED}Error: $1${RESET}" >&2
exit 1
}
# Check prerequisites
command -v git >/dev/null 2>&1 || error "git is not installed. Please install git first."
resolve_install_ref() {
if [ -n "${PATINA_REF}" ]; then
printf "%s" "${PATINA_REF}"
return 0
fi
git ls-remote "${REPO_URL}" HEAD 2>/dev/null | awk 'NR == 1 { print $1 }'
}
checkout_install_ref() {
dir="$1"
ref="$2"
set +e
(
cd "${dir}"
git fetch --depth=1 origin "${ref}" || exit 10
git checkout --detach FETCH_HEAD >/dev/null 2>&1 || exit 11
)
rc="$?"
set -e
if [ "${rc}" = "10" ]; then
error "Failed to fetch patina ref '${ref}'. Use PATINA_REF=<tag-or-full-sha>."
fi
if [ "${rc}" = "11" ]; then
error "Failed to check out patina ref '${ref}'."
fi
if [ "${rc}" != "0" ]; then
error "Failed to install patina ref '${ref}'."
fi
}
# Install runtime Node dependencies (currently just js-yaml) so the local CLI
# entry points (bin/patina.js) work from the installed checkout. Best-effort:
# the skill install itself does not need Node, so a missing npm or failed install
# only warns rather than aborting. See issue #536.
install_runtime_deps() {
if [ -f "${PATINA_DIR}/node_modules/js-yaml/package.json" ]; then
return 0
fi
if ! command -v npm >/dev/null 2>&1; then
warn " npm not found — skipping runtime deps. The local CLI needs 'js-yaml'; run 'npm install --omit=dev' in ${PATINA_DIR} to enable it."
return 0
fi
info "Installing patina runtime dependencies..."
if ! ( cd "${PATINA_DIR}" && npm install --omit=dev --no-audit --no-fund >/dev/null 2>&1 ); then
warn " Runtime dependency install failed. Run 'npm install --omit=dev' in ${PATINA_DIR} to enable the local CLI."
fi
}
# Ensure the patina repo checkout exists at PATINA_DIR (clone or update once).
# Idempotent and tool-neutral so any single agent can be installed on its own,
# without requiring Claude Code to be installed first.
ensure_patina_repo() {
if [ -n "${PATINA_REPO_READY}" ]; then
return 0
fi
if [ -d "${PATINA_DIR}/.git" ]; then
info "Updating existing patina installation..."
checkout_install_ref "${PATINA_DIR}" "${INSTALL_REF}"
else
if [ -d "${PATINA_DIR}" ]; then
error "${PATINA_DIR} exists but is not a git repo. Remove it and try again."
fi
mkdir -p "$(dirname "${PATINA_DIR}")"
info "Cloning patina at ${INSTALL_REF}..."
git clone --depth=1 "${REPO_URL}" "${PATINA_DIR}" || error "Failed to clone patina. Check your network connection."
checkout_install_ref "${PATINA_DIR}" "${INSTALL_REF}"
fi
install_runtime_deps
PATINA_REPO_READY=1
}
INSTALL_REF="$(resolve_install_ref)"
if [ -z "${INSTALL_REF}" ]; then
error "Failed to resolve patina install ref. Set PATINA_REF=<tag-or-full-sha> and retry."
fi
# --- Claude Code ---
if [ "${INSTALL_CLAUDE}" = "true" ]; then
info "Installing for Claude Code..."
ensure_patina_repo
success "Claude Code: /patina ready"
else
warn "Skipping Claude Code installation (INSTALL_CLAUDE=false)"
fi
# --- Codex CLI ---
if [ "${INSTALL_CODEX}" = "true" ]; then
info "Installing for Codex CLI..."
if [ ! -d "${CODEX_SKILLS_DIR}" ]; then
info "Creating ${CODEX_SKILLS_DIR}..."
mkdir -p "${CODEX_SKILLS_DIR}"
fi
ensure_patina_repo
ln -snf "${PATINA_DIR}" "${CODEX_SKILLS_DIR}/patina"
success "Codex: /patina linked to ${CODEX_SKILLS_DIR}"
else
warn "Skipping Codex installation (INSTALL_CODEX=false)"
fi
# --- Cursor ---
if [ "${INSTALL_CURSOR}" = "true" ]; then
info "Installing for Cursor..."
if [ ! -d "${CURSOR_RULES_DIR}" ]; then
info "Creating ${CURSOR_RULES_DIR}..."
mkdir -p "${CURSOR_RULES_DIR}"
fi
# Cursor rules are inside the repo; symlink or copy depending on install method
ensure_patina_repo
if [ -f "${PATINA_DIR}/.cursor/rules/patina.md" ]; then
ln -snf "${PATINA_DIR}/.cursor/rules/patina.md" "${CURSOR_RULES_DIR}/patina.md"
success "Cursor: rules linked to ${CURSOR_RULES_DIR}/patina.md"
else
warn "Cursor rules not found in repo. Run 'git pull' or check repo integrity."
fi
else
warn "Skipping Cursor installation (INSTALL_CURSOR=false)"
fi
# --- OpenCode / Sisyphus ---
if [ "${INSTALL_OPCODE}" = "true" ]; then
info "Installing for OpenCode / Sisyphus..."
if [ ! -d "${OPCODE_SKILLS_DIR}" ]; then
info "Creating ${OPCODE_SKILLS_DIR}..."
mkdir -p "${OPCODE_SKILLS_DIR}"
fi
ensure_patina_repo
# OpenCode uses AGENTS.md + standalone-prompt.md as the skill interface
ln -snf "${PATINA_DIR}" "${OPCODE_SKILLS_DIR}/patina"
success "OpenCode: skill linked to ${OPCODE_SKILLS_DIR}/patina"
else
warn "Skipping OpenCode installation (INSTALL_OPCODE=false)"
fi
# Done
printf "\n"
success "✓ patina installed."
info " If it saves you edits, a star helps others find it → https://github.com/devswha/patina"
printf "\n"
info "Usage:"
if [ "${INSTALL_CLAUDE}" = "true" ]; then
printf " Claude Code:\n"
printf " /patina Humanize Korean text\n"
printf " /patina --lang en Humanize English text\n"
fi
if [ "${INSTALL_CODEX}" = "true" ]; then
printf " Codex CLI:\n"
printf " /patina Humanize Korean text\n"
printf " /patina --lang en Humanize English text\n"
fi
if [ "${INSTALL_CURSOR}" = "true" ]; then
printf " Cursor:\n"
printf " Rules loaded from ~/.cursor/rules/patina.md\n"
fi
if [ "${INSTALL_OPCODE}" = "true" ]; then
printf " OpenCode / Sisyphus:\n"
printf " Skill loaded from ~/.config/opencode/skills/patina\n"
printf " Use AGENTS.md + core/standalone-prompt.md\n"
fi
printf "\n"
info "Environment variables to control installation:"
printf " PATINA_REF=<tag-or-full-sha> Pin installed checkout (default: resolved remote HEAD SHA)\n"
printf " INSTALL_CLAUDE=true|false (default: true)\n"
printf " INSTALL_CODEX=true|false (default: true)\n"
printf " INSTALL_CURSOR=true|false (default: true)\n"
printf " INSTALL_OPCODE=true|false (default: true)\n"
printf "\n"