Skip to content

Commit d6b5e93

Browse files
committed
feat: add install script and update release configuration
Adds install.sh script for easy installation of the latest release binary via curl/wget on Linux (amd64/arm64). The script detects the platform, downloads the appropriate release asset from GitHub, extracts the 'reflow' binary, and installs it to /usr/local/bin using sudo. Updates README.md to include the install script usage instructions and replaces the dynamic Go version badge with a static one. Updates .goreleaser.yml archive and release name templates to use {{.Tag}} instead of {{.Version}} to include the 'v' prefix in artifact names (e.g., reflow_v0.1.0_linux_amd64.tar.gz).
1 parent 128e739 commit d6b5e93

File tree

3 files changed

+164
-3
lines changed

3 files changed

+164
-3
lines changed

.goreleaser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ builds:
2222

2323
archives:
2424
- id: reflow-archives
25-
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
25+
name_template: "{{ .ProjectName }}_{{ .Tag }}_{{ .Os }}_{{ .Arch }}"
2626
format: tar.gz
2727
files:
2828
- README.md

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ It automatically builds your Next.js app within Docker (no need for a Dockerfile
4242
1. **Install Go:** Make sure you have Go installed (version 1.18+ recommended).
4343
2. **Clone the repository:**
4444
```bash
45-
git clone [https://github.com/RevereInc/reflow.git](https://github.com/RevereInc/reflow.git)
45+
git clone https://github.com/RevereInc/reflow.git
4646
cd reflow
4747
```
4848
3. **Build the binary:**
@@ -55,6 +55,16 @@ It automatically builds your Next.js app within Docker (no need for a Dockerfile
5555
sudo mv reflow /usr/local/bin/
5656
```
5757
58+
### Install Script (Linux)
59+
60+
You can install the latest version of Reflow using the following command. It automatically detects your architecture (amd64/arm64), downloads the correct release binary, and installs it to `/usr/local/bin`.
61+
62+
**Note:** This requires `curl` or `wget`, `tar`, and `sudo` privileges to write to `/usr/local/bin`.
63+
64+
```bash
65+
curl -sSL https://raw.githubusercontent.com/RevereInc/reflow/main/install.sh | sudo bash
66+
```
67+
5868
## Getting Started / Usage
5969
6070
1. **Initialize Reflow:**
@@ -158,7 +168,7 @@ jobs:
158168
key: ${{ secrets.SSH_PRIVATE_KEY }}
159169
script: |
160170
cd /path/to/where/t/is || exit 1
161-
./revflow deploy your-project-name ${{ github.sha }}
171+
./reflow deploy your-project-name ${{ github.sha }}
162172
```
163173
164174
* You need to add `SSH_HOST`, `SSH_USERNAME`, and `SSH_PRIVATE_KEY` as secrets in your GitHub repository settings.

install.sh

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#!/bin/sh
2+
# install.sh - Installs the latest release of Reflow (t)
3+
# Usage: curl -sSL https://raw.githubusercontent.com/RevereInc/reflow/main/install.sh | sudo bash
4+
5+
set -e
6+
7+
# --- Configuration ---
8+
REPO="RevereInc/reflow"
9+
BINARY_NAME="reflow"
10+
INSTALL_DIR="/usr/local/bin"
11+
# ---
12+
13+
# --- Helper Functions ---
14+
info() {
15+
printf "[INFO] %s\\n" "$1"
16+
}
17+
18+
error_exit() {
19+
printf "[ERROR] %s\\n" "$1" >&2
20+
exit 1
21+
}
22+
23+
# --- Check Prerequisites ---
24+
if ! command -v curl >/dev/null && ! command -v wget >/dev/null; then
25+
error_exit "Please install curl or wget to download the release."
26+
fi
27+
if ! command -v tar >/dev/null; then
28+
error_exit "Please install tar to extract the release."
29+
fi
30+
if ! command -v uname >/dev/null; then
31+
error_exit "Cannot determine OS or architecture (uname not found)."
32+
fi
33+
34+
# --- Detect OS/Arch ---
35+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
36+
ARCH=$(uname -m)
37+
TARGET_ARCH=""
38+
39+
case $ARCH in
40+
x86_64 | amd64)
41+
TARGET_ARCH="amd64"
42+
;;
43+
arm64 | aarch64)
44+
TARGET_ARCH="arm64"
45+
;;
46+
*)
47+
error_exit "Unsupported architecture: $ARCH"
48+
;;
49+
esac
50+
51+
case $OS in
52+
linux)
53+
OS="linux"
54+
;;
55+
*)
56+
error_exit "Unsupported operating system: $OS (This script currently supports Linux only)"
57+
;;
58+
esac
59+
60+
info "Detected OS: $OS, Arch: $TARGET_ARCH"
61+
62+
# --- Fetch Latest Release Info ---
63+
info "Fetching latest release information from GitHub..."
64+
API_URL="https://api.github.com/repos/$REPO/releases/latest"
65+
DOWNLOAD_URL=""
66+
LATEST_VERSION=""
67+
68+
if command -v curl >/dev/null; then
69+
API_RESPONSE=$(curl -sSL --fail "$API_URL") || error_exit "Failed to fetch release info from GitHub API (curl). Check network or repository URL."
70+
else
71+
API_RESPONSE=$(wget -qO- "$API_URL") || error_exit "Failed to fetch release info from GitHub API (wget). Check network or repository URL."
72+
fi
73+
74+
if command -v jq >/dev/null; then
75+
LATEST_VERSION=$(echo "$API_RESPONSE" | jq -r ".tag_name // \"\"")
76+
ASSET_PATTERN="_${OS}_${TARGET_ARCH}.tar.gz"
77+
DOWNLOAD_URL=$(echo "$API_RESPONSE" | jq -r ".assets[] | select(.name | endswith(\"$ASSET_PATTERN\")) | .browser_download_url // \"\"")
78+
else
79+
info "jq not found, attempting less reliable grep/sed fallback..."
80+
LATEST_VERSION=$(echo "$API_RESPONSE" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' | head -n 1)
81+
if [ -z "$LATEST_VERSION" ]; then error_exit "Could not parse latest version tag from GitHub API response."; fi
82+
83+
PROJECT_NAME=$(basename "$REPO") # Should be 'reflow'
84+
EXPECTED_FILENAME="${PROJECT_NAME}_${LATEST_VERSION}_${OS}_${TARGET_ARCH}.tar.gz"
85+
info "Looking for asset: $EXPECTED_FILENAME"
86+
DOWNLOAD_URL=$(echo "$API_RESPONSE" | grep '"browser_download_url":' | grep "$EXPECTED_FILENAME" | sed -E 's/.*"([^"]+)".*/\1/' | head -n 1)
87+
fi
88+
89+
if [ -z "$LATEST_VERSION" ] || [ "$LATEST_VERSION" = "null" ]; then
90+
error_exit "Could not determine latest version tag from GitHub API."
91+
fi
92+
if [ -z "$DOWNLOAD_URL" ] || [ "$DOWNLOAD_URL" = "null" ]; then
93+
error_exit "Could not find suitable release asset URL for $OS/$TARGET_ARCH (Version: $LATEST_VERSION). Please check the releases page: https://github.com/$REPO/releases"
94+
fi
95+
96+
info "Latest version: $LATEST_VERSION"
97+
info "Downloading asset: $DOWNLOAD_URL"
98+
99+
# --- Download and Extract ---
100+
FILENAME=$(basename "$DOWNLOAD_URL")
101+
TMP_DIR=$(mktemp -d -t reflow_install.XXXXXX)
102+
trap 'info "Cleaning up temporary directory: $TMP_DIR"; rm -rf "$TMP_DIR"' EXIT
103+
DOWNLOAD_PATH="$TMP_DIR/$FILENAME"
104+
EXTRACTED_BINARY="$TMP_DIR/$BINARY_NAME"
105+
106+
if command -v curl >/dev/null; then
107+
curl -sSL -o "$DOWNLOAD_PATH" "$DOWNLOAD_URL" || error_exit "Download failed (curl)."
108+
else
109+
wget -q -O "$DOWNLOAD_PATH" "$DOWNLOAD_URL" || error_exit "Download failed (wget)."
110+
fi
111+
info "Downloaded to $DOWNLOAD_PATH"
112+
113+
info "Extracting $BINARY_NAME..."
114+
tar -xzf "$DOWNLOAD_PATH" -C "$TMP_DIR" --strip-components=0 "$BINARY_NAME" || \
115+
tar -xzf "$DOWNLOAD_PATH" -C "$TMP_DIR" --strip-components=1 "$BINARY_NAME" || \
116+
error_exit "Failed to extract $BINARY_NAME from archive. Archive structure might have changed."
117+
118+
if [ ! -f "$EXTRACTED_BINARY" ]; then
119+
error_exit "$BINARY_NAME not found after extraction."
120+
fi
121+
122+
# --- Install ---
123+
info "Making binary executable..."
124+
chmod +x "$EXTRACTED_BINARY"
125+
126+
info "Attempting to install $BINARY_NAME to $INSTALL_DIR..."
127+
if [ ! -d "$INSTALL_DIR" ]; then
128+
info "Creating install directory $INSTALL_DIR (may require sudo)..."
129+
if [ "$(id -u)" -ne 0 ]; then
130+
sudo mkdir -p "$INSTALL_DIR" || error_exit "Failed to create $INSTALL_DIR using sudo."
131+
else
132+
mkdir -p "$INSTALL_DIR" || error_exit "Failed to create $INSTALL_DIR."
133+
fi
134+
fi
135+
136+
if [ "$(id -u)" -ne 0 ]; then
137+
if ! command -v sudo >/dev/null; then
138+
error_exit "sudo command not found, cannot install to $INSTALL_DIR. Please run script with sudo or install manually: mv $EXTRACTED_BINARY $INSTALL_DIR/"
139+
fi
140+
info "Running 'sudo mv' to install..."
141+
sudo mv "$EXTRACTED_BINARY" "$INSTALL_DIR/$BINARY_NAME" || error_exit "Failed to move binary to $INSTALL_DIR using sudo. Check permissions or run script with 'sudo bash'."
142+
else
143+
info "Running 'mv' as root to install..."
144+
mv "$EXTRACTED_BINARY" "$INSTALL_DIR/$BINARY_NAME" || error_exit "Failed to move binary to $INSTALL_DIR."
145+
fi
146+
147+
info ""
148+
info "$BINARY_NAME version $LATEST_VERSION installed successfully to $INSTALL_DIR/$BINARY_NAME"
149+
info "Run '$BINARY_NAME --help' to get started."
150+
151+
exit 0

0 commit comments

Comments
 (0)