#!/usr/bin/env bash set -euo pipefail PKG_NAME="local-installer-agent" ARCH="${ARCH:-amd64}" PUBLISH_DIR="${AGENT_PUBLISH_DIR:-../web-server/uploads/packages/agent}" if [ -z "${BUILD_ROOT:-}" ]; then if [[ "$(pwd -P)" == /mnt/* ]]; then BUILD_ROOT="/tmp/${PKG_NAME}-build" else BUILD_ROOT="build" fi fi next_patch_version() { local latest="" if [ -d "${PUBLISH_DIR}" ]; then latest="$( for package_path in "${PUBLISH_DIR}/${PKG_NAME}_"*"_${ARCH}.deb"; do [ -e "${package_path}" ] || continue package_file="$(basename "${package_path}")" package_version="${package_file#${PKG_NAME}_}" package_version="${package_version%_${ARCH}.deb}" printf '%s\n' "${package_version}" done | sort -V | tail -n 1 )" fi if [ -z "${latest}" ]; then latest="$( sed -nE 's/^Version:[[:space:]]*([^[:space:]]+).*/\1/p' packaging/DEBIAN/control | head -n 1 )" fi if [[ "${latest}" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then printf '%s.%s.%s\n' "${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}" "$((BASH_REMATCH[3] + 1))" return fi printf '0.1.0\n' } VERSION="${VERSION:-$(next_patch_version)}" BUILD_DIR="${BUILD_ROOT}/${PKG_NAME}_${VERSION}_${ARCH}" rm -rf "${BUILD_ROOT}" mkdir -p "${BUILD_DIR}/opt/local-installer-agent" mkdir -p "${BUILD_DIR}/etc/local-installer-agent" mkdir -p "${BUILD_DIR}/etc/systemd/system" mkdir -p "${BUILD_DIR}/DEBIAN" cp -r app "${BUILD_DIR}/opt/local-installer-agent/" cp requirements.txt "${BUILD_DIR}/opt/local-installer-agent/" find "${BUILD_DIR}/opt/local-installer-agent/app" -type d -name "__pycache__" -prune -exec rm -rf {} + find "${BUILD_DIR}/opt/local-installer-agent/app" -type f \( -name "*.pyc" -o -name "*.pyo" \) -delete find "${BUILD_DIR}/opt/local-installer-agent" -type d -exec chmod 755 {} + find "${BUILD_DIR}/opt/local-installer-agent" -type f -exec chmod 644 {} + cp packaging/systemd/local-installer-agent.service \ "${BUILD_DIR}/etc/systemd/system/local-installer-agent.service" cp packaging/DEBIAN/control "${BUILD_DIR}/DEBIAN/control" cp packaging/DEBIAN/postinst "${BUILD_DIR}/DEBIAN/postinst" cp packaging/DEBIAN/prerm "${BUILD_DIR}/DEBIAN/prerm" cp packaging/DEBIAN/postrm "${BUILD_DIR}/DEBIAN/postrm" chmod 755 "${BUILD_DIR}/DEBIAN/postinst" chmod 755 "${BUILD_DIR}/DEBIAN/prerm" chmod 755 "${BUILD_DIR}/DEBIAN/postrm" chmod 644 "${BUILD_DIR}/DEBIAN/control" chmod 644 "${BUILD_DIR}/etc/systemd/system/local-installer-agent.service" sed -i -E "s/^Version:.*/Version: ${VERSION}/" "${BUILD_DIR}/DEBIAN/control" sed -i -E "s/^Architecture:.*/Architecture: ${ARCH}/" "${BUILD_DIR}/DEBIAN/control" cat > "${BUILD_DIR}/etc/local-installer-agent/agent.env" <