-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
81 lines (66 loc) · 2.37 KB
/
Copy pathinstall.sh
File metadata and controls
81 lines (66 loc) · 2.37 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
#!/bin/sh
set -e
# GitHub repository details
OWNER="morriganreza973"
REPO="codex"
BINARY_NAME="codex"
# Determine OS and Architecture
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
ARCH="$(uname -m)"
case "${ARCH}" in
x86_64) ARCH="amd64" ;;
arm64|aarch64) ARCH="arm64" ;;
*) echo "Unsupported architecture: ${ARCH}"; exit 1 ;;
esac
# Fetch latest release version
API_URL="https://api.github.com/repos/${OWNER}/${REPO}/releases/latest"
# Determine the authorization header if a token is available
AUTH_HEADER=""
if [ -n "${GH_TOKEN}" ]; then
AUTH_HEADER="Authorization: Bearer ${GH_TOKEN}"
elif [ -n "${GITHUB_TOKEN}" ]; then
AUTH_HEADER="Authorization: Bearer ${GITHUB_TOKEN}"
fi
# Disable xtrace to prevent leaking token if run with sh -x
case "$-" in
*x*) was_x=1; set +x ;;
*) was_x=0 ;;
esac
if command -v curl >/dev/null 2>&1; then
if [ -n "${AUTH_HEADER}" ]; then
LATEST_RELEASE=$(curl -H "${AUTH_HEADER}" -s "${API_URL}" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
else
LATEST_RELEASE=$(curl -s "${API_URL}" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
fi
elif command -v wget >/dev/null 2>&1; then
if [ -n "${AUTH_HEADER}" ]; then
LATEST_RELEASE=$(wget --header="${AUTH_HEADER}" -qO- "${API_URL}" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
else
LATEST_RELEASE=$(wget -qO- "${API_URL}" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
fi
else
if [ "$was_x" = 1 ]; then set -x; fi
echo "Error: curl or wget is required to install ${BINARY_NAME}." >&2
exit 1
fi
# Restore xtrace if it was enabled
if [ "$was_x" = 1 ]; then
set -x
fi
if [ -z "${LATEST_RELEASE}" ]; then
echo "Error: Failed to fetch the latest release version." >&2
exit 1
fi
# Download URL
DOWNLOAD_URL="https://github.com/${OWNER}/${REPO}/releases/download/${LATEST_RELEASE}/${BINARY_NAME}-${OS}-${ARCH}"
# Installation directory
INSTALL_DIR="/usr/local/bin"
# Download and install
echo "Downloading ${BINARY_NAME} ${LATEST_RELEASE} for ${OS}/${ARCH}..."
if command -v curl >/dev/null 2>&1; then
sudo curl -L -o "${INSTALL_DIR}/${BINARY_NAME}" "${DOWNLOAD_URL}"
elif command -v wget >/dev/null 2>&1; then
sudo wget -O "${INSTALL_DIR}/${BINARY_NAME}" "${DOWNLOAD_URL}"
fi
sudo chmod +x "${INSTALL_DIR}/${BINARY_NAME}"
echo "${BINARY_NAME} installed successfully to ${INSTALL_DIR}/${BINARY_NAME}"