-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·57 lines (46 loc) · 1.15 KB
/
install.sh
File metadata and controls
executable file
·57 lines (46 loc) · 1.15 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
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
usage() {
cat <<'EOF'
Usage: install.sh [target_bin_dir]
Installs:
start-codex
switch-codex-account
codex-start
EOF
}
pick_target_bin() {
local path_entry
IFS=':' read -r -a path_parts <<< "${PATH:-}"
for path_entry in "${path_parts[@]}"; do
[[ -z "$path_entry" ]] && continue
if [[ -d "$path_entry" && -w "$path_entry" ]]; then
printf '%s\n' "$path_entry"
return 0
fi
done
printf '%s\n' "${HOME}/.local/bin"
}
install_file() {
local src="$1"
local dst="$2"
cp "$src" "$dst"
chmod 700 "$dst"
}
main() {
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
usage
exit 0
fi
local target_bin="${1:-}"
if [[ -z "$target_bin" ]]; then
target_bin="$(pick_target_bin)"
fi
mkdir -p "$target_bin"
install_file "${SCRIPT_DIR}/start-codex" "${target_bin}/start-codex"
install_file "${SCRIPT_DIR}/switch-codex-account" "${target_bin}/switch-codex-account"
install_file "${SCRIPT_DIR}/start-codex" "${target_bin}/codex-start"
printf 'Installed Codex account tools to %s\n' "$target_bin"
}
main "$@"