Skip to content

Commit ce5813d

Browse files
committed
feat: add script to build from source and support binary path with install.sh
1 parent e77731d commit ce5813d

File tree

2 files changed

+119
-3
lines changed

2 files changed

+119
-3
lines changed

scripts/build-from-source.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
#
3+
# Hypeman Build from Source Script
4+
#
5+
# Usage:
6+
# ./scripts/build-from-source.sh
7+
#
8+
# Options (via environment variables:
9+
# OUTPUT_DIR - Full path of directory to place built binaries (optional, default: $(pwd)/bin)
10+
#
11+
12+
set -e
13+
14+
# Default values
15+
BINARY_NAME="hypeman-api"
16+
17+
# Colors for output (true color)
18+
RED='\033[38;2;255;110;110m'
19+
GREEN='\033[38;2;92;190;83m'
20+
YELLOW='\033[0;33m'
21+
PURPLE='\033[38;2;172;134;249m'
22+
NC='\033[0m' # No Color
23+
24+
info() { echo -e "${GREEN}[INFO]${NC} $1"; }
25+
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
26+
error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; }
27+
28+
# =============================================================================
29+
# Pre-flight checks - verify all requirements before doing anything
30+
# =============================================================================
31+
32+
# Check for required commands
33+
command -v go >/dev/null 2>&1 || error "go is required but not installed"
34+
command -v make >/dev/null 2>&1 || error "make is required but not installed"
35+
36+
# =============================================================================
37+
# Setup directories
38+
# =============================================================================
39+
40+
# Get the directory where this script is located
41+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
42+
SOURCE_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
43+
44+
if [ -z "$OUTPUT_DIR" ]; then
45+
OUTPUT_DIR=${SOURCE_DIR}/bin
46+
fi
47+
48+
# Create output directory if it doesn't exist
49+
mkdir -p "$OUTPUT_DIR"
50+
51+
BUILD_LOG="${OUTPUT_DIR}/build.log"
52+
53+
# =============================================================================
54+
# Build from source
55+
# =============================================================================
56+
57+
info "Building from source (${SOURCE_DIR})..."
58+
59+
info "Building binaries (this may take a few minutes)..."
60+
cd "${SOURCE_DIR}"
61+
62+
# Build main binary (includes dependencies) - capture output, show on error
63+
if ! make build >> "$BUILD_LOG" 2>&1; then
64+
echo ""
65+
echo -e "${RED}Build failed. Full build log:${NC}"
66+
cat "$BUILD_LOG"
67+
error "Build failed"
68+
fi
69+
cp "bin/hypeman" "${OUTPUT_DIR}/${BINARY_NAME}"
70+
71+
# Build hypeman-token (not included in make build)
72+
if ! go build -o "${OUTPUT_DIR}/hypeman-token" ./cmd/gen-jwt >> "$BUILD_LOG" 2>&1; then
73+
echo ""
74+
echo -e "${RED}Build failed. Full build log:${NC}"
75+
cat "$BUILD_LOG"
76+
error "Failed to build hypeman-token"
77+
fi
78+
79+
# Copy .env.example for config template
80+
cp ".env.example" "${OUTPUT_DIR}/.env.example"
81+
82+
info "Build complete"
83+
info "Binaries are available in: ${OUTPUT_DIR}"

scripts/install.sh

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# VERSION - Install specific API version (default: latest)
1010
# CLI_VERSION - Install specific CLI version (default: latest)
1111
# BRANCH - Build from source using this branch (for development/testing)
12+
# BINARY_DIR - Use binaries from this directory instead of building/downloading
1213
# INSTALL_DIR - Binary installation directory (default: /opt/hypeman/bin)
1314
# DATA_DIR - Data directory (default: /var/lib/hypeman)
1415
# CONFIG_DIR - Config directory (default: /etc/hypeman)
@@ -99,13 +100,30 @@ command -v systemctl >/dev/null 2>&1 || error "systemctl is required but not ins
99100
command -v setcap >/dev/null 2>&1 || error "setcap is required but not installed (install libcap2-bin)"
100101
command -v openssl >/dev/null 2>&1 || error "openssl is required but not installed"
101102

103+
# Count how many of BRANCH, VERSION, BINARY_DIR are set
104+
count=0
105+
[ -n "$BRANCH" ] && ((count++))
106+
[ -n "$VERSION" ] && ((count++))
107+
[ -n "$BINARY_DIR" ] && ((count++))
108+
109+
if [ "$count" -gt 1 ]; then
110+
error "BRANCH, VERSION, and BINARY_DIR are mutually exclusive"
111+
fi
112+
102113
# Additional checks for build-from-source mode
103114
if [ -n "$BRANCH" ]; then
104115
command -v git >/dev/null 2>&1 || error "git is required for BRANCH mode but not installed"
105116
command -v go >/dev/null 2>&1 || error "go is required for BRANCH mode but not installed"
106117
command -v make >/dev/null 2>&1 || error "make is required for BRANCH mode but not installed"
107118
fi
108119

120+
# Additional checks for BINARY_DIR mode
121+
if [ -n "$BINARY_DIR" ]; then
122+
if [ ! -d "$BINARY_DIR" ]; then
123+
error "BINARY_DIR does not exist: ${BINARY_DIR}. Are you sure you provided the correct path?"
124+
fi
125+
fi
126+
109127
# Detect OS
110128
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
111129
if [ "$OS" != "linux" ]; then
@@ -184,10 +202,25 @@ TMP_DIR=$(mktemp -d)
184202
trap "rm -rf $TMP_DIR" EXIT
185203

186204
# =============================================================================
187-
# Get binaries (either download release or build from source)
205+
# Get binaries (either use BINARY_DIR, download release, or build from source)
188206
# =============================================================================
189207

190-
if [ -n "$BRANCH" ]; then
208+
if [ -n "$BINARY_DIR" ]; then
209+
# Use binaries from specified directory
210+
info "Using binaries from ${BINARY_DIR}..."
211+
212+
# Copy binaries to TMP_DIR
213+
info "Copying binaries from ${BINARY_DIR}..."
214+
cp "${BINARY_DIR}/${BINARY_NAME}" "${TMP_DIR}/${BINARY_NAME}"
215+
cp "${BINARY_DIR}/hypeman-token" "${TMP_DIR}/hypeman-token"
216+
cp "${BINARY_DIR}/.env.example" "${TMP_DIR}/.env.example"
217+
218+
# Make binaries executable
219+
chmod +x "${TMP_DIR}/${BINARY_NAME}"
220+
chmod +x "${TMP_DIR}/hypeman-token"
221+
222+
VERSION="custom (from binary)"
223+
elif [ -n "$BRANCH" ]; then
191224
# Build from source mode
192225
info "Building from source (branch: $BRANCH)..."
193226

@@ -405,7 +438,7 @@ $SUDO systemctl start "$SERVICE_NAME"
405438

406439
CLI_REPO="kernel/hypeman-cli"
407440

408-
if [ -z "$CLI_VERSION" ]; then
441+
if [ -z "$CLI_VERSION" ] || [ "$CLI_VERSION" == "latest" ]; then
409442
info "Fetching latest CLI version with available artifacts..."
410443
CLI_VERSION=$(find_release_with_artifact "$CLI_REPO" "hypeman" "$OS" "$ARCH")
411444
if [ -z "$CLI_VERSION" ]; then

0 commit comments

Comments
 (0)