-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·87 lines (74 loc) · 2.6 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·87 lines (74 loc) · 2.6 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
#!/bin/bash
set -euo pipefail
# resolve paths relative to this script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
WORK_DIR="$SCRIPT_DIR/work"
ELECTRON="$WORK_DIR/native/node_modules/electron/dist/electron"
APP="$WORK_DIR/app"
# Ensure Bun-installed CLIs are discoverable even from desktop launchers.
export PATH="$HOME/.bun/bin:$PATH"
command -v bun >/dev/null 2>&1 || {
echo "Bun not found. Install it from https://bun.sh and retry."
exit 1
}
# find codex cli
if [ -n "${CODEX_CLI_PATH:-}" ]; then
CODEX_CLI="$CODEX_CLI_PATH"
elif command -v codex >/dev/null 2>&1; then
CODEX_CLI="$(command -v codex)"
else
CODEX_CLI="$(find "$HOME/.bun/install/global/node_modules/@openai/codex/vendor" -type f -name codex -print -quit 2>/dev/null || true)"
fi
if [ ! -f "$ELECTRON" ]; then
echo "Electron not found. Run ./setup.sh first."
exit 1
fi
if [ -z "${CODEX_CLI:-}" ] || [ ! -x "$CODEX_CLI" ]; then
cat <<EOF
Unable to locate the Codex CLI binary.
Install the CLI and retry:
bun install -g @openai/codex
Or set an explicit path:
CODEX_CLI_PATH=/absolute/path/to/codex ./run.sh
EOF
exit 1
fi
export ELECTRON_FORCE_IS_PACKAGED=1
DETECTED_BUILD_NUMBER=$(bun -e '
const packageJson = await Bun.file(process.argv[1]).json();
const buildNumber = packageJson.codexBuildNumber;
if (typeof buildNumber !== "string" || !/^\d+$/.test(buildNumber)) process.exit(1);
console.log(buildNumber);
' "$APP/package.json") || {
echo "Unable to read the Codex build number from $APP/package.json."
exit 1
}
export CODEX_BUILD_NUMBER="${CODEX_BUILD_NUMBER:-$DETECTED_BUILD_NUMBER}"
export CODEX_BUILD_FLAVOR=prod
export BUILD_FLAVOR=prod
export NODE_ENV=production
export CODEX_CLI_PATH="$CODEX_CLI"
export ELECTRON_RENDERER_URL="file://$APP/webview/index.html"
# Linux "clean mode": reduce non-essential Chromium background services.
# Set CODEX_LINUX_CLEAN_MODE=0 to disable.
CODEX_LINUX_CLEAN_MODE="${CODEX_LINUX_CLEAN_MODE:-1}"
EXTRA_FLAGS=()
if [ "$CODEX_LINUX_CLEAN_MODE" = "1" ]; then
EXTRA_FLAGS+=(
--disable-breakpad
--disable-component-update
--disable-features=MediaRouter,OptimizationHints,AutofillServerCommunication
)
fi
# Optional: disable GPU process to reduce helper process count further.
# Set CODEX_DISABLE_GPU=1 when needed.
if [ "${CODEX_DISABLE_GPU:-0}" = "1" ]; then
EXTRA_FLAGS+=(--disable-gpu)
fi
# Keep Chromium's sandbox enabled by default. Use this only as a compatibility
# fallback on systems where Electron cannot initialize its sandbox.
if [ "${CODEX_DISABLE_SANDBOX:-0}" = "1" ]; then
EXTRA_FLAGS+=(--no-sandbox)
fi
cd "$APP"
exec "$ELECTRON" "$APP" "${EXTRA_FLAGS[@]}" "$@"