install: default jj setup in one-click flow
This commit is contained in:
@@ -6,6 +6,119 @@ SKILL_NAME="gitea-issue-devops-agent"
|
||||
CODEX_HOME="${CODEX_HOME:-$HOME/.codex}"
|
||||
TARGET_DIR="${CODEX_HOME}/skills/${SKILL_NAME}"
|
||||
TMP_DIR="$(mktemp -d)"
|
||||
INSTALL_JJ="${INSTALL_JJ:-1}"
|
||||
JJ_INSTALL_METHOD="${JJ_INSTALL_METHOD:-auto}"
|
||||
JJ_CHANNEL="${JJ_CHANNEL:-release}"
|
||||
|
||||
log() {
|
||||
echo "[install] $*"
|
||||
}
|
||||
|
||||
warn() {
|
||||
echo "[install] warning: $*" >&2
|
||||
}
|
||||
|
||||
manual_jj_help() {
|
||||
warn "jj was not installed automatically."
|
||||
warn "Manual options:"
|
||||
warn " - Homebrew: brew install jj"
|
||||
warn " - cargo-binstall: cargo binstall --strategies crate-meta-data jj-cli"
|
||||
if [ "$JJ_CHANNEL" = "prerelease" ]; then
|
||||
warn " - cargo prerelease: cargo install --git https://github.com/jj-vcs/jj.git --locked --bin jj jj-cli"
|
||||
else
|
||||
warn " - cargo release: cargo install --locked --bin jj jj-cli"
|
||||
fi
|
||||
warn "After installation, verify with: jj --version"
|
||||
}
|
||||
|
||||
install_jj_with_brew() {
|
||||
if ! command -v brew >/dev/null 2>&1; then
|
||||
return 1
|
||||
fi
|
||||
if [ "$JJ_CHANNEL" != "release" ]; then
|
||||
warn "brew path skipped because prerelease jj is requested."
|
||||
return 1
|
||||
fi
|
||||
|
||||
log "attempting jj installation via Homebrew"
|
||||
brew install jj
|
||||
}
|
||||
|
||||
install_jj_with_binstall() {
|
||||
if ! command -v cargo >/dev/null 2>&1 || ! command -v cargo-binstall >/dev/null 2>&1; then
|
||||
return 1
|
||||
fi
|
||||
if [ "$JJ_CHANNEL" != "release" ]; then
|
||||
warn "cargo-binstall path skipped because prerelease jj is requested."
|
||||
return 1
|
||||
fi
|
||||
|
||||
log "attempting jj installation via cargo-binstall"
|
||||
cargo binstall --strategies crate-meta-data jj-cli
|
||||
}
|
||||
|
||||
install_jj_with_cargo() {
|
||||
if ! command -v cargo >/dev/null 2>&1; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
log "attempting jj installation via cargo"
|
||||
if [ "$JJ_CHANNEL" = "prerelease" ]; then
|
||||
cargo install --git https://github.com/jj-vcs/jj.git --locked --bin jj jj-cli
|
||||
else
|
||||
cargo install --locked --bin jj jj-cli
|
||||
fi
|
||||
}
|
||||
|
||||
attempt_jj_install() {
|
||||
if [ "$INSTALL_JJ" = "0" ]; then
|
||||
log "skipping jj installation because INSTALL_JJ=0"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if command -v jj >/dev/null 2>&1; then
|
||||
log "jj already installed: $(jj --version)"
|
||||
return 0
|
||||
fi
|
||||
|
||||
case "$JJ_INSTALL_METHOD" in
|
||||
auto)
|
||||
install_jj_with_brew || install_jj_with_binstall || install_jj_with_cargo || {
|
||||
manual_jj_help
|
||||
return 0
|
||||
}
|
||||
;;
|
||||
brew)
|
||||
install_jj_with_brew || {
|
||||
manual_jj_help
|
||||
return 0
|
||||
}
|
||||
;;
|
||||
binstall)
|
||||
install_jj_with_binstall || {
|
||||
manual_jj_help
|
||||
return 0
|
||||
}
|
||||
;;
|
||||
cargo)
|
||||
install_jj_with_cargo || {
|
||||
manual_jj_help
|
||||
return 0
|
||||
}
|
||||
;;
|
||||
*)
|
||||
warn "unsupported JJ_INSTALL_METHOD='$JJ_INSTALL_METHOD'; skipping jj install."
|
||||
manual_jj_help
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
if command -v jj >/dev/null 2>&1; then
|
||||
log "jj installation succeeded: $(jj --version)"
|
||||
else
|
||||
manual_jj_help
|
||||
fi
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
rm -rf "$TMP_DIR"
|
||||
@@ -13,15 +126,15 @@ cleanup() {
|
||||
trap cleanup EXIT
|
||||
|
||||
if ! command -v git >/dev/null 2>&1; then
|
||||
echo "[install] git is required but not found."
|
||||
log "git is required but not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[install] downloading ${SKILL_NAME} from ${REPO_URL}"
|
||||
log "downloading ${SKILL_NAME} from ${REPO_URL}"
|
||||
git clone --depth 1 "$REPO_URL" "$TMP_DIR/repo" >/dev/null 2>&1
|
||||
|
||||
if [ ! -d "$TMP_DIR/repo/skills/${SKILL_NAME}" ]; then
|
||||
echo "[install] skill directory not found in repository."
|
||||
log "skill directory not found in repository."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -29,5 +142,7 @@ mkdir -p "${CODEX_HOME}/skills"
|
||||
rm -rf "$TARGET_DIR"
|
||||
cp -R "$TMP_DIR/repo/skills/${SKILL_NAME}" "$TARGET_DIR"
|
||||
|
||||
echo "[install] done"
|
||||
echo "[install] installed path: ${TARGET_DIR}"
|
||||
log "skill installed"
|
||||
log "installed path: ${TARGET_DIR}"
|
||||
attempt_jj_install
|
||||
log "done"
|
||||
|
||||
Reference in New Issue
Block a user