-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·135 lines (124 loc) · 4.02 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·135 lines (124 loc) · 4.02 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
#!/usr/bin/env bash
set -euo pipefail
repo_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
codex_home="${CODEX_HOME:-$HOME/.codex}"
timestamp="$(date -u +%Y%m%dT%H%M%SZ)"
backup_dir="$codex_home/backups/sol-orchestration-$timestamp"
staging_dir="$backup_dir/staging"
state_file="$codex_home/sol-orchestration-state.json"
command -v codex >/dev/null || {
printf '%s\n' 'error: codex CLI is not installed or not on PATH' >&2
exit 69
}
command -v python3 >/dev/null || {
printf '%s\n' 'error: python3 is required by the installer' >&2
exit 69
}
python3 - <<'PY'
import sys
if sys.version_info < (3, 11):
raise SystemExit("error: Python 3.11 or newer is required")
PY
managed=(
instruction.sol.md
agent-instructions/router.md
agent-instructions/worker.md
agent-instructions/arbiter.md
router.config.toml
worker.config.toml
arbiter.config.toml
bin/codex-tier-exec
bin/codex-sol-uninstall
config.toml
)
# Preflight everything in the backup/staging directory before touching live files.
mkdir -p "$backup_dir/original" "$staging_dir/agent-instructions" "$staging_dir/bin"
: > "$backup_dir/existed.txt"
if [[ -f "$codex_home/config.toml" ]]; then
cp -p "$codex_home/config.toml" "$staging_dir/config.toml"
fi
python3 "$repo_dir/scripts/patch_config.py" \
"$staging_dir/config.toml" "$codex_home/instruction.sol.md"
install -m 0644 "$repo_dir/instruction.sol.md" "$staging_dir/instruction.sol.md"
for role in router worker arbiter; do
install -m 0644 "$repo_dir/agent-instructions/$role.md" \
"$staging_dir/agent-instructions/$role.md"
python3 - "$repo_dir/profiles/$role.config.toml.in" "$staging_dir/$role.config.toml" \
"$codex_home/agent-instructions/$role.md" <<'PY'
import json
from pathlib import Path
import sys
source, target, instruction = map(Path, sys.argv[1:])
rendered = source.read_text().replace("__INSTRUCTIONS_FILE__", json.dumps(str(instruction)))
target.write_text(rendered)
PY
done
install -m 0755 "$repo_dir/bin/codex-tier-exec" "$staging_dir/bin/codex-tier-exec"
install -m 0755 "$repo_dir/uninstall.sh" "$staging_dir/bin/codex-sol-uninstall"
# Back up the live files only after preflight succeeds.
for rel in "${managed[@]}"; do
target="$codex_home/$rel"
if [[ -e "$target" ]]; then
mkdir -p "$backup_dir/original/$(dirname "$rel")"
cp -p "$target" "$backup_dir/original/$rel"
printf '%s\n' "$rel" >> "$backup_dir/existed.txt"
fi
done
if [[ -f "$state_file" ]]; then
cp -p "$state_file" "$backup_dir/previous-state.json"
fi
committed=0
rollback() {
code=$?
if [[ $committed -eq 0 ]]; then
for rel in "${managed[@]}"; do
target="$codex_home/$rel"
if grep -Fqx "$rel" "$backup_dir/existed.txt"; then
mkdir -p "$(dirname "$target")"
cp -p "$backup_dir/original/$rel" "$target"
else
rm -f "$target"
fi
done
if [[ -f "$backup_dir/previous-state.json" ]]; then
cp -p "$backup_dir/previous-state.json" "$state_file"
else
rm -f "$state_file"
fi
printf 'Installation failed; live files were rolled back. Backup: %s\n' "$backup_dir" >&2
fi
exit "$code"
}
trap rollback ERR
mkdir -p "$codex_home/agent-instructions" "$codex_home/bin"
for rel in "${managed[@]}"; do
target="$codex_home/$rel"
mkdir -p "$(dirname "$target")"
cp -p "$staging_dir/$rel" "$target"
done
python3 - "$state_file" "$backup_dir" "$codex_home" "${managed[@]}" <<'PY'
import hashlib
import json
from pathlib import Path
import sys
state = Path(sys.argv[1])
backup = sys.argv[2]
home = Path(sys.argv[3])
managed = sys.argv[4:]
hashes = {}
for relative in managed:
path = home / relative
hashes[relative] = hashlib.sha256(path.read_bytes()).hexdigest()
temporary = state.with_suffix(".tmp")
temporary.write_text(json.dumps({
"backup_dir": backup,
"installed_sha256": hashes,
}, indent=2) + "\n")
temporary.replace(state)
PY
committed=1
trap - ERR
rm -rf "$staging_dir"
printf '%s\n' "Installed Codex Sol orchestration into $codex_home"
printf '%s\n' "Backup: $backup_dir"
printf '%s\n' 'Restart Codex or start a new task before testing the profile.'