-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·227 lines (205 loc) · 5.49 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·227 lines (205 loc) · 5.49 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/env sh
set -eu
repo="UtenKekkoDev/cli-model-switcher"
branch="main"
codex_home="${CODEX_HOME:-$HOME/.codex}"
install_dir="$codex_home/skills/cli-model-switcher"
shell_name="auto"
recipes="opencode-openrouter,local-ollama"
active="opencode-openrouter"
mode="wizard"
dry_run="0"
no_install="0"
usage() {
cat <<'EOF'
Install CLI Model Switcher on Linux, macOS, or WSL.
Usage:
sh install.sh [options]
Options:
--dir DIR Install directory. Defaults to $CODEX_HOME/skills/cli-model-switcher or ~/.codex/skills/cli-model-switcher.
--repo OWNER/REPO GitHub repository. Defaults to UtenKekkoDev/cli-model-switcher.
--branch NAME Git branch to install. Defaults to main.
--shell NAME Shell helper target: auto, bash, zsh, or fish. Defaults to auto.
--recipes LIST Comma-separated setup wizard recipes. Defaults to opencode-openrouter,local-ollama.
--active NAME Active setup profile. Defaults to opencode-openrouter.
--lite Use setup --lite for minimal ai-lite and shell helper setup.
--full Use setup --full instead of setup --wizard --yes.
--no-install Initialize profiles without writing shell helper files.
--dry-run Print and validate the planned install without cloning or writing files.
-h, --help Show this help.
EOF
}
while [ "$#" -gt 0 ]; do
case "$1" in
--dir)
install_dir="$2"
shift 2
;;
--repo)
repo="$2"
shift 2
;;
--branch)
branch="$2"
shift 2
;;
--shell)
shell_name="$2"
shift 2
;;
--recipes)
recipes="$2"
shift 2
;;
--active)
active="$2"
shift 2
;;
--full)
if [ "$mode" != "wizard" ]; then
echo "Choose only one install mode: --lite or --full." >&2
exit 2
fi
mode="full"
shift
;;
--lite)
if [ "$mode" != "wizard" ]; then
echo "Choose only one install mode: --lite or --full." >&2
exit 2
fi
mode="lite"
shift
;;
--no-install)
no_install="1"
shift
;;
--dry-run)
dry_run="1"
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown option: $1" >&2
usage >&2
exit 2
;;
esac
done
case "$shell_name" in
auto|bash|zsh|fish) ;;
*)
echo "Unsupported --shell value: $shell_name" >&2
exit 2
;;
esac
find_python() {
if [ -n "${AI_CLI_SWITCHER_PYTHON:-}" ]; then
printf '%s\n' "$AI_CLI_SWITCHER_PYTHON"
return
fi
if command -v python3 >/dev/null 2>&1; then
command -v python3
return
fi
if command -v python >/dev/null 2>&1; then
command -v python
return
fi
echo "Python 3 was not found. Install Python 3 or set AI_CLI_SWITCHER_PYTHON." >&2
exit 1
}
python_bin="$(find_python)"
script_dir="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
run_setup() {
root="$1"
setup_dry_run="${2:-0}"
helper="$root/scripts/cli_model_switcher.py"
if [ ! -f "$helper" ]; then
echo "Missing helper script: $helper" >&2
exit 1
fi
set -- "$helper" setup
if [ "$mode" = "lite" ]; then
set -- "$@" --lite
elif [ "$mode" = "full" ]; then
set -- "$@" --full
else
set -- "$@" --wizard --yes --recipes "$recipes" --active "$active"
fi
set -- "$@" --shell "$shell_name"
if [ "$no_install" = "1" ]; then
set -- "$@" --no-install
fi
if [ "$setup_dry_run" = "1" ]; then
set -- "$@" --dry-run
fi
"$python_bin" "$@"
}
clone_or_update() {
if [ -d "$install_dir/.git" ]; then
git -C "$install_dir" fetch origin "$branch"
git -C "$install_dir" checkout "$branch"
git -C "$install_dir" pull --ff-only origin "$branch"
return
fi
if [ -f "$install_dir/scripts/cli_model_switcher.py" ]; then
echo "Using existing installation at $install_dir"
return
fi
if [ -e "$install_dir" ] && [ "$(find "$install_dir" -mindepth 1 -maxdepth 1 2>/dev/null | head -n 1)" ]; then
echo "Install directory is not empty and is not a CLI Model Switcher checkout: $install_dir" >&2
exit 1
fi
if command -v git >/dev/null 2>&1; then
mkdir -p "$(dirname "$install_dir")"
git clone --depth 1 --branch "$branch" "https://github.com/$repo.git" "$install_dir"
return
fi
tmp_dir="$(mktemp -d)"
archive="$tmp_dir/source.tar.gz"
archive_url="https://github.com/$repo/archive/refs/heads/$branch.tar.gz"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$archive_url" -o "$archive"
elif command -v wget >/dev/null 2>&1; then
wget -qO "$archive" "$archive_url"
else
echo "Need git, curl, or wget to download $repo." >&2
exit 1
fi
mkdir -p "$install_dir"
tar -xzf "$archive" -C "$install_dir" --strip-components=1
rm -rf "$tmp_dir"
}
echo "CLI Model Switcher installer"
echo "Repository: $repo"
echo "Branch: $branch"
echo "Install directory: $install_dir"
echo "Shell: $shell_name"
echo "Python: $python_bin"
if [ "$dry_run" = "1" ]; then
echo "Dry run: would clone/update and run setup."
if [ -f "$script_dir/scripts/cli_model_switcher.py" ]; then
run_setup "$script_dir" "1"
else
echo "Dry run skipped setup execution because the helper script is not next to install.sh."
fi
exit 0
fi
clone_or_update
run_setup "$install_dir"
cat <<EOF
Installed CLI Model Switcher.
Open a new terminal or reload the shell profile printed above, then run:
ayatori about
ayatori status
ai-lite --dry-run
ai-status
ai-doctor --fix
In each project where you want simple agent-side switching, run:
ai-lite
EOF