Files
duplicate-finder/debian/build-deb.sh
Carlos 76e89a7313 Fix .deb install path and Gitea upload auth
The .deb install instructions in the README pointed at a URL that
doesn't exist — Gitea exposes the Debian registry as an apt repo, not
as plain file downloads. Switched the README to the apt-repo flow
(add a sources.list line, then apt install).

Also fixed build-deb.sh: Gitea's Debian package endpoint returns
HTTP 405 for token-bearer auth; it requires HTTP basic auth (user +
token-as-password) and the literal /upload suffix on the URL.

Package built and pushed to the registry — apt install works now.
2026-04-24 00:55:11 -04:00

142 lines
7.7 KiB
Bash

#!/bin/bash
# Build dupfinder.deb and upload it to the Gitea package registry.
# Run this on the NAS / any Linux machine with dpkg-deb and curl installed.
#
# Usage:
# ./debian/build-deb.sh
# ./debian/build-deb.sh --no-upload # build only, skip Gitea upload
set -e
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
DEBIAN_DIR="$REPO_ROOT/debian"
BUILD_DIR="$REPO_ROOT/build/deb"
# ── Config ────────────────────────────────────────────────────────────────────
PKG_NAME="dupfinder"
PKG_VERSION="1.0.0"
PKG_ARCH="amd64"
DEB_FILE="${PKG_NAME}_${PKG_VERSION}_${PKG_ARCH}.deb"
GITEA_URL="http://192.168.1.64:3000"
GITEA_OWNER="tocmo0nlord"
GITEA_TOKEN="${GITEA_TOKEN:-72d5ea48d6b97d2185a774de0a36c88ae30f91b0}"
DISTRO="bookworm"
COMPONENT="main"
NO_UPLOAD=false
[[ "${1}" == "--no-upload" ]] && NO_UPLOAD=true
# ── Helpers ───────────────────────────────────────────────────────────────────
info() { echo -e "\033[0;36m==> $*\033[0m"; }
ok() { echo -e "\033[0;32m OK $*\033[0m"; }
fail() { echo -e "\033[0;31m !! $*\033[0m"; exit 1; }
# ── Check dependencies ────────────────────────────────────────────────────────
command -v dpkg-deb &>/dev/null || fail "dpkg-deb not found. Run: sudo apt install dpkg-dev"
command -v curl &>/dev/null || fail "curl not found. Run: sudo apt install curl"
# ── Prepare staging area ──────────────────────────────────────────────────────
info "Preparing build directory..."
PKG_STAGE="$BUILD_DIR/${PKG_NAME}_${PKG_VERSION}_${PKG_ARCH}"
rm -rf "$PKG_STAGE"
mkdir -p "$PKG_STAGE/DEBIAN"
# ── Copy DEBIAN control files ─────────────────────────────────────────────────
info "Copying control files..."
cp "$DEBIAN_DIR/control" "$PKG_STAGE/DEBIAN/control"
cp "$DEBIAN_DIR/postinst" "$PKG_STAGE/DEBIAN/postinst"
cp "$DEBIAN_DIR/prerm" "$PKG_STAGE/DEBIAN/prerm"
cp "$DEBIAN_DIR/postrm" "$PKG_STAGE/DEBIAN/postrm"
# Inject current version into control file
sed -i "s/^Version:.*/Version: $PKG_VERSION/" "$PKG_STAGE/DEBIAN/control"
# Fix permissions — maintainer scripts must be executable
chmod 755 "$PKG_STAGE/DEBIAN/postinst" \
"$PKG_STAGE/DEBIAN/prerm" \
"$PKG_STAGE/DEBIAN/postrm"
# ── Copy payload files ────────────────────────────────────────────────────────
info "Copying payload files..."
cp -r "$DEBIAN_DIR/files/." "$PKG_STAGE/"
# Copy the docker-compose.yml from repo root into the package
mkdir -p "$PKG_STAGE/opt/dupfinder"
cp "$REPO_ROOT/docker-compose.yml" "$PKG_STAGE/opt/dupfinder/docker-compose.yml"
# Copy source as fallback build path
cp -r "$REPO_ROOT/app" "$PKG_STAGE/opt/dupfinder/source/" 2>/dev/null || true
cp -r "$REPO_ROOT/templates" "$PKG_STAGE/opt/dupfinder/source/" 2>/dev/null || true
cp "$REPO_ROOT/Dockerfile" "$PKG_STAGE/opt/dupfinder/source/" 2>/dev/null || true
cp "$REPO_ROOT/requirements.txt" "$PKG_STAGE/opt/dupfinder/source/" 2>/dev/null || true
# ── Fix file permissions ──────────────────────────────────────────────────────
find "$PKG_STAGE" -type f -name "*.sh" -exec chmod 755 {} \;
chmod 755 "$PKG_STAGE/usr/local/bin/dupfinder" 2>/dev/null || true
# Directories must be 755, files 644 (except executables)
find "$PKG_STAGE" -type d -exec chmod 755 {} \;
find "$PKG_STAGE" -type f ! -name "*.sh" \
! -path "*/DEBIAN/*" \
! -name "dupfinder" \
-exec chmod 644 {} \;
ok "Staging area ready: $PKG_STAGE"
# ── Build .deb ────────────────────────────────────────────────────────────────
info "Building $DEB_FILE ..."
mkdir -p "$BUILD_DIR"
dpkg-deb --build --root-owner-group "$PKG_STAGE" "$BUILD_DIR/$DEB_FILE"
DEB_SIZE=$(du -sh "$BUILD_DIR/$DEB_FILE" | cut -f1)
ok "Built: $BUILD_DIR/$DEB_FILE ($DEB_SIZE)"
# ── Upload to Gitea ───────────────────────────────────────────────────────────
if [[ "$NO_UPLOAD" == "true" ]]; then
echo ""
echo "Skipping upload (--no-upload). File is at:"
echo " $BUILD_DIR/$DEB_FILE"
exit 0
fi
info "Uploading to Gitea package registry..."
# Gitea's Debian registry requires HTTP basic auth (user + token-as-password)
# and the literal /upload endpoint — token-bearer auth returns 405.
UPLOAD_URL="$GITEA_URL/api/packages/$GITEA_OWNER/debian/pool/$DISTRO/$COMPONENT/upload"
HTTP_STATUS=$(curl -s -o /tmp/gitea_upload_response.txt -w "%{http_code}" \
-u "$GITEA_OWNER:$GITEA_TOKEN" \
--upload-file "$BUILD_DIR/$DEB_FILE" \
"$UPLOAD_URL")
if [[ "$HTTP_STATUS" == "201" || "$HTTP_STATUS" == "200" ]]; then
ok "Uploaded successfully (HTTP $HTTP_STATUS)"
elif [[ "$HTTP_STATUS" == "409" ]]; then
echo " Package version $PKG_VERSION already exists in registry."
echo " Bump PKG_VERSION in this script to publish a new version."
else
echo " Upload failed (HTTP $HTTP_STATUS):"
cat /tmp/gitea_upload_response.txt
exit 1
fi
# ── Print install instructions ────────────────────────────────────────────────
echo ""
echo "╔══════════════════════════════════════════════════════════════════╗"
echo "║ Package published! Install on any Ubuntu/Debian machine with: ║"
echo "╠══════════════════════════════════════════════════════════════════╣"
echo "║ ║"
echo "║ 1. Add the repo: ║"
echo "║ echo \"deb [trusted=yes] \\ ║"
echo "$GITEA_URL/api/packages/$GITEA_OWNER/debian \\ ║"
echo "$DISTRO $COMPONENT\" \\ ║"
echo "║ | sudo tee /etc/apt/sources.list.d/dupfinder.list ║"
echo "║ ║"
echo "║ 2. Install: ║"
echo "║ sudo apt update && sudo apt install dupfinder ║"
echo "║ ║"
echo "║ 3. Configure: ║"
echo "║ sudo dupfinder setup ║"
echo "║ ║"
echo "╚══════════════════════════════════════════════════════════════════╝"
echo ""