The repository, its Python service, its systemd units, its token file and its environment prefix still carried the old name, which matches nothing public any more. Paths, units, user and variables now use repo: REPO_*, /etc/repo/token, /var/lib/repo, repo.service and repo-prune.timer. A server installed before this change keeps the old user, paths and token: run server/install.sh again to recreate them.
82 lines
2.4 KiB
Bash
Executable File
82 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Envoie un ou plusieurs paquets vers le dépôt repo.
|
|
#
|
|
# REPO_URL=http://mc.laxacube.ch:30065 REPO_TOKEN=... ./push.sh *.pkg.tar.zst
|
|
#
|
|
# REPO_URL URL du dépôt (défaut : http://127.0.0.1:30065 ; Caddy écoute le port
|
|
# pour n'importe quel Host, le nom public fonctionne aussi)
|
|
# REPO_TOKEN jeton d'administration ; à défaut, lu dans $REPO_TOKEN_FILE
|
|
# (/etc/repo/token par défaut), avec sudo si nécessaire.
|
|
|
|
set -euo pipefail
|
|
|
|
REPO_URL="${REPO_URL:-http://127.0.0.1:30065}"
|
|
TOKEN_FILE="${REPO_TOKEN_FILE:-/etc/repo/token}"
|
|
REPO_TOKEN="${REPO_TOKEN:-}"
|
|
|
|
usage() {
|
|
echo "usage: $0 [--url URL] [--token JETON] <paquet.pkg.tar.zst> [...]" >&2
|
|
exit 2
|
|
}
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--url) REPO_URL="${2:?}"; shift 2 ;;
|
|
--token) REPO_TOKEN="${2:?}"; shift 2 ;;
|
|
-h|--help) usage ;;
|
|
--) shift; break ;;
|
|
-*) echo "option inconnue : $1" >&2; usage ;;
|
|
*) break ;;
|
|
esac
|
|
done
|
|
|
|
if [[ $# -eq 0 ]]; then usage; fi
|
|
|
|
if [[ -z "$REPO_TOKEN" ]]; then
|
|
if [[ -r "$TOKEN_FILE" ]]; then
|
|
REPO_TOKEN="$(<"$TOKEN_FILE")"
|
|
elif command -v sudo >/dev/null 2>&1 && sudo -n cat "$TOKEN_FILE" >/dev/null 2>&1; then
|
|
REPO_TOKEN="$(sudo -n cat "$TOKEN_FILE")"
|
|
else
|
|
echo "jeton introuvable : passez --token ou REPO_TOKEN" >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
REPO_TOKEN="${REPO_TOKEN//[$'\r\n']/}"
|
|
|
|
REPO_URL="${REPO_URL%/}"
|
|
echo "→ $REPO_URL"
|
|
|
|
status=0
|
|
for pkg in "$@"; do
|
|
[[ -f "$pkg" ]] || { echo "fichier introuvable : $pkg" >&2; status=1; continue; }
|
|
name="$(basename "$pkg")"
|
|
printf ' %s ' "$name"
|
|
if response="$(curl -sS -w '\n%{http_code}' -X POST "$REPO_URL/api/packages" \
|
|
-H "Authorization: Bearer $REPO_TOKEN" \
|
|
-H "X-Filename: $name" \
|
|
-H 'Content-Type: application/octet-stream' \
|
|
--data-binary "@$pkg")"; then
|
|
code="${response##*$'\n'}"
|
|
body="${response%$'\n'*}"
|
|
# Un simple 200 ne suffit pas : on exige une réponse JSON valide du service
|
|
# (un hôte mal configuré dans Caddy renvoie un 200 vide).
|
|
if [[ "$code" == "200" ]] && grep -Eq '"ok" *: *true' <<<"$body"; then
|
|
echo "✓"
|
|
else
|
|
echo "✗ ($code)"
|
|
if [[ -n "$body" ]]; then
|
|
printf '%s\n' "$body" | sed 's/^/ /'
|
|
else
|
|
echo " réponse vide — vérifiez l'URL publiée par Caddy pour cet hôte"
|
|
fi
|
|
status=1
|
|
fi
|
|
else
|
|
echo "✗ (connexion impossible)"
|
|
status=1
|
|
fi
|
|
done
|
|
|
|
exit "$status"
|