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)
@@ -25,6 +26,8 @@ CONFIG_FILE="${CONFIG_DIR}/config"
2526SYSTEMD_DIR=" /etc/systemd/system"
2627SERVICE_NAME=" hypeman"
2728SERVICE_USER=" hypeman"
29+ BUILD_SCRIPT=" build-from-source.sh"
30+
2831
2932# Colors for output (true color)
3033RED=' \033[38;2;255;110;110m'
@@ -99,13 +102,34 @@ command -v systemctl >/dev/null 2>&1 || error "systemctl is required but not ins
99102command -v setcap > /dev/null 2>&1 || error " setcap is required but not installed (install libcap2-bin)"
100103command -v openssl > /dev/null 2>&1 || error " openssl is required but not installed"
101104
105+ # Branch and binary_dir are mutually exclusive
106+ if [ -n " $BRANCH " ] && [ -n " $BINARY_DIR " ]; then
107+ error " BRANCH and BINARY_DIR are mutually exclusive"
108+ fi
109+
102110# Additional checks for build-from-source mode
103111if [ -n " $BRANCH " ]; then
104112 command -v git > /dev/null 2>&1 || error " git is required for BRANCH mode but not installed"
105113 command -v go > /dev/null 2>&1 || error " go is required for BRANCH mode but not installed"
106114 command -v make > /dev/null 2>&1 || error " make is required for BRANCH mode but not installed"
107115fi
108116
117+ # Additional checks for BINARY_DIR mode
118+ if [ -n " $BINARY_DIR " ]; then
119+ if [ ! -d " $BINARY_DIR " ]; then
120+ error " BINARY_DIR does not exist: ${BINARY_DIR} "
121+ fi
122+ if [ ! -f " ${BINARY_DIR} /${BINARY_NAME} " ]; then
123+ error " Required binary not found: ${BINARY_DIR} /${BINARY_NAME} "
124+ fi
125+ if [ ! -f " ${BINARY_DIR} /hypeman-token" ]; then
126+ error " Required binary not found: ${BINARY_DIR} /hypeman-token"
127+ fi
128+ if [ ! -f " ${BINARY_DIR} /.env.example" ]; then
129+ error " Required file not found: ${BINARY_DIR} /.env.example"
130+ fi
131+ fi
132+
109133# Detect OS
110134OS=$( uname -s | tr ' [:upper:]' ' [:lower:]' )
111135if [ " $OS " != " linux" ]; then
@@ -184,48 +208,34 @@ TMP_DIR=$(mktemp -d)
184208trap " rm -rf $TMP_DIR " EXIT
185209
186210# =============================================================================
187- # Get binaries (either download release or build from source)
211+ # Get binaries (either use BINARY_DIR, download release, or build from source)
188212# =============================================================================
189213
190- if [ -n " $BRANCH " ]; then
214+ if [ -n " $BINARY_DIR " ]; then
215+ # Use binaries from specified directory
216+ info " Using binaries from ${BINARY_DIR} ..."
217+
218+ # Copy binaries to TMP_DIR
219+ info " Copying binaries from ${BINARY_DIR} ..."
220+ cp " ${BINARY_DIR} /${BINARY_NAME} " " ${TMP_DIR} /${BINARY_NAME} "
221+ cp " ${BINARY_DIR} /hypeman-token" " ${TMP_DIR} /hypeman-token"
222+ cp " ${BINARY_DIR} /.env.example" " ${TMP_DIR} /.env.example"
223+
224+ # Make binaries executable
225+ chmod +x " ${TMP_DIR} /${BINARY_NAME} "
226+ chmod +x " ${TMP_DIR} /hypeman-token"
227+
228+ VERSION=" custom (from ${BINARY_DIR} )"
229+ elif [ -n " $BRANCH " ]; then
191230 # Build from source mode
192231 info " Building from source (branch: $BRANCH )..."
193232
194- BUILD_DIR=" ${TMP_DIR} /hypeman"
195- BUILD_LOG=" ${TMP_DIR} /build.log"
196-
197- # Clone repo (quiet)
198- if ! git clone --branch " $BRANCH " --depth 1 -q " https://github.com/${REPO} .git" " $BUILD_DIR " 2>&1 | tee -a " $BUILD_LOG " ; then
199- error " Failed to clone repository. Build log:\n$( cat " $BUILD_LOG " ) "
200- fi
201-
202- info " Building binaries (this may take a few minutes)..."
203- cd " $BUILD_DIR "
204-
205- # Build main binary (includes dependencies) - capture output, show on error
206- if ! make build >> " $BUILD_LOG " 2>&1 ; then
207- echo " "
208- echo -e " ${RED} Build failed. Full build log:${NC} "
209- cat " $BUILD_LOG "
210- error " Build failed"
211- fi
212- cp " bin/hypeman" " ${TMP_DIR} /${BINARY_NAME} "
213-
214- # Build hypeman-token (not included in make build)
215- if ! go build -o " ${TMP_DIR} /hypeman-token" ./cmd/gen-jwt >> " $BUILD_LOG " 2>&1 ; then
216- echo " "
217- echo -e " ${RED} Build failed. Full build log:${NC} "
218- cat " $BUILD_LOG "
219- error " Failed to build hypeman-token"
233+ # Run build script
234+ if ! " OUTPUT_DIR=$TMP_DIR $BUILD_SCRIPT " ; then
235+ error " Build from source failed"
220236 fi
221237
222- # Copy .env.example for config template
223- cp " .env.example" " ${TMP_DIR} /.env.example"
224-
225238 VERSION=" $BRANCH (source)"
226- cd - > /dev/null
227-
228- info " Build complete"
229239else
230240 # Download release mode
231241 if [ -z " $VERSION " ]; then
0 commit comments