Skip to content

Commit e37c768

Browse files
committed
feat: add robust cross-platform installer with OS/arch detection and version resolution
1 parent e9a83ea commit e37c768

1 file changed

Lines changed: 24 additions & 28 deletions

File tree

installer/install.sh

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@ echo "Installing Nimbus CLI..."
77
REPO="infraspecdev/faas-engine-go"
88
INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}"
99

10-
# Check dependencies
11-
for cmd in curl; do
12-
if ! command -v $cmd >/dev/null 2>&1; then
13-
echo "Error: $cmd is required"
14-
exit 1
15-
fi
16-
done
10+
# Check dependency
11+
if ! command -v curl >/dev/null 2>&1; then
12+
echo "Error: curl is required"
13+
exit 1
14+
fi
1715

18-
# Get version (allow override via VERSION env var)
16+
# Get version (allow override)
1917
VERSION="${1:-}"
2018
if [ -z "$VERSION" ]; then
2119
echo "Fetching latest version..."
22-
VERSION=$(curl -s https://api.github.com/repos/$REPO/releases/latest | grep -o '"tag_name":"[^"]*' | cut -d'"' -f4)
20+
VERSION=$(curl -s https://api.github.com/repos/$REPO/releases/latest | sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p')
2321
fi
2422

2523
if [ -z "$VERSION" ]; then
@@ -29,12 +27,12 @@ fi
2927

3028
echo "Version: $VERSION"
3129

32-
# Detect OS and Architecture
30+
# Detect OS and architecture
3331
OS="$(uname -s)"
3432
ARCH="$(uname -m)"
3533

3634
case "$OS" in
37-
Linux)
35+
Linux)
3836
case "$ARCH" in
3937
x86_64) FILE="nimbus-linux-amd64-$VERSION" ;;
4038
aarch64) FILE="nimbus-linux-arm64-$VERSION" ;;
@@ -57,34 +55,32 @@ esac
5755
URL="https://github.com/$REPO/releases/download/$VERSION/$FILE"
5856
TMPFILE=$(mktemp)
5957

60-
# Download with cleanup on error
6158
trap "rm -f $TMPFILE" EXIT
6259

63-
echo "Downloading binary from $URL..."
64-
if ! curl -fL --progress-bar -o "$TMPFILE" "$URL"; then
65-
echo "Error: Failed to download"
66-
exit 1
67-
fi
60+
echo "Downloading binary..."
61+
curl -fL --progress-bar -o "$TMPFILE" "$URL"
6862

6963
chmod +x "$TMPFILE"
7064

71-
# Verify directory and permissions
7265
if [ ! -d "$INSTALL_DIR" ]; then
7366
echo "Error: Install directory $INSTALL_DIR does not exist"
7467
exit 1
7568
fi
7669

77-
# Install
7870
echo "Installing to $INSTALL_DIR..."
7971

80-
if ! sudo mv "$TMPFILE" "$INSTALL_DIR/nimbus" 2>/dev/null; then
81-
if [ "$EUID" -ne 0 ]; then
82-
echo "Error: Insufficient permissions. Try running with sudo or as root."
83-
exit 1
84-
fi
85-
echo "Error: Failed to move binary"
86-
exit 1
72+
if [ "$EUID" -ne 0 ]; then
73+
sudo mv "$TMPFILE" "$INSTALL_DIR/nimbus"
74+
else
75+
mv "$TMPFILE" "$INSTALL_DIR/nimbus"
8776
fi
8877

89-
echo "✓ Installation complete"
90-
echo "Run: nimbus --help"
78+
echo "Installation complete"
79+
echo "Run: nimbus --help"
80+
81+
# PATH warning
82+
if ! command -v nimbus >/dev/null 2>&1; then
83+
echo "Warning: $INSTALL_DIR is not in your PATH"
84+
echo "Add it using:"
85+
echo " export PATH=\$PATH:$INSTALL_DIR"
86+
fi

0 commit comments

Comments
 (0)