diff --git a/TODO-4.2.1.md b/TODO-4.2.1.md index d1c2923..544e9e9 100644 --- a/TODO-4.2.1.md +++ b/TODO-4.2.1.md @@ -29,7 +29,11 @@ - Created aur-cli/PKGBUILD with [cli,dct,compression] extras only - No flask/gunicorn/fastapi/uvicorn/pyzbar deps - 68MB vs 79MB for full package -- [ ] `stegasoo-api` - REST API package (needs auth overhaul first) +- [x] `stegasoo-api` - REST API package + - Created aur-api/PKGBUILD with [api,cli,compression] extras + - Has fastapi/uvicorn, no flask/gunicorn + - 74MB package size + - Includes systemd service with TLS ## API Auth Work - [x] API key authentication (simpler than OAuth2 for personal use) @@ -47,5 +51,4 @@ - `stegasoo api serve` (starts with TLS by default) ## API Documentation -- [ ] Postman collection -- [ ] Environment variable templates +- [ ] Postman collection (with environment templates) diff --git a/aur-api/.SRCINFO b/aur-api/.SRCINFO new file mode 100644 index 0000000..909a66f --- /dev/null +++ b/aur-api/.SRCINFO @@ -0,0 +1,23 @@ +pkgbase = stegasoo-api-git + pkgdesc = Stegasoo REST API with TLS and API key authentication + pkgver = 4.2.0.r6.g34ede38 + pkgrel = 1 + url = https://github.com/adlee-was-taken/stegasoo + install = stegasoo-api-git.install + arch = x86_64 + license = MIT + makedepends = git + makedepends = python + makedepends = python-build + makedepends = python-hatchling + depends = python>=3.11 + depends = zbar + optdepends = libjpeg-turbo: jpegtran for lossless JPEG rotation (DCT-safe) + provides = stegasoo-api + conflicts = stegasoo-api + conflicts = stegasoo + conflicts = stegasoo-git + source = stegasoo-api-git::git+https://github.com/adlee-was-taken/stegasoo.git#branch=main + sha256sums = SKIP + +pkgname = stegasoo-api-git diff --git a/aur-api/PKGBUILD b/aur-api/PKGBUILD new file mode 100644 index 0000000..a4f23d6 --- /dev/null +++ b/aur-api/PKGBUILD @@ -0,0 +1,109 @@ +# Maintainer: Aaron D. Lee +pkgname=stegasoo-api-git +pkgver=4.2.0.r6.g34ede38 +pkgrel=1 +pkgdesc="Stegasoo REST API with TLS and API key authentication" +arch=('x86_64') +url="https://github.com/adlee-was-taken/stegasoo" +license=('MIT') + +# Python 3.11-3.14 supported +depends=( + 'python>=3.11' + 'zbar' # QR code reading for RSA key extraction +) +makedepends=( + 'git' + 'python' + 'python-build' + 'python-hatchling' +) +optdepends=( + 'libjpeg-turbo: jpegtran for lossless JPEG rotation (DCT-safe)' +) +provides=('stegasoo-api') +conflicts=('stegasoo-api' 'stegasoo' 'stegasoo-git') +install=stegasoo-api-git.install +source=("${pkgname}::git+https://github.com/adlee-was-taken/stegasoo.git#branch=main") +sha256sums=('SKIP') + +pkgver() { + cd "$pkgname" + git describe --long --tags 2>/dev/null | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g' || \ + printf "%s.r%s.g%s" "4.2.1" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" +} + +build() { + cd "$pkgname" + python -m build --wheel --no-isolation +} + +package() { + cd "$pkgname" + + # Detect Python version for site-packages path + local pyver=$(python -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")') + + # Install to /opt/stegasoo-api with dedicated venv + install -dm755 "$pkgdir/opt/stegasoo-api" + + # Create fresh venv in package + python -m venv "$pkgdir/opt/stegasoo-api/venv" + + # Install the wheel with API + CLI + compression extras + local wheel=$(ls dist/*.whl | head -1) + "$pkgdir/opt/stegasoo-api/venv/bin/pip" install --no-cache-dir "${wheel}[api,cli,compression]" + + # Install API frontend (not included in wheel by default) + local site_packages="$pkgdir/opt/stegasoo-api/venv/lib/python${pyver}/site-packages" + install -dm755 "$site_packages/frontends/api" + cp -r frontends/api/*.py "$site_packages/frontends/api/" + cp -r frontends/__init__.py "$site_packages/frontends/" 2>/dev/null || true + + # Create temp directory for API + install -dm755 "$site_packages/frontends/api/temp_files" + + # Create config directories + install -dm755 "$pkgdir/opt/stegasoo-api/config" + install -dm700 "$pkgdir/opt/stegasoo-api/certs" + + # Fix shebangs - replace build-time paths with installed paths + find "$pkgdir/opt/stegasoo-api/venv/bin" -type f -exec \ + sed -i "s|$pkgdir/opt/stegasoo-api/venv|/opt/stegasoo-api/venv|g" {} \; + + # Fix pyvenv.cfg + sed -i "s|$pkgdir||g" "$pkgdir/opt/stegasoo-api/venv/pyvenv.cfg" + + # Create symlink to /usr/bin + install -dm755 "$pkgdir/usr/bin" + ln -s /opt/stegasoo-api/venv/bin/stegasoo "$pkgdir/usr/bin/stegasoo" + + # Install license + install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE" + + # Install docs + install -Dm644 README.md "$pkgdir/usr/share/doc/$pkgname/README.md" + + # Install systemd service + install -Dm644 /dev/stdin "$pkgdir/usr/lib/systemd/system/stegasoo-api.service" < (to create API keys) +ExecStart=/opt/stegasoo-api/venv/bin/stegasoo api serve --host 127.0.0.1 --port 8000 +Restart=on-failure +RestartSec=5 + +[Install] +WantedBy=multi-user.target +EOF +} diff --git a/aur-api/stegasoo-api-git.install b/aur-api/stegasoo-api-git.install new file mode 100644 index 0000000..99271e6 --- /dev/null +++ b/aur-api/stegasoo-api-git.install @@ -0,0 +1,48 @@ +post_install() { + # Create stegasoo system user if it doesn't exist + if ! getent passwd stegasoo >/dev/null; then + useradd -r -s /usr/bin/nologin -d /opt/stegasoo-api stegasoo + echo "Created system user 'stegasoo'" + fi + + # Set ownership of directories + chown -R stegasoo:stegasoo /opt/stegasoo-api/config 2>/dev/null || true + chown -R stegasoo:stegasoo /opt/stegasoo-api/certs 2>/dev/null || true + + echo "" + echo "Stegasoo API installed successfully!" + echo "" + echo "Quick Start:" + echo " 1. Create an API key:" + echo " stegasoo api keys create mykey" + echo "" + echo " 2. Start the API server:" + echo " sudo systemctl start stegasoo-api" + echo "" + echo " 3. Access the API:" + echo " curl -k -H 'X-API-Key: YOUR_KEY' https://localhost:8000/" + echo "" + echo "Management commands:" + echo " stegasoo api keys list # List API keys" + echo " stegasoo api keys create X # Create new key" + echo " stegasoo api tls info # Show certificate info" + echo " stegasoo api serve --help # Server options" + echo "" + echo "API docs available at: https://localhost:8000/docs" + echo "" +} + +post_upgrade() { + post_install +} + +pre_remove() { + # Stop service if running + systemctl stop stegasoo-api 2>/dev/null || true +} + +post_remove() { + echo "Stegasoo API removed." + echo "User 'stegasoo' and config in /opt/stegasoo-api were not removed." + echo "To remove: userdel stegasoo && rm -rf /opt/stegasoo-api" +} diff --git a/aur-api/test-build.sh b/aur-api/test-build.sh new file mode 100755 index 0000000..74f361e --- /dev/null +++ b/aur-api/test-build.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# Test build the AUR API package locally + +set -e + +cd "$(dirname "$0")" + +echo "=== Cleaning previous builds ===" +rm -rf stegasoo-api-git pkg src *.pkg.tar.zst *.whl 2>/dev/null || true + +echo "=== Generating .SRCINFO ===" +makepkg --printsrcinfo > .SRCINFO + +echo "=== Building package ===" +makepkg -sf + +echo "=== Package built ===" +ls -la *.pkg.tar.zst + +echo "" +echo "To install: sudo pacman -U stegasoo-api-git-*.pkg.tar.zst" +echo "To test: makepkg -si"