create-debs.sh 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/env bash
  2. # create-debs.sh — build the smartbotic-vectorapi + -webui .deb packages
  3. set -euo pipefail
  4. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  5. SOURCE_DIR="${SOURCE_DIR:-$(cd "$SCRIPT_DIR/../.." && pwd)}"
  6. BUILD_DIR="${BUILD_DIR:-$SOURCE_DIR/build}"
  7. OUTPUT_DIR="${OUTPUT_DIR:-$SOURCE_DIR/dist}"
  8. BUILD_DEB_REVISION="${BUILD_DEB_REVISION:-1}"
  9. TEMPLATE_DIR="$SCRIPT_DIR/templates"
  10. SCRIPTS_DIR="$SCRIPT_DIR/scripts"
  11. SYSTEMD_DIR="$SCRIPT_DIR/systemd"
  12. CONFIG_DIR="$SOURCE_DIR/config"
  13. API_DIR="$SOURCE_DIR/api"
  14. WEBUI_DIST="${WEBUI_DIST:-$BUILD_DIR/webui/dist}"
  15. VERSION="$(cat "$SOURCE_DIR/VERSION")"
  16. DEB_VERSION="${VERSION}-${BUILD_DEB_REVISION}"
  17. echo "=== smartbotic-vectorapi deb builder ==="
  18. echo "VERSION=$VERSION DEB_VERSION=$DEB_VERSION"
  19. echo "BUILD_DIR=$BUILD_DIR OUTPUT_DIR=$OUTPUT_DIR WEBUI_DIST=$WEBUI_DIST"
  20. mkdir -p "$OUTPUT_DIR"
  21. calc_installed_size() {
  22. local staging_dir="$1" total=0
  23. for d in "$staging_dir"/*/; do
  24. [ "$(basename "$d")" = "DEBIAN" ] && continue
  25. total=$(( total + $(du -sk "$d" | awk '{print $1}') ))
  26. done
  27. echo "$total"
  28. }
  29. build_deb() {
  30. local pkg_name="$1" staging_dir="$2" arch="$3"
  31. local installed_size; installed_size="$(calc_installed_size "$staging_dir")"
  32. sed -i -e "s/{{VERSION}}/${DEB_VERSION}/g" -e "s/{{INSTALLED_SIZE}}/${installed_size}/g" "$staging_dir/DEBIAN/control"
  33. find "$staging_dir" -type d -exec chmod 0755 {} +
  34. find "$staging_dir/DEBIAN" -type f -exec chmod 0644 {} +
  35. for f in postinst prerm postrm preinst; do
  36. [ -f "$staging_dir/DEBIAN/$f" ] && chmod 0755 "$staging_dir/DEBIAN/$f"
  37. done
  38. local deb_file="${OUTPUT_DIR}/${pkg_name}_${DEB_VERSION}_${arch}.deb"
  39. dpkg-deb --build --root-owner-group "$staging_dir" "$deb_file"
  40. echo " -> $deb_file"
  41. }
  42. # ---- Package 1: smartbotic-vectorapi (server) ----
  43. echo "--- smartbotic-vectorapi ---"
  44. PKG1="$(mktemp -d)"; trap 'rm -rf "$PKG1"' EXIT
  45. mkdir -p "$PKG1/DEBIAN" "$PKG1/usr/bin" "$PKG1/etc/smartbotic-vectorapi" \
  46. "$PKG1/lib/systemd/system" "$PKG1/usr/share/smartbotic-vectorapi"
  47. [ -f "$BUILD_DIR/src/smartbotic-vectorapi" ] || { echo "ERROR: binary not found at $BUILD_DIR/src/smartbotic-vectorapi" >&2; exit 1; }
  48. cp "$BUILD_DIR/src/smartbotic-vectorapi" "$PKG1/usr/bin/smartbotic-vectorapi"
  49. chmod 0755 "$PKG1/usr/bin/smartbotic-vectorapi"
  50. cp "$CONFIG_DIR/config.json" "$PKG1/etc/smartbotic-vectorapi/config.json"
  51. cp "$SYSTEMD_DIR/smartbotic-vectorapi.service" "$PKG1/lib/systemd/system/"
  52. cp "$API_DIR/openapi.json" "$API_DIR/llms.txt" "$PKG1/usr/share/smartbotic-vectorapi/"
  53. mkdir -p "$PKG1/usr/share/smartbotic-vectorapi/docs"
  54. cp -a "$API_DIR/docs/." "$PKG1/usr/share/smartbotic-vectorapi/docs/"
  55. cp "$TEMPLATE_DIR/control.server" "$PKG1/DEBIAN/control"
  56. cp "$SCRIPTS_DIR/server.postinst" "$PKG1/DEBIAN/postinst"
  57. cp "$SCRIPTS_DIR/server.prerm" "$PKG1/DEBIAN/prerm"
  58. cp "$SCRIPTS_DIR/server.postrm" "$PKG1/DEBIAN/postrm"
  59. printf '/etc/smartbotic-vectorapi/config.json\n' > "$PKG1/DEBIAN/conffiles"
  60. build_deb "smartbotic-vectorapi" "$PKG1" "amd64"
  61. # ---- Package 2: smartbotic-vectorapi-webui (static assets) ----
  62. echo "--- smartbotic-vectorapi-webui ---"
  63. PKG2="$(mktemp -d)"; trap 'rm -rf "$PKG1" "$PKG2"' EXIT
  64. mkdir -p "$PKG2/DEBIAN" "$PKG2/usr/share/smartbotic-vectorapi/webui"
  65. if [ -d "$WEBUI_DIST" ] && [ -n "$(ls -A "$WEBUI_DIST" 2>/dev/null)" ]; then
  66. cp -a "$WEBUI_DIST"/. "$PKG2/usr/share/smartbotic-vectorapi/webui/"
  67. else
  68. echo "ERROR: webui dist not found at $WEBUI_DIST (build with -DBUILD_WEBUI=ON)" >&2; exit 1
  69. fi
  70. cp "$TEMPLATE_DIR/control.webui" "$PKG2/DEBIAN/control"
  71. build_deb "smartbotic-vectorapi-webui" "$PKG2" "all"
  72. echo "=== Done. Packages in $OUTPUT_DIR ==="
  73. ls -lh "$OUTPUT_DIR"/*.deb