-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-codex.sh
More file actions
executable file
·97 lines (85 loc) · 3.17 KB
/
Copy pathinstall-codex.sh
File metadata and controls
executable file
·97 lines (85 loc) · 3.17 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
#!/usr/bin/env bash
# Install Zero Workflow into Codex's personal local marketplace.
set -euo pipefail
SRC_DIR="$(cd "$(dirname "$0")" && pwd -P)"
CODEX_HOME="${CODEX_HOME:-$HOME/.codex}"
MARKETPLACE_ROOT="$HOME/.agents/plugins"
MARKETPLACE_PATH="$MARKETPLACE_ROOT/marketplace.json"
PLUGIN_PARENT="$HOME/plugins"
PLUGIN_DEST="$PLUGIN_PARENT/zero-workflow"
STAGE="$PLUGIN_PARENT/.zero-workflow.stage.$$"
BACKUP="$PLUGIN_PARENT/.zero-workflow.backup.$$"
SCAFFOLD_PARENT="$PLUGIN_PARENT/.zero-workflow.scaffold.$$"
CREATOR_ROOT="$CODEX_HOME/skills/.system/plugin-creator"
CREATE_PLUGIN="$CREATOR_ROOT/scripts/create_basic_plugin.py"
VALIDATE_PLUGIN="$CREATOR_ROOT/scripts/validate_plugin.py"
UPDATE_CACHEBUSTER="$CREATOR_ROOT/scripts/update_plugin_cachebuster.py"
READ_MARKETPLACE="$CREATOR_ROOT/scripts/read_marketplace_name.py"
ASSUME_YES=0
INSTALL_COMPLETE=0
case "${1:-}" in
"") ;;
--yes) ASSUME_YES=1 ;;
*) echo "Usage: $0 [--yes]" >&2; exit 2 ;;
esac
cleanup() {
status=$?
trap - EXIT HUP INT TERM
if [ "$INSTALL_COMPLETE" -ne 1 ] && [ -d "$BACKUP" ] && [ ! -e "$PLUGIN_DEST" ]; then
mv "$BACKUP" "$PLUGIN_DEST"
fi
rm -rf "$STAGE" "$SCAFFOLD_PARENT"
[ "$INSTALL_COMPLETE" -eq 1 ] && rm -rf "$BACKUP"
exit "$status"
}
trap cleanup EXIT
trap 'exit 129' HUP
trap 'exit 130' INT
trap 'exit 143' TERM
for helper in "$CREATE_PLUGIN" "$VALIDATE_PLUGIN" "$UPDATE_CACHEBUSTER" "$READ_MARKETPLACE"; do
if [ ! -f "$helper" ]; then
echo "Codex plugin helper not found: $helper" >&2
echo "Update Codex, then rerun this installer." >&2
exit 1
fi
done
python3 "$VALIDATE_PLUGIN" "$SRC_DIR"
mkdir -p "$PLUGIN_PARENT" "$MARKETPLACE_ROOT"
if [ -d "$PLUGIN_DEST" ] && [ "$(cd "$PLUGIN_DEST" && pwd -P)" = "$SRC_DIR" ]; then
echo "Refusing to replace the source checkout in place: $SRC_DIR" >&2
exit 1
fi
if [ -e "$PLUGIN_DEST" ] && [ "$ASSUME_YES" -ne 1 ]; then
printf 'Replace the existing Codex plugin at %s? [y/N] ' "$PLUGIN_DEST"
read -r answer
case "$answer" in y|Y) ;; *) echo "Installation cancelled."; exit 0 ;; esac
fi
python3 "$CREATE_PLUGIN" zero-workflow \
--path "$SCAFFOLD_PARENT" \
--with-skills \
--with-marketplace \
--marketplace-path "$MARKETPLACE_PATH" \
--install-policy AVAILABLE \
--auth-policy ON_INSTALL \
--category Productivity \
--force
mkdir -p "$STAGE"
for part in .codex-plugin skills runtime templates scripts agents compat; do
mkdir -p "$STAGE/$part"
cp -R "$SRC_DIR/$part/." "$STAGE/$part/"
done
for file in VERSION README.md AGENTS.md LICENSE THIRD_PARTY_NOTICES.md install-codex.sh install.sh install.ps1; do
[ -f "$SRC_DIR/$file" ] && cp "$SRC_DIR/$file" "$STAGE/$file"
done
chmod +x "$STAGE/install-codex.sh" "$STAGE/install.sh" "$STAGE/scripts/zw-check-runtime.sh"
python3 "$UPDATE_CACHEBUSTER" "$STAGE"
python3 "$VALIDATE_PLUGIN" "$STAGE"
"$STAGE/scripts/zw-check-runtime.sh"
[ -e "$PLUGIN_DEST" ] && mv "$PLUGIN_DEST" "$BACKUP"
mv "$STAGE" "$PLUGIN_DEST"
INSTALL_COMPLETE=1
marketplace_name="$(python3 "$READ_MARKETPLACE" --marketplace-path "$MARKETPLACE_PATH")"
codex plugin add "zero-workflow@$marketplace_name"
echo
echo "Zero Workflow installed for Codex from: $PLUGIN_DEST"
echo "Start a new Codex thread, then run \$zw or \$zw-check."