-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
84 lines (70 loc) · 2.32 KB
/
install.sh
File metadata and controls
84 lines (70 loc) · 2.32 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
#!/bin/sh
set -e
REPO="ScaleCommerce-DEV/scdev"
BINARY="scdev"
BIN_DIR="$HOME/.scdev/bin"
SYMLINK_DIR="/usr/local/bin"
# Detect OS
OS="$(uname -s)"
case "$OS" in
Darwin) OS="darwin" ;;
Linux) OS="linux" ;;
*) echo "Unsupported OS: $OS"; exit 1 ;;
esac
# Detect architecture
ARCH="$(uname -m)"
case "$ARCH" in
x86_64|amd64) ARCH="amd64" ;;
arm64|aarch64) ARCH="arm64" ;;
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
esac
# Check for Docker
if ! command -v docker >/dev/null 2>&1; then
echo "Warning: Docker is not installed. scdev requires Docker to run."
fi
ASSET="${BINARY}-${OS}-${ARCH}"
URL="https://github.com/${REPO}/releases/latest/download/${ASSET}"
CHECKSUMS_URL="https://github.com/${REPO}/releases/latest/download/checksums.txt"
echo "Downloading scdev for ${OS}/${ARCH}..."
mkdir -p "$BIN_DIR"
TMP_BIN="$(mktemp)"
TMP_SUMS="$(mktemp)"
# shellcheck disable=SC2064
trap "rm -f '$TMP_BIN' '$TMP_SUMS'" EXIT
curl -fsSL -o "$TMP_BIN" "$URL"
curl -fsSL -o "$TMP_SUMS" "$CHECKSUMS_URL"
# Verify SHA256. The checksums file is 'sha256 filename' per line; grep
# for our asset and run sha256sum (or shasum on macOS) against it.
EXPECTED="$(grep " ${ASSET}$" "$TMP_SUMS" | awk '{print $1}')"
if [ -z "$EXPECTED" ]; then
echo "error: no checksum for ${ASSET} in checksums.txt"
exit 1
fi
if command -v sha256sum >/dev/null 2>&1; then
ACTUAL="$(sha256sum "$TMP_BIN" | awk '{print $1}')"
else
ACTUAL="$(shasum -a 256 "$TMP_BIN" | awk '{print $1}')"
fi
if [ "$EXPECTED" != "$ACTUAL" ]; then
echo "error: checksum mismatch for ${ASSET}"
echo " expected: ${EXPECTED}"
echo " actual: ${ACTUAL}"
exit 1
fi
mv "$TMP_BIN" "$BIN_DIR/$BINARY"
chmod +x "$BIN_DIR/$BINARY"
# Remove macOS quarantine attribute
if [ "$OS" = "darwin" ] && command -v xattr >/dev/null 2>&1; then
xattr -d com.apple.quarantine "$BIN_DIR/$BINARY" 2>/dev/null || true
fi
# Symlink into a PATH location. The real binary stays in the user-owned
# $BIN_DIR so future `scdev self-update` runs never need sudo.
if [ -w "$SYMLINK_DIR" ]; then
ln -sfn "$BIN_DIR/$BINARY" "$SYMLINK_DIR/$BINARY"
else
echo "Creating symlink in ${SYMLINK_DIR} (requires sudo, one-time)..."
sudo ln -sfn "$BIN_DIR/$BINARY" "$SYMLINK_DIR/$BINARY"
fi
echo "scdev installed to ${BIN_DIR}/${BINARY}"
echo " symlinked from ${SYMLINK_DIR}/${BINARY}"
scdev version