-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
107 lines (90 loc) · 2.67 KB
/
install.sh
File metadata and controls
107 lines (90 loc) · 2.67 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/sh
# DeployHQ CLI installer
# Usage: curl -fsSL https://deployhq.com/install/cli | sh
set -e
REPO="deployhq/deployhq-cli"
BINARY="dhq"
# Detect OS and architecture
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$ARCH" in
x86_64|amd64) ARCH="amd64" ;;
arm64|aarch64) ARCH="arm64" ;;
*) echo "Unsupported architecture: $ARCH"; exit 1 ;;
esac
case "$OS" in
linux|darwin) ;;
mingw*|msys*|cygwin*) OS="windows" ;;
*) echo "Unsupported OS: $OS"; exit 1 ;;
esac
# Determine install directory
# Priority: explicit env var > existing binary location > writable defaults
if [ -n "$INSTALL_DIR" ]; then
# Explicit override via env var
:
elif EXISTING=$(command -v "$BINARY" 2>/dev/null); then
# Update in place — install where the current binary lives
INSTALL_DIR=$(dirname "$EXISTING")
elif [ -w "/usr/local/bin" ]; then
INSTALL_DIR="/usr/local/bin"
elif [ -d "$HOME/.local/bin" ] || mkdir -p "$HOME/.local/bin" 2>/dev/null; then
INSTALL_DIR="$HOME/.local/bin"
else
INSTALL_DIR="/usr/local/bin"
fi
# Get latest version
echo "Fetching latest version..."
VERSION=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name"' | sed -E 's/.*"v?([^"]+)".*/\1/')
if [ -z "$VERSION" ]; then
echo "Error: could not determine latest version"
exit 1
fi
echo "Installing dhq v$VERSION ($OS/$ARCH)..."
# Download
EXT="tar.gz"
if [ "$OS" = "windows" ]; then
EXT="zip"
fi
URL="https://github.com/$REPO/releases/download/v$VERSION/${BINARY}_${VERSION}_${OS}_${ARCH}.${EXT}"
TMP=$(mktemp -d)
trap 'rm -rf "$TMP"' EXIT
echo "Downloading $URL..."
curl -fsSL "$URL" -o "$TMP/archive.$EXT"
# Extract
cd "$TMP"
if [ "$EXT" = "zip" ]; then
unzip -q "archive.$EXT"
else
tar xzf "archive.$EXT"
fi
# Install
if [ -w "$INSTALL_DIR" ]; then
mv "$BINARY" "$INSTALL_DIR/$BINARY"
else
echo "Installing to $INSTALL_DIR (requires sudo)..."
sudo mv "$BINARY" "$INSTALL_DIR/$BINARY"
fi
chmod +x "$INSTALL_DIR/$BINARY"
echo ""
echo "dhq v$VERSION installed to $INSTALL_DIR/$BINARY"
# Check if install dir is in PATH
case ":$PATH:" in
*":$INSTALL_DIR:"*) ;;
*)
echo ""
echo "NOTE: $INSTALL_DIR is not in your PATH."
echo "Add it by running:"
echo ""
if [ -f "$HOME/.zshrc" ]; then
echo " echo 'export PATH=\"$INSTALL_DIR:\$PATH\"' >> ~/.zshrc && source ~/.zshrc"
else
echo " echo 'export PATH=\"$INSTALL_DIR:\$PATH\"' >> ~/.bashrc && source ~/.bashrc"
fi
echo ""
;;
esac
echo ""
echo "Get started:"
echo " dhq hello (guided onboarding)"
echo " dhq auth login (or login directly)"
echo " dhq --help"