-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·86 lines (68 loc) · 2.4 KB
/
install.sh
File metadata and controls
executable file
·86 lines (68 loc) · 2.4 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
85
86
#!/bin/sh
set -e
REPO="hardhackerlabs/podwise-cli"
BINARY_NAME="podwise"
# Default install directory
INSTALL_DIR="/usr/local/bin"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo "==> Installing $BINARY_NAME from $REPO..."
# Detect OS
OS=$(uname -s)
case "$OS" in
Linux) OS="linux" ;;
Darwin) OS="darwin" ;;
*) echo "${RED}Error: Unsupported operating system: $OS${NC}"; exit 1 ;;
esac
# Detect Architecture
ARCH=$(uname -m)
case "$ARCH" in
x86_64|amd64) ARCH="amd64" ;;
arm64|aarch64) ARCH="arm64" ;;
*) echo "${RED}Error: Unsupported architecture: $ARCH${NC}"; exit 1 ;;
esac
echo "==> Detected OS: $OS, Architecture: $ARCH"
# Fetch latest version if not specified
if [ -z "$VERSION" ]; then
echo "==> Fetching latest release version..."
VERSION=$(curl -s "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$VERSION" ]; then
echo "${RED}Error: Could not determine the latest version from GitHub.${NC}"
exit 1
fi
fi
echo "==> Version to install: $VERSION"
# Format the filename according to .goreleaser.yaml: podwise_linux_amd64.tar.gz
FILE_NAME="${BINARY_NAME}_${OS}_${ARCH}.tar.gz"
DOWNLOAD_URL="https://github.com/$REPO/releases/download/$VERSION/$FILE_NAME"
# Create a temporary directory
TMP_DIR=$(mktemp -d)
trap 'rm -rf "$TMP_DIR"' EXIT
echo "==> Downloading $FILE_NAME..."
curl -sL -o "$TMP_DIR/$FILE_NAME" "$DOWNLOAD_URL"
echo "==> Extracting archive..."
cd "$TMP_DIR"
tar xzf "$FILE_NAME"
if [ ! -f "$BINARY_NAME" ]; then
echo "${RED}Error: Binary '$BINARY_NAME' not found in the downloaded archive.${NC}"
exit 1
fi
# Determine the installation directory (fallback to ~/.local/bin if /usr/local/bin is not writable)
if [ ! -w "$INSTALL_DIR" ]; then
INSTALL_DIR="$HOME/.local/bin"
mkdir -p "$INSTALL_DIR"
# Check if ~/.local/bin is in PATH
if ! echo "$PATH" | grep -q "$INSTALL_DIR"; then
echo "${YELLOW}Warning: $INSTALL_DIR is not in your PATH.${NC}"
echo "Please add the following line to your shell profile (~/.bashrc, ~/.zshrc, etc.):"
echo "export PATH=\"\$PATH:$INSTALL_DIR\""
fi
fi
echo "==> Installing to $INSTALL_DIR..."
mv "$BINARY_NAME" "$INSTALL_DIR/"
chmod +x "$INSTALL_DIR/$BINARY_NAME"
echo "${GREEN}==> Installation complete!${NC}"
echo "You can now run: $BINARY_NAME"