-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·79 lines (65 loc) · 1.92 KB
/
install.sh
File metadata and controls
executable file
·79 lines (65 loc) · 1.92 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
#!/bin/sh
set -eu
REPO="rishabyd/codeberg-cli"
INSTALL_DIR="/usr/local/bin"
BINARY_NAME="cb"
detect_os() {
case "$(uname -s)" in
Linux*) echo "linux" ;;
*) echo "Unsupported operating system" >&2; exit 1 ;;
esac
}
detect_arch() {
case "$(uname -m)" in
x86_64|amd64) echo "amd64" ;;
aarch64|arm64) echo "arm64" ;;
*) echo "Unsupported architecture" >&2; exit 1 ;;
esac
}
require_cmd() {
command -v "$1" >/dev/null 2>&1 || { echo "Missing required command: $1" >&2; exit 1; }
}
fetch_latest_tag() {
url="https://api.github.com/repos/${REPO}/releases/latest"
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$url" | sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n1
return
fi
if command -v wget >/dev/null 2>&1; then
wget -qO- "$url" | sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n1
return
fi
echo "Need curl or wget" >&2
exit 1
}
main() {
require_cmd tar
os=$(detect_os)
arch=$(detect_arch)
tag=$(fetch_latest_tag)
[ -n "$tag" ] || { echo "Could not resolve latest release" >&2; exit 1; }
version=$(printf "%s" "$tag" | sed 's/^v//')
asset="${BINARY_NAME}_${version}_${os}_${arch}.tar.gz"
url="https://github.com/${REPO}/releases/download/${tag}/${asset}"
tmp_dir=$(mktemp -d)
trap 'rm -rf "$tmp_dir"' EXIT
archive_path="${tmp_dir}/${asset}"
echo "Downloading ${asset}..."
if command -v curl >/dev/null 2>&1; then
curl -fsSL "$url" -o "$archive_path"
else
wget -qO "$archive_path" "$url"
fi
tar -xzf "$archive_path" -C "$tmp_dir"
chmod +x "${tmp_dir}/${BINARY_NAME}"
target="${INSTALL_DIR}/${BINARY_NAME}"
if [ -w "$INSTALL_DIR" ]; then
mv "${tmp_dir}/${BINARY_NAME}" "$target"
else
echo "Installing to ${target} (sudo may prompt)..."
sudo mv "${tmp_dir}/${BINARY_NAME}" "$target"
fi
echo "Installed ${BINARY_NAME} ${tag} to ${target}"
echo "Run: cb auth login"
}
main