-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·67 lines (56 loc) · 1.91 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·67 lines (56 loc) · 1.91 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
#!/usr/bin/env bash
set -euo pipefail
# KosmoKrator installer — detects OS/arch and downloads the right binary.
# Usage: curl -fsSL https://raw.githubusercontent.com/OpenCompanyApp/kosmokrator/main/install.sh | bash
REPO="OpenCompanyApp/kosmokrator"
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
CANONICAL_BIN="kosmo"
LEGACY_BIN="kosmokrator"
ASSET_PREFIX="kosmokrator"
# Detect platform
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Darwin) PLATFORM="macos" ;;
Linux) PLATFORM="linux" ;;
*)
echo "Error: Unsupported OS: $OS" >&2
exit 1
;;
esac
case "$ARCH" in
arm64|aarch64) ARCH_SUFFIX="aarch64" ;;
x86_64|amd64) ARCH_SUFFIX="x86_64" ;;
*)
echo "Error: Unsupported architecture: $ARCH" >&2
exit 1
;;
esac
ASSET="${ASSET_PREFIX}-${PLATFORM}-${ARCH_SUFFIX}"
URL="https://github.com/${REPO}/releases/latest/download/${ASSET}"
echo "Detected: ${PLATFORM}/${ARCH_SUFFIX}"
echo "Downloading: ${ASSET}"
# Check if we need sudo
NEED_SUDO=""
if [ ! -w "$INSTALL_DIR" ] 2>/dev/null; then
NEED_SUDO="sudo"
echo "Note: ${INSTALL_DIR} requires root — using sudo"
fi
$NEED_SUDO mkdir -p "$INSTALL_DIR"
$NEED_SUDO curl -fSL "$URL" -o "${INSTALL_DIR}/${CANONICAL_BIN}"
$NEED_SUDO chmod +x "${INSTALL_DIR}/${CANONICAL_BIN}"
# Keep the old command working. Prefer a symlink, but fall back to a tiny
# wrapper on filesystems that do not allow symlinks.
if ! $NEED_SUDO ln -sfn "${CANONICAL_BIN}" "${INSTALL_DIR}/${LEGACY_BIN}" 2>/dev/null; then
tmp_wrapper="$(mktemp)"
cat > "$tmp_wrapper" <<'WRAPPER'
#!/usr/bin/env sh
exec "$(dirname "$0")/kosmo" "$@"
WRAPPER
$NEED_SUDO mv "$tmp_wrapper" "${INSTALL_DIR}/${LEGACY_BIN}"
$NEED_SUDO chmod +x "${INSTALL_DIR}/${LEGACY_BIN}"
fi
echo ""
echo "Installed: ${INSTALL_DIR}/${CANONICAL_BIN}"
echo "Compatibility command: ${INSTALL_DIR}/${LEGACY_BIN}"
"${INSTALL_DIR}/${CANONICAL_BIN}" --version 2>/dev/null || true