Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
Latest commit
executable file
·280 lines (248 loc) · 7.78 KB
/
Copy pathinstall
File metadata and controls
executable file
·280 lines (248 loc) · 7.78 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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/usr/bin/env bash
set -euo pipefail
APP="codius"
REPOSITORY="CodiusAI/codius-cli"
MUTED='\033[0;2m'
RED='\033[0;31m'
CYAN='\033[0;36m'
YELLOW='\033[0;33m'
NC='\033[0m'
usage() {
cat <<'EOF'
Codius CLI installer
Usage: install [options]
Options:
-h, --help Display this help message
-v, --version <version> Install a specific release, with or without a leading v
-b, --binary <path> Install a local Codius binary
--no-modify-path Do not modify shell startup files
Environment:
VERSION Release version when --version is omitted
CODIUS_INSTALL_DIR Exact directory that should contain the codius binary
XDG_BIN_DIR XDG-compatible binary directory
Examples:
curl -fsSL https://raw.githubusercontent.com/CodiusAI/codius-cli/dev/install | bash
curl -fsSL https://raw.githubusercontent.com/CodiusAI/codius-cli/dev/install | bash -s -- --version 1.18.4
./install --binary /path/to/codius
EOF
}
requested_version="${VERSION:-}"
local_binary=""
modify_path=true
while [[ $#-gt 0 ]];do
case"$1"in
-h|--help)
usage
exit 0
;;
-v|--version)
[[ -n"${2:-}" ]] || { echo -e "${RED}Error: --version requires a value${NC}">&2;exit 1; }
requested_version="$2"
shift 2
;;
-b|--binary)
[[ -n"${2:-}" ]] || { echo -e "${RED}Error: --binary requires a path${NC}">&2;exit 1; }
local_binary="$2"
shift 2
;;
--no-modify-path)
modify_path=false
shift
;;
*)
echo -e "${YELLOW}Warning: ignoring unknown option '$1'${NC}">&2
shift
;;
esac
done
require_command() {
command -v "$1">/dev/null 2>&1|| {
echo -e "${RED}Error: '$1' is required${NC}">&2
exit 1
}
}
resolve_install_dir() {
if [[ -n"${CODIUS_INSTALL_DIR:-}" ]];then
printf'%s\n'"$CODIUS_INSTALL_DIR"
return
fi
if [[ -n"${XDG_BIN_DIR:-}" ]];then
printf'%s\n'"$XDG_BIN_DIR"
return
fi
if [[ -d"$HOME/bin"&&-w"$HOME/bin" ]];then
printf'%s\n'"$HOME/bin"
return
fi
printf'%s\n'"$HOME/.codius/bin"
}
INSTALL_DIR="$(resolve_install_dir)"
INSTALL_PATH="$INSTALL_DIR/$APP"
mkdir -p "$INSTALL_DIR"
normalize_platform() {
local raw_os raw_arch
raw_os="$(uname -s)"
raw_arch="$(uname -m)"
case"$raw_os"in
Darwin*) os="darwin" ;;
Linux*) os="linux" ;;
MINGW*|MSYS*|CYGWIN*) os="windows" ;;
*)
echo -e "${RED}Unsupported operating system: $raw_os${NC}">&2
exit 1
;;
esac
case"$raw_arch"in
x86_64|amd64) arch="x64" ;;
arm64|aarch64) arch="arm64" ;;
*)
echo -e "${RED}Unsupported architecture: $raw_arch${NC}">&2
exit 1
;;
esac
if [[ "$os"=="darwin"&&"$arch"=="x64" ]];then
local translated
translated="$(sysctl -n sysctl.proc_translated 2>/dev/null ||echo 0)"
[[ "$translated"=="1" ]] && arch="arm64"
fi
}
supports_avx2() {
[[ "$arch"=="x64" ]] ||return 1
if [[ "$os"=="linux" ]];then
grep -qwi avx2 /proc/cpuinfo 2>/dev/null
return
fi
if [[ "$os"=="darwin" ]];then
[[ "$(sysctl -n hw.optional.avx2_0 2>/dev/null ||echo 0)"=="1" ]]
return
fi
if [[ "$os"=="windows" ]];then
localcommand output
command='(Add-Type -MemberDefinition "[DllImport(""kernel32.dll"")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);" -Name Kernel32 -Namespace Win32 -PassThru)::IsProcessorFeaturePresent(40)'
output=""
ifcommand -v powershell.exe >/dev/null 2>&1;then
output="$(powershell.exe -NoProfile -NonInteractive -Command "$command"2>/dev/null || true)"
elifcommand -v pwsh >/dev/null 2>&1;then
output="$(pwsh -NoProfile -NonInteractive -Command "$command"2>/dev/null || true)"
fi
output="$(printf '%s'"$output"| tr -d '\r[:space:]'| tr '[:upper:]''[:lower:]')"
[[ "$output"=="true"||"$output"=="1" ]]
return
fi
return 1
}
uses_musl() {
[[ "$os"=="linux" ]] ||return 1
[[ -f /etc/alpine-release ]] &&return 0
command -v ldd >/dev/null 2>&1&& ldd --version 2>&1| grep -qi musl
}
install_binary() {
local source="$1"
local temp_path="$INSTALL_PATH.tmp.$$"
cp "$source""$temp_path"
chmod 755 "$temp_path"
mv -f "$temp_path""$INSTALL_PATH"
}
if [[ -n"$local_binary" ]];then
[[ -f"$local_binary" ]] || {
echo -e "${RED}Error: binary not found at $local_binary${NC}">&2
exit 1
}
echo -e "${MUTED}Installing local Codius binary from${NC}$local_binary"
install_binary "$local_binary"
installed_version="local"
else
require_command curl
normalize_platform
target="$os-$arch"
if [[ "$arch"=="x64" ]] &&! supports_avx2;then
target="$target-baseline"
fi
if uses_musl;then
target="$target-musl"
fi
archive_extension="zip"
[[ "$os"=="linux" ]] && archive_extension="tar.gz"
filename="$APP-$target.$archive_extension"
requested_version="${requested_version#v}"
if [[ -z"$requested_version" ]];then
release_json="$(curl -fsSL -H 'Accept: application/vnd.github+json'"https://api.github.com/repos/$REPOSITORY/releases/latest")"
installed_version="$(printf '%s'"$release_json"| sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"v\{0,1\}\([^"]*\)".*/\1/p'| head -n 1)"
[[ -n"$installed_version" ]] || {
echo -e "${RED}Error: unable to determine the latest Codius release${NC}">&2
exit 1
}
else
installed_version="$requested_version"
fi
ifcommand -v "$APP">/dev/null 2>&1;then
current_version="$($APP --version 2>/dev/null || true)"
if [[ "$current_version"=="$installed_version" ]];then
echo -e "${MUTED}Codius $installed_version is already installed.${NC}"
exit 0
fi
fi
url="https://github.com/$REPOSITORY/releases/download/v$installed_version/$filename"
temp_dir="$(mktemp -d "${TMPDIR:-/tmp}/codius-install.XXXXXX")"
trap'rm -rf "$temp_dir"' EXIT
echo -e "${MUTED}Downloading${NC} Codius $installed_version${MUTED}for${NC}$target"
curl -fL --retry 3 --retry-delay 1 --progress-bar -o "$temp_dir/$filename""$url"
if [[ "$archive_extension"=="tar.gz" ]];then
require_command tar
tar -xzf "$temp_dir/$filename" -C "$temp_dir"
else
require_command unzip
unzip -q "$temp_dir/$filename" -d "$temp_dir"
fi
extracted="$temp_dir/codius"
[[ "$os"=="windows"&&-f"$temp_dir/codius.exe" ]] && extracted="$temp_dir/codius.exe"
[[ -f"$extracted" ]] || {
echo -e "${RED}Error: the release archive did not contain a Codius binary${NC}">&2
exit 1
}
install_binary "$extracted"
fi
add_to_path() {
local file="$1"
local command="$2"
[[ -f"$file" ]] || touch "$file"
if grep -Fqx "$command""$file"2>/dev/null;then
return
fi
{
printf'\n# Codius CLI\n'
printf'%s\n'"$command"
} >>"$file"
echo -e "${MUTED}Added Codius to PATH in${NC}$file"
}
if [[ "$modify_path"==true&&":$PATH:"!=*":$INSTALL_DIR:"* ]];then
shell_name="$(basename "${SHELL:-sh}")"
case"$shell_name"in
fish)
add_to_path "$HOME/.config/fish/config.fish""fish_add_path $INSTALL_DIR"
;;
zsh)
add_to_path "${ZDOTDIR:-$HOME}/.zshrc""export PATH=\"$INSTALL_DIR:\$PATH\""
;;
bash)
add_to_path "$HOME/.bashrc""export PATH=\"$INSTALL_DIR:\$PATH\""
;;
*)
add_to_path "$HOME/.profile""export PATH=\"$INSTALL_DIR:\$PATH\""
;;
esac
fi
if [[ "${GITHUB_ACTIONS:-}"=="true"&&-n"${GITHUB_PATH:-}" ]];then
printf'%s\n'"$INSTALL_DIR">>"$GITHUB_PATH"
fi
printf'\n'
echo -e "${CYAN}Codius CLI installed${NC}${MUTED}($installed_version)${NC}"
echo -e "${MUTED}Binary:${NC}$INSTALL_PATH"
if [[ ":$PATH:"!=*":$INSTALL_DIR:"* ]];then
echo -e "${YELLOW}Open a new terminal or run:${NC} export PATH=\"$INSTALL_DIR:\$PATH\""
fi
printf'\n'
echo"cd <project>"
echo"codius"
printf'\n'
echo -e "${MUTED}Documentation:${NC} https://codius.ai"