| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- #!/usr/bin/env bash
- # create-debs.sh — build the smartbotic-vectorapi + -webui .deb packages
- set -euo pipefail
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
- SOURCE_DIR="${SOURCE_DIR:-$(cd "$SCRIPT_DIR/../.." && pwd)}"
- BUILD_DIR="${BUILD_DIR:-$SOURCE_DIR/build}"
- OUTPUT_DIR="${OUTPUT_DIR:-$SOURCE_DIR/dist}"
- BUILD_DEB_REVISION="${BUILD_DEB_REVISION:-1}"
- TEMPLATE_DIR="$SCRIPT_DIR/templates"
- SCRIPTS_DIR="$SCRIPT_DIR/scripts"
- SYSTEMD_DIR="$SCRIPT_DIR/systemd"
- CONFIG_DIR="$SOURCE_DIR/config"
- API_DIR="$SOURCE_DIR/api"
- WEBUI_DIST="${WEBUI_DIST:-$BUILD_DIR/webui/dist}"
- VERSION="$(cat "$SOURCE_DIR/VERSION")"
- DEB_VERSION="${VERSION}-${BUILD_DEB_REVISION}"
- echo "=== smartbotic-vectorapi deb builder ==="
- echo "VERSION=$VERSION DEB_VERSION=$DEB_VERSION"
- echo "BUILD_DIR=$BUILD_DIR OUTPUT_DIR=$OUTPUT_DIR WEBUI_DIST=$WEBUI_DIST"
- mkdir -p "$OUTPUT_DIR"
- calc_installed_size() {
- local staging_dir="$1" total=0
- for d in "$staging_dir"/*/; do
- [ "$(basename "$d")" = "DEBIAN" ] && continue
- total=$(( total + $(du -sk "$d" | awk '{print $1}') ))
- done
- echo "$total"
- }
- build_deb() {
- local pkg_name="$1" staging_dir="$2" arch="$3"
- local installed_size; installed_size="$(calc_installed_size "$staging_dir")"
- sed -i -e "s/{{VERSION}}/${DEB_VERSION}/g" -e "s/{{INSTALLED_SIZE}}/${installed_size}/g" "$staging_dir/DEBIAN/control"
- find "$staging_dir" -type d -exec chmod 0755 {} +
- find "$staging_dir/DEBIAN" -type f -exec chmod 0644 {} +
- for f in postinst prerm postrm preinst; do
- [ -f "$staging_dir/DEBIAN/$f" ] && chmod 0755 "$staging_dir/DEBIAN/$f"
- done
- local deb_file="${OUTPUT_DIR}/${pkg_name}_${DEB_VERSION}_${arch}.deb"
- dpkg-deb --build --root-owner-group "$staging_dir" "$deb_file"
- echo " -> $deb_file"
- }
- # ---- Package 1: smartbotic-vectorapi (server) ----
- echo "--- smartbotic-vectorapi ---"
- PKG1="$(mktemp -d)"; trap 'rm -rf "$PKG1"' EXIT
- mkdir -p "$PKG1/DEBIAN" "$PKG1/usr/bin" "$PKG1/etc/smartbotic-vectorapi" \
- "$PKG1/lib/systemd/system" "$PKG1/usr/share/smartbotic-vectorapi"
- [ -f "$BUILD_DIR/src/smartbotic-vectorapi" ] || { echo "ERROR: binary not found at $BUILD_DIR/src/smartbotic-vectorapi" >&2; exit 1; }
- cp "$BUILD_DIR/src/smartbotic-vectorapi" "$PKG1/usr/bin/smartbotic-vectorapi"
- chmod 0755 "$PKG1/usr/bin/smartbotic-vectorapi"
- cp "$CONFIG_DIR/config.json" "$PKG1/etc/smartbotic-vectorapi/config.json"
- cp "$SYSTEMD_DIR/smartbotic-vectorapi.service" "$PKG1/lib/systemd/system/"
- cp "$API_DIR/openapi.json" "$API_DIR/llms.txt" "$PKG1/usr/share/smartbotic-vectorapi/"
- mkdir -p "$PKG1/usr/share/smartbotic-vectorapi/docs"
- cp -a "$API_DIR/docs/." "$PKG1/usr/share/smartbotic-vectorapi/docs/"
- cp "$TEMPLATE_DIR/control.server" "$PKG1/DEBIAN/control"
- cp "$SCRIPTS_DIR/server.postinst" "$PKG1/DEBIAN/postinst"
- cp "$SCRIPTS_DIR/server.prerm" "$PKG1/DEBIAN/prerm"
- cp "$SCRIPTS_DIR/server.postrm" "$PKG1/DEBIAN/postrm"
- printf '/etc/smartbotic-vectorapi/config.json\n' > "$PKG1/DEBIAN/conffiles"
- build_deb "smartbotic-vectorapi" "$PKG1" "amd64"
- # ---- Package 2: smartbotic-vectorapi-webui (static assets) ----
- echo "--- smartbotic-vectorapi-webui ---"
- PKG2="$(mktemp -d)"; trap 'rm -rf "$PKG1" "$PKG2"' EXIT
- mkdir -p "$PKG2/DEBIAN" "$PKG2/usr/share/smartbotic-vectorapi/webui"
- if [ -d "$WEBUI_DIST" ] && [ -n "$(ls -A "$WEBUI_DIST" 2>/dev/null)" ]; then
- cp -a "$WEBUI_DIST"/. "$PKG2/usr/share/smartbotic-vectorapi/webui/"
- else
- echo "ERROR: webui dist not found at $WEBUI_DIST (build with -DBUILD_WEBUI=ON)" >&2; exit 1
- fi
- cp "$TEMPLATE_DIR/control.webui" "$PKG2/DEBIAN/control"
- build_deb "smartbotic-vectorapi-webui" "$PKG2" "all"
- echo "=== Done. Packages in $OUTPUT_DIR ==="
- ls -lh "$OUTPUT_DIR"/*.deb
|