diff --git a/src/build_dpkg.sh b/src/build_dpkg.sh index f35fc1f4..95b25a0c 100755 --- a/src/build_dpkg.sh +++ b/src/build_dpkg.sh @@ -226,12 +226,13 @@ EOF popd || exit #################################################### -# Bundle the API into src/bin -echo "Fetching lqos_api (api.zip) ..." -curl -fsSL -o /tmp/lqos_api.zip "https://download.libreqos.com/api.zip" -unzip -o /tmp/lqos_api.zip -d "$LQOS_DIR/bin" -chmod +x "$LQOS_DIR/bin/lqos_api" || true -rm -f /tmp/lqos_api.zip +# Bundle the API into the package +echo "Fetching lqos_api via update_api.sh ..." +bash ./update_api.sh --bin-dir "$LQOS_DIR/bin" --no-restart +if [[ ! -x "$LQOS_DIR/bin/lqos_api" ]]; then + echo "Error: lqos_api was not installed into the package at $LQOS_DIR/bin/lqos_api" + exit 1 +fi #################################################### # Assemble the package diff --git a/src/update_api.sh b/src/update_api.sh index f71a1793..06a073b0 100755 --- a/src/update_api.sh +++ b/src/update_api.sh @@ -2,15 +2,58 @@ set -euo pipefail -# Fetch and install the lqos_api binary into src/bin +# Fetch and install the lqos_api binary into src/bin (or an alternate destination) # - Downloads https://download.libreqos.com/api2.zip # - Extracts the single file lqos_api -# - Places it into ./bin alongside other binaries +# - Places it into ./bin alongside other binaries (override with --bin-dir) SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -BIN_DIR="$SCRIPT_DIR/bin" TMP_ZIP="$(mktemp /tmp/lqos_api.XXXXXX.zip)" +BIN_DIR="${LQOS_API_BIN_DIR:-$SCRIPT_DIR/bin}" +RESTART_SERVICE="${LQOS_API_RESTART_SERVICE:-1}" + +usage() { + cat < "$BIN_DIR/lqos_api.new" chmod +x "$BIN_DIR/lqos_api.new" mv "$BIN_DIR/lqos_api.new" "$BIN_DIR/lqos_api" -# Function copied from build_rust.sh -service_exists() { - local n=$1 - if [[ $(systemctl list-units --all -t service --full --no-legend "$n.service" | sed 's/^\s*//g' | cut -f1 -d' ') == $n.service ]]; then - return 0 - else - return 1 - fi -} +if [[ "$RESTART_SERVICE" == "1" ]]; then + # Function copied from build_rust.sh + service_exists() { + local n=$1 + if [[ $(systemctl list-units --all -t service --full --no-legend "$n.service" | sed 's/^\s*//g' | cut -f1 -d' ') == $n.service ]]; then + return 0 + else + return 1 + fi + } -echo "Restart lqos_api service (if present)" -if service_exists lqos_api; then - echo "lqos_api is running as a service. Restarting it. You may need to enter your sudo password." - sudo systemctl restart lqos_api + echo "Restart lqos_api service (if present)" + if service_exists lqos_api; then + echo "lqos_api is running as a service. Restarting it. You may need to enter your sudo password." + sudo systemctl restart lqos_api + else + echo "lqos_api service not found; skipping restart." + fi else - echo "lqos_api service not found; skipping restart." + echo "Skipping lqos_api service restart." fi rm -f "$TMP_ZIP"