Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·149 lines (125 loc) · 3.73 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·149 lines (125 loc) · 3.73 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env bash
set -euo pipefail
REPO="andrespd99/fireauth"
BINARY="fireauth"
INSTALL_DIR="/usr/local/bin"
API_BASE="https://api.github.com/repos/${REPO}"
# --- Parse arguments ---
TARGET_VERSION=""
usage() {
cat <<EOF
Usage: $0 [OPTIONS]
Install fireauth from GitHub releases.
Options:
--version <ver> Install a specific version (e.g. 0.3.0, 0.3.0-alpha.1)
If omitted, installs the latest stable release.
--help Show this help message.
Examples:
$0 # Install latest stable
$0 --version 0.3.0-stable # Install a specific stable release
$0 --version 0.3.0-alpha.1 # Install a pre-release
EOF
}
while [ $# -gt 0 ]; do
case "$1" in
--version)
TARGET_VERSION="$2"
shift 2
;;
--help|-h)
usage
exit 0
;;
*)
echo "Error: unknown option: $1" >&2
usage >&2
exit 1
;;
esac
done
# Detect OS and architecture.
OS="$(uname -s | tr '[:upper:]' '[:lower:]')"
ARCH="$(uname -m)"
case "$ARCH" in
x86_64) ARCH="amd64" ;;
aarch64) ARCH="arm64" ;;
arm64) ARCH="arm64" ;;
*)
echo "Error: unsupported architecture: $ARCH" >&2
exit 1
;;
esac
case "$OS" in
darwin|linux) ;;
*)
echo "Error: unsupported OS: $OS" >&2
exit 1
;;
esac
echo "Detected: ${OS}/${ARCH}"
ARCHIVE="${BINARY}_${OS}_${ARCH}.tar.gz"
# --- Resolve release ---
if [ -n "$TARGET_VERSION" ]; then
# Strip leading 'v' if user included it.
TARGET_VERSION="${TARGET_VERSION#v}"
TAG="v${TARGET_VERSION}"
echo "Fetching release ${TAG}..."
ASSET_URL=$(curl -fsSL \
-H "Accept: application/vnd.github+json" \
"${API_BASE}/releases/tags/${TAG}" \
| grep -o "\"browser_download_url\": \"https://[^\"]*${ARCHIVE}\"" \
| head -1 \
| sed -E 's/.*"browser_download_url": "(.*)"/\1/')
if [ -z "$ASSET_URL" ]; then
echo "Error: could not find asset '${ARCHIVE}' in release ${TAG}" >&2
echo "Available assets:" >&2
curl -fsSL "${API_BASE}/releases/tags/${TAG}" \
| grep '"name"' | sed -E 's/.*"name": "(.*)".*/ \1/' >&2
exit 1
fi
else
# Find the latest stable release (tag matching v*.*.*-stable).
echo "Fetching latest stable release..."
RELEASES_JSON=$(curl -fsSL \
-H "Accept: application/vnd.github+json" \
"${API_BASE}/releases?per_page=30")
TAG=$(echo "$RELEASES_JSON" \
| grep -E '"tag_name": "v[0-9]+\.[0-9]+\.[0-9]+-stable"' \
| head -1 \
| sed -E 's/.*"tag_name": "([^"]+)".*/\1/')
if [ -z "$TAG" ]; then
echo "Error: no stable release found (tag matching v*.*.*-stable)." >&2
echo "Available releases:" >&2
echo "$RELEASES_JSON" | grep '"tag_name"' | sed -E 's/.*"tag_name": "(.*)".*/ \1/' >&2
echo "" >&2
echo "You can install a specific version with: $0 --version <version>" >&2
exit 1
fi
echo "Latest stable version: ${TAG}"
ASSET_URL=$(echo "$RELEASES_JSON" \
| grep -o "\"browser_download_url\": \"https://[^\"]*${ARCHIVE}\"" \
| head -1 \
| sed -E 's/.*"browser_download_url": "(.*)"/\1/')
if [ -z "$ASSET_URL" ]; then
echo "Error: could not find asset '${ARCHIVE}' in release ${TAG}" >&2
exit 1
fi
fi
# --- Download ---
echo "Downloading ${ARCHIVE}..."
TMP_DIR=$(mktemp -d)
trap 'rm -rf "$TMP_DIR"' EXIT
curl -fsSL -o "${TMP_DIR}/${ARCHIVE}" "$ASSET_URL"
tar -xzf "${TMP_DIR}/${ARCHIVE}" -C "$TMP_DIR"
# --- Install ---
if [ -w "$INSTALL_DIR" ]; then
mv "${TMP_DIR}/${BINARY}" "${INSTALL_DIR}/${BINARY}"
else
echo "Installing to ${INSTALL_DIR} (requires sudo)..."
sudo mv "${TMP_DIR}/${BINARY}" "${INSTALL_DIR}/${BINARY}"
fi
chmod +x "${INSTALL_DIR}/${BINARY}"
echo ""
echo "fireauth ${TAG} installed to ${INSTALL_DIR}/${BINARY}"
echo ""
echo "Next step: run 'fireauth init' to set up your Firebase credentials."