|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +usage() { |
| 5 | + cat <<'EOF' |
| 6 | +Usage: install-skill.sh --codex|--claude|--cursor|--dest <path> [--skill <mcp|cli>] [--ref <git-ref>] [--remove-conflict] |
| 7 | +
|
| 8 | +Installs (or replaces) the XcodeBuildMCP skill. If --skill is omitted, the |
| 9 | +installer will ask which skill to install. |
| 10 | +If the script is run from a local checkout, it installs the local skill file. |
| 11 | +Otherwise it downloads the skill from the provided --ref or from main. |
| 12 | +
|
| 13 | +If no destination is provided, the installer will prompt for a client. |
| 14 | +EOF |
| 15 | +} |
| 16 | + |
| 17 | +destination="" |
| 18 | +skill_choice="" |
| 19 | +skill_ref_override="" |
| 20 | +remove_conflict="false" |
| 21 | +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 22 | +repo_root="$(cd "${script_dir}/.." && pwd)" |
| 23 | + |
| 24 | +while [[ $# -gt 0 ]]; do |
| 25 | + case "$1" in |
| 26 | + --codex) |
| 27 | + destination="${HOME}/.codex/skills/public" |
| 28 | + shift |
| 29 | + ;; |
| 30 | + --claude) |
| 31 | + destination="${HOME}/.claude/skills" |
| 32 | + shift |
| 33 | + ;; |
| 34 | + --cursor) |
| 35 | + destination="${HOME}/.cursor/skills" |
| 36 | + shift |
| 37 | + ;; |
| 38 | + --dest) |
| 39 | + if [[ $# -lt 2 ]]; then |
| 40 | + echo "Missing value for --dest" >&2 |
| 41 | + usage |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | + destination="$2" |
| 45 | + shift 2 |
| 46 | + ;; |
| 47 | + --skill) |
| 48 | + if [[ $# -lt 2 ]]; then |
| 49 | + echo "Missing value for --skill" >&2 |
| 50 | + usage |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | + skill_choice="$2" |
| 54 | + shift 2 |
| 55 | + ;; |
| 56 | + --ref) |
| 57 | + if [[ $# -lt 2 ]]; then |
| 58 | + echo "Missing value for --ref" >&2 |
| 59 | + usage |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | + skill_ref_override="$2" |
| 63 | + shift 2 |
| 64 | + ;; |
| 65 | + --remove-conflict) |
| 66 | + remove_conflict="true" |
| 67 | + shift |
| 68 | + ;; |
| 69 | + -h|--help) |
| 70 | + usage |
| 71 | + exit 0 |
| 72 | + ;; |
| 73 | + *) |
| 74 | + echo "Unknown option: $1" >&2 |
| 75 | + usage |
| 76 | + exit 1 |
| 77 | + ;; |
| 78 | + esac |
| 79 | +done |
| 80 | + |
| 81 | +prompt_for_destination() { |
| 82 | + while true; do |
| 83 | + printf "Which client should receive the skill?\n" |
| 84 | + printf "1) Codex\n" |
| 85 | + printf "2) Claude\n" |
| 86 | + printf "3) Cursor\n" |
| 87 | + read -r -p "Enter 1, 2, or 3: " selection |
| 88 | + case "${selection}" in |
| 89 | + 1) |
| 90 | + destination="${HOME}/.codex/skills/public" |
| 91 | + return 0 |
| 92 | + ;; |
| 93 | + 2) |
| 94 | + destination="${HOME}/.claude/skills" |
| 95 | + return 0 |
| 96 | + ;; |
| 97 | + 3) |
| 98 | + destination="${HOME}/.cursor/skills" |
| 99 | + return 0 |
| 100 | + ;; |
| 101 | + *) |
| 102 | + echo "Invalid selection. Please enter 1, 2, or 3." |
| 103 | + ;; |
| 104 | + esac |
| 105 | + done |
| 106 | +} |
| 107 | + |
| 108 | +prompt_for_skill() { |
| 109 | + while true; do |
| 110 | + printf "Which skill would you like to install?\n" |
| 111 | + printf "1) XcodeBuildMCP (MCP server)\n" |
| 112 | + printf "2) XcodeBuildMCP CLI\n" |
| 113 | + read -r -p "Enter 1 or 2: " selection |
| 114 | + case "${selection}" in |
| 115 | + 1) |
| 116 | + skill_choice="mcp" |
| 117 | + return 0 |
| 118 | + ;; |
| 119 | + 2) |
| 120 | + skill_choice="cli" |
| 121 | + return 0 |
| 122 | + ;; |
| 123 | + *) |
| 124 | + echo "Invalid selection. Please enter 1 or 2." |
| 125 | + ;; |
| 126 | + esac |
| 127 | + done |
| 128 | +} |
| 129 | + |
| 130 | +if [[ -z "${destination}" ]]; then |
| 131 | + prompt_for_destination |
| 132 | +fi |
| 133 | + |
| 134 | +if [[ -z "${skill_choice}" ]]; then |
| 135 | + prompt_for_skill |
| 136 | +fi |
| 137 | + |
| 138 | +case "${skill_choice}" in |
| 139 | + mcp|server|xcodebuildmcp) |
| 140 | + skill_dir_name="xcodebuildmcp" |
| 141 | + skill_label="XcodeBuildMCP (MCP server)" |
| 142 | + alt_dir_name="xcodebuildmcp-cli" |
| 143 | + alt_label="XcodeBuildMCP CLI" |
| 144 | + ;; |
| 145 | + cli|xcodebuildmcp-cli) |
| 146 | + skill_dir_name="xcodebuildmcp-cli" |
| 147 | + skill_label="XcodeBuildMCP CLI" |
| 148 | + alt_dir_name="xcodebuildmcp" |
| 149 | + alt_label="XcodeBuildMCP (MCP server)" |
| 150 | + ;; |
| 151 | + *) |
| 152 | + echo "Unknown skill: ${skill_choice}" >&2 |
| 153 | + usage |
| 154 | + exit 1 |
| 155 | + ;; |
| 156 | +esac |
| 157 | + |
| 158 | +skill_dir="${destination}/${skill_dir_name}" |
| 159 | +alt_dir="${destination}/${alt_dir_name}" |
| 160 | +skill_path="skills/${skill_dir_name}/SKILL.md" |
| 161 | +skill_base_url="https://raw.githubusercontent.com/cameroncooke/XcodeBuildMCP" |
| 162 | +skill_ref="main" |
| 163 | + |
| 164 | +if [[ -n "${skill_ref_override}" ]]; then |
| 165 | + skill_ref="${skill_ref_override}" |
| 166 | +fi |
| 167 | + |
| 168 | +if [[ -e "${alt_dir}" ]]; then |
| 169 | + if [[ "${remove_conflict}" == "true" ]]; then |
| 170 | + rm -r "${alt_dir}" |
| 171 | + else |
| 172 | + printf "%s\n" "Only one skill can be installed at a time because the MCP and CLI skills conflict." |
| 173 | + read -r -p "Found ${alt_label} at ${alt_dir}. Remove it to continue? [y/N]: " confirm |
| 174 | + case "${confirm}" in |
| 175 | + y|Y|yes|YES) |
| 176 | + rm -r "${alt_dir}" |
| 177 | + ;; |
| 178 | + *) |
| 179 | + echo "Aborting to avoid installing both skills." |
| 180 | + exit 1 |
| 181 | + ;; |
| 182 | + esac |
| 183 | + fi |
| 184 | +fi |
| 185 | + |
| 186 | +if [[ -e "${skill_dir}" ]]; then |
| 187 | + rm -r "${skill_dir}" |
| 188 | +fi |
| 189 | +mkdir -p "${skill_dir}" |
| 190 | + |
| 191 | +primary_url="${skill_base_url}/${skill_ref}/${skill_path}" |
| 192 | +fallback_url="${skill_base_url}/main/${skill_path}" |
| 193 | +local_skill_path="${repo_root}/${skill_path}" |
| 194 | + |
| 195 | +if [[ -f "${local_skill_path}" ]]; then |
| 196 | + cp "${local_skill_path}" "${skill_dir}/SKILL.md" |
| 197 | +else |
| 198 | + if ! curl -fsSL "${primary_url}" -o "${skill_dir}/SKILL.md"; then |
| 199 | + if [[ "${skill_ref}" != "main" ]]; then |
| 200 | + printf "%s\n" "Release tag ${skill_ref} not found. Falling back to main." |
| 201 | + curl -fsSL "${fallback_url}" -o "${skill_dir}/SKILL.md" |
| 202 | + else |
| 203 | + printf "%s\n" "Failed to download ${primary_url}." >&2 |
| 204 | + exit 1 |
| 205 | + fi |
| 206 | + fi |
| 207 | +fi |
| 208 | + |
| 209 | +printf 'Installed %s to %s\n' "${skill_label}" "${skill_dir}" |
0 commit comments