-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·176 lines (146 loc) · 4.02 KB
/
install.sh
File metadata and controls
executable file
·176 lines (146 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
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
#!/usr/bin/env bash
set -e
prompt_install_scope() {
if [ -n "${CODEXOS_INSTALL_SCOPE:-}" ]; then
case "$CODEXOS_INSTALL_SCOPE" in
repo|systemwide)
INSTALL_SCOPE="$CODEXOS_INSTALL_SCOPE"
return
;;
*)
echo "Invalid CODEXOS_INSTALL_SCOPE: $CODEXOS_INSTALL_SCOPE"
exit 1
;;
esac
fi
while true; do
cat <<'EOF'
Choose install scope for Codex-OS:
1) this repo only
2) systemwide
3) decline
EOF
read -r -p "Enter 1, 2, or 3: " scope_choice
case "$scope_choice" in
1) INSTALL_SCOPE="repo"; return ;;
2) INSTALL_SCOPE="systemwide"; return ;;
3)
printf '^C\n'
exit 130
;;
*) echo "Invalid choice. Please enter 1, 2, or 3." ;;
esac
done
}
confirm_systemwide_install() {
local backup_cmd='cp -R ~/.codex ~/.codex.backup.$(date +%Y%m%d%H%M%S)'
local restore_cmd='mv ~/.codex.backup.<timestamp> ~/.codex'
if [ "${CODEXOS_INSTALL_ACCEPT:-}" = "Accept" ]; then
return
fi
cat <<EOF
Systemwide install selected.
Backup your settings with:
${backup_cmd}
Retrieve them with:
${restore_cmd}
EOF
read -r -p "Type Accept to proceed or Decline to cancel: " decision
case "$decision" in
Accept) ;;
Decline)
printf '^C\n'
exit 130
;;
*)
echo "Install cancelled. Type Accept exactly to proceed."
printf '^C\n'
exit 130
;;
esac
}
echo "Setting up Codex-OS..."
prompt_install_scope
if [ "$INSTALL_SCOPE" = "repo" ]; then
chmod +x ./ro
echo "Repo-only setup complete."
echo "Use ./ro from this repository. No global Codex settings were changed."
exit 0
fi
confirm_systemwide_install
mkdir -p ~/.codex
# Link system
ln -sfn "$(pwd)" ~/.codex/system
# Expose ro globally (user-level)
mkdir -p ~/.local/bin
ln -sfn ~/.codex/system/ro ~/.local/bin/ro
chmod +x ~/.codex/system/ro
# Link codex binary into ~/.local/bin when discoverable
CODEX_BIN="$(command -v codex || true)"
if [ -z "$CODEX_BIN" ]; then
CODEX_BIN="$(ls -1dt "$HOME"/.vscode/extensions/openai.chatgpt-*/bin/*/codex 2>/dev/null | head -n 1 || true)"
fi
if [ -n "$CODEX_BIN" ]; then
ln -sfn "$CODEX_BIN" ~/.local/bin/codex
fi
# Also link into common global PATH bins when writable
for bin_dir in /usr/local/bin /opt/homebrew/bin; do
if [ -d "$bin_dir" ] && [ -w "$bin_dir" ]; then
ln -sfn ~/.codex/system/ro "$bin_dir/ro"
fi
done
# Ensure ~/.local/bin is on PATH for common shells
PATH_LINE='export PATH="$HOME/.local/bin:$PATH"'
ensure_path_line() {
local file="$1"
if [ ! -f "$file" ]; then
touch "$file"
fi
if ! grep -Fq "$PATH_LINE" "$file"; then
printf '\n%s\n' "$PATH_LINE" >> "$file"
fi
}
ensure_path_line "$HOME/.bash_profile"
ensure_path_line "$HOME/.bashrc"
ensure_path_line "$HOME/.zshrc"
# Make available in current shell for immediate use
export PATH="$HOME/.local/bin:$PATH"
# Ensure global plugin directory exists
mkdir -p ~/.codex/system/plugins
# Create plugin registry if missing
REGISTRY=~/.codex/system/plugin-registry.json
if [ ! -f "$REGISTRY" ]; then
cat <<EOF > "$REGISTRY"
{
"sql-helper": "https://github.com/example/sql-helper",
"debug-helper": "https://github.com/example/debug-helper",
"api-designer": "https://github.com/example/api-designer"
}
EOF
fi
# Link global AGENTS to system AGENTS (so VS Code chat uses the same rules)
GLOBAL_AGENTS="$HOME/.codex/AGENTS.md"
if [ -e "$GLOBAL_AGENTS" ] && [ ! -L "$GLOBAL_AGENTS" ]; then
cp "$GLOBAL_AGENTS" "$GLOBAL_AGENTS.bak.$(date +%Y%m%d%H%M%S)"
fi
ln -sfn ~/.codex/system/AGENTS.md "$GLOBAL_AGENTS"
# Create config if missing
CONFIG=~/.codex/config.toml
if [ ! -f "$CONFIG" ]; then
cat <<EOF > "$CONFIG"
project_doc_fallback_filenames = ["AGENTS.md"]
project_doc_max_bytes = 65536
[tools]
web_search = true
shell = true
[agent]
max_steps = 30
model_instructions_file = "~/.codex/AGENTS.md"
EOF
fi
echo "Codex setup complete."
if command -v ro >/dev/null 2>&1; then
echo "ro is available at: $(command -v ro)"
else
echo "'ro' is not yet in this shell PATH. Restart terminal or run: source ~/.bash_profile"
fi