11#! /usr/bin/env bash
22set -euo pipefail
3+ umask 077
34
45DISPLAY_NAME=" Codex Desktop"
56SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
@@ -9,16 +10,101 @@ LOG_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/codex-ubuntu"
910LOG_FILE=" ${LOG_DIR} /electron-wrapper.log"
1011
1112mkdir -p " $LOG_DIR "
12-
13- if [ -f " $CONFIG_FILE " ]; then
14- # shellcheck disable=SC1090
15- . " $CONFIG_FILE "
16- fi
13+ chmod 700 " $LOG_DIR " > /dev/null 2>&1 || true
14+ mkdir -p " $CONFIG_DIR "
15+ chmod 700 " $CONFIG_DIR " > /dev/null 2>&1 || true
1716
1817log () {
1918 printf ' [%s] %s\n' " $( date -Is) " " $* " >> " $LOG_FILE "
2019}
2120
21+ load_config_file () {
22+ local config_output=" "
23+ local line=" "
24+ local key=" "
25+ local value=" "
26+
27+ [ -f " $CONFIG_FILE " ] || return 0
28+
29+ chmod 600 " $CONFIG_FILE " > /dev/null 2>&1 || true
30+
31+ if ! config_output=" $( python3 - " $CONFIG_FILE " << 'PY '
32+ from pathlib import Path
33+ import shlex
34+ import sys
35+
36+ config_path = Path(sys.argv[1])
37+ allowed_keys = {
38+ "CODEX_UBUNTU_ELECTRON_APP_ROOT",
39+ "CODEX_UBUNTU_NODE_BIN_DIR",
40+ }
41+
42+ for line_number, raw_line in enumerate(
43+ config_path.read_text(encoding="utf-8").splitlines(),
44+ start=1,
45+ ):
46+ stripped = raw_line.strip()
47+ if not stripped or stripped.startswith("#"):
48+ continue
49+ if "=" not in raw_line:
50+ print(
51+ f"Invalid config line in {config_path}:{line_number}",
52+ file=sys.stderr,
53+ )
54+ raise SystemExit(1)
55+
56+ key, raw_value = raw_line.split("=", 1)
57+ key = key.strip()
58+ if key not in allowed_keys:
59+ print(
60+ f"Unsupported key in {config_path}:{line_number}: {key}",
61+ file=sys.stderr,
62+ )
63+ raise SystemExit(1)
64+
65+ raw_value = raw_value.strip()
66+ if not raw_value:
67+ value = ""
68+ else:
69+ try:
70+ tokens = shlex.split(raw_value, posix=True)
71+ except ValueError as exc:
72+ print(
73+ f"Invalid shell-like value for {key} in {config_path}:{line_number}: {exc}",
74+ file=sys.stderr,
75+ )
76+ raise SystemExit(1)
77+
78+ if len(tokens) != 1:
79+ print(
80+ f"Invalid shell-like value for {key} in {config_path}:{line_number}",
81+ file=sys.stderr,
82+ )
83+ raise SystemExit(1)
84+
85+ value = tokens[0]
86+
87+ print(f"{key}={value}")
88+ PY
89+ ) " ; then
90+ return 1
91+ fi
92+
93+ while IFS= read -r line; do
94+ [ -n " $line " ] || continue
95+ key=" ${line%% =* } "
96+ value=" ${line#* =} "
97+ case " $key " in
98+ CODEX_UBUNTU_ELECTRON_APP_ROOT)
99+ CODEX_UBUNTU_ELECTRON_APP_ROOT=" $value "
100+ ;;
101+ CODEX_UBUNTU_NODE_BIN_DIR)
102+ CODEX_UBUNTU_NODE_BIN_DIR=" $value "
103+ ;;
104+ esac
105+ done <<< " $config_output"
106+ }
107+
22108prepend_path_once () {
23109 local dir=" $1 "
24110 case " :$PATH :" in
@@ -86,6 +172,7 @@ main() {
86172 local node_bin_dir=" "
87173 local app_root=" "
88174
175+ load_config_file
89176 prepend_path_once " ${HOME} /.local/bin"
90177 if node_bin_dir=" $( resolve_node_bin_dir) " ; then
91178 prepend_path_once " $node_bin_dir "
0 commit comments