mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-19 19:54:31 +00:00
0.9.6.19 route WebDAV and legacy per connection
This commit is contained in:
@@ -5,6 +5,10 @@ CONFIG_DIR="/etc/bratonien-tools/nc-connector"
|
|||||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
|
|
||||||
|
declare -A webdav_success_for_legacy=()
|
||||||
|
declare -A webdav_failure_for_legacy=()
|
||||||
|
declare -A legacy_seen=()
|
||||||
|
|
||||||
read_config_value() {
|
read_config_value() {
|
||||||
local key="$1"
|
local key="$1"
|
||||||
local file="$2"
|
local file="$2"
|
||||||
@@ -17,6 +21,15 @@ read_config_value() {
|
|||||||
printf '%s' "$value"
|
printf '%s' "$value"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
numeric_connection_id() {
|
||||||
|
local value="${1:-}"
|
||||||
|
if [[ "$value" =~ ^[0-9]+$ ]]; then
|
||||||
|
printf '%s' "$value"
|
||||||
|
else
|
||||||
|
printf '0'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
compact_text() {
|
compact_text() {
|
||||||
printf '%s\n' "$1" | tail -n 20 | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g; s/^[[:space:]]//; s/[[:space:]]$//'
|
printf '%s\n' "$1" | tail -n 20 | tr '\n' ' ' | sed 's/[[:space:]]\+/ /g; s/^[[:space:]]//; s/[[:space:]]$//'
|
||||||
}
|
}
|
||||||
@@ -133,72 +146,76 @@ done
|
|||||||
[[ -n "$route_piwigo_root" ]] || route_piwigo_root="/var/www/piwigo"
|
[[ -n "$route_piwigo_root" ]] || route_piwigo_root="/var/www/piwigo"
|
||||||
ROUTE_STATUS_FILE="${route_piwigo_root%/}/_data/bratonien-tools/nc-connector-status/route-status.json"
|
ROUTE_STATUS_FILE="${route_piwigo_root%/}/_data/bratonien-tools/nc-connector-status/route-status.json"
|
||||||
|
|
||||||
webdav_success=0
|
webdav_success_count=0
|
||||||
webdav_failed=0
|
webdav_failure_count=0
|
||||||
webdav_failure_detail=""
|
legacy_run_count=0
|
||||||
|
legacy_failure_count=0
|
||||||
|
fallback_used=0
|
||||||
|
unpaired_webdav_failure=0
|
||||||
|
summary_parts=()
|
||||||
|
|
||||||
if [[ ${#webdav_configs[@]} -eq 0 ]]; then
|
for config in "${webdav_configs[@]}"; do
|
||||||
webdav_failed=1
|
name="$(basename "$config")"
|
||||||
webdav_failure_detail="Keine WebDAV-Runtime-Verbindung ist konfiguriert. Es existiert aktuell nur die Legacy-Verbindung; deshalb kann WebDAV nicht primaer laufen."
|
connection_id="$(numeric_connection_id "$(read_config_value CONNECTION_ID "$config")")"
|
||||||
echo "NC Connector: $webdav_failure_detail" >&2
|
legacy_id="$(numeric_connection_id "$(read_config_value MIGRATION_LEGACY_CONNECTION_ID "$config")")"
|
||||||
else
|
|
||||||
for config in "${webdav_configs[@]}"; do
|
if [[ "$connection_id" -lt 1 ]]; then
|
||||||
name="$(basename "$config")"
|
echo "NC Connector: $name besitzt keine gueltige WebDAV-Verbindungs-ID." >&2
|
||||||
echo "NC Connector WebDAV primaer: $name"
|
webdav_failure_count=$((webdav_failure_count + 1))
|
||||||
webdav_output=""
|
unpaired_webdav_failure=1
|
||||||
if webdav_output="$(env PIWIGO_CONFIG="$config" bash "$SCRIPT_DIR/sync-webdav.sh" 2>&1)"; then
|
summary_parts+=("$name: ungueltige Verbindungs-ID")
|
||||||
webdav_success=1
|
continue
|
||||||
[[ -z "$webdav_output" ]] || printf '%s\n' "$webdav_output"
|
fi
|
||||||
|
|
||||||
|
echo "NC Connector WebDAV #$connection_id: $name"
|
||||||
|
webdav_output=""
|
||||||
|
if webdav_output="$(env PIWIGO_CONFIG="$config" bash "$SCRIPT_DIR/sync-webdav.sh" 2>&1)"; then
|
||||||
|
webdav_success_count=$((webdav_success_count + 1))
|
||||||
|
[[ -z "$webdav_output" ]] || printf '%s\n' "$webdav_output"
|
||||||
|
if [[ "$legacy_id" -gt 0 ]]; then
|
||||||
|
webdav_success_for_legacy["$legacy_id"]="$connection_id"
|
||||||
|
summary_parts+=("WebDAV #$connection_id erfolgreich; Legacy #$legacy_id uebersprungen")
|
||||||
else
|
else
|
||||||
webdav_exit=$?
|
summary_parts+=("WebDAV #$connection_id erfolgreich")
|
||||||
webdav_failed=1
|
|
||||||
[[ -z "$webdav_output" ]] || printf '%s\n' "$webdav_output" >&2
|
|
||||||
webdav_failure_detail="$(read_webdav_failure_detail "$config" "$webdav_output")"
|
|
||||||
webdav_failure_detail="Exit-Code ${webdav_exit}: ${webdav_failure_detail}"
|
|
||||||
echo "NC Connector: WebDAV-Lauf fehlgeschlagen: $webdav_failure_detail" >&2
|
|
||||||
echo "NC Connector: Legacy-Fallback bleibt verfuegbar." >&2
|
|
||||||
fi
|
fi
|
||||||
done
|
else
|
||||||
fi
|
webdav_exit=$?
|
||||||
|
webdav_failure_count=$((webdav_failure_count + 1))
|
||||||
|
[[ -z "$webdav_output" ]] || printf '%s\n' "$webdav_output" >&2
|
||||||
|
webdav_failure_detail="$(read_webdav_failure_detail "$config" "$webdav_output")"
|
||||||
|
webdav_failure_detail="Exit-Code ${webdav_exit}: ${webdav_failure_detail}"
|
||||||
|
echo "NC Connector: WebDAV #$connection_id fehlgeschlagen: $webdav_failure_detail" >&2
|
||||||
|
|
||||||
if [[ "$webdav_success" -eq 1 ]]; then
|
if [[ "$legacy_id" -gt 0 ]]; then
|
||||||
write_route_status \
|
webdav_failure_for_legacy["$legacy_id"]="$webdav_failure_detail"
|
||||||
"webdav" \
|
echo "NC Connector: Nur Legacy-Verbindung #$legacy_id ist fuer diesen WebDAV-Lauf als Fallback vorgesehen." >&2
|
||||||
"WebDAV (primaer)" \
|
else
|
||||||
"WebDAV erfolgreich. Legacy-Fallback wurde in diesem Lauf nicht ausgefuehrt." \
|
unpaired_webdav_failure=1
|
||||||
"0" \
|
summary_parts+=("WebDAV #$connection_id fehlgeschlagen ohne Legacy-Fallback")
|
||||||
"1"
|
fi
|
||||||
echo "NC Connector: WebDAV erfolgreich; Legacy-Verbindung wird in diesem Lauf nicht ausgefuehrt."
|
fi
|
||||||
exit 0
|
done
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ${#configs[@]} -eq 0 ]]; then
|
|
||||||
[[ -n "$webdav_failure_detail" ]] || webdav_failure_detail="WebDAV ist fehlgeschlagen; Ursache konnte nicht ermittelt werden."
|
|
||||||
write_route_status \
|
|
||||||
"failed" \
|
|
||||||
"FEHLER - kein Datenweg" \
|
|
||||||
"WebDAV-Fehler: $webdav_failure_detail Keine Legacy-Fallback-Verbindung vorhanden." \
|
|
||||||
"0" \
|
|
||||||
"0"
|
|
||||||
echo "NC Connector: WebDAV ist fehlgeschlagen und es ist keine Legacy-Fallback-Verbindung vorhanden." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "NC Connector: kein erfolgreicher WebDAV-Lauf; Legacy-Fallback wird ausgefuehrt."
|
|
||||||
legacy_result=0
|
|
||||||
|
|
||||||
for config in "${configs[@]}"; do
|
for config in "${configs[@]}"; do
|
||||||
name="$(basename "$config")"
|
name="$(basename "$config")"
|
||||||
connection_id=""
|
connection_id="0"
|
||||||
if [[ "$name" =~ ^connection-([0-9]+)\.conf$ ]]; then
|
if [[ "$name" =~ ^connection-([0-9]+)\.conf$ ]]; then
|
||||||
connection_id="${BASH_REMATCH[1]}"
|
connection_id="${BASH_REMATCH[1]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ "$connection_id" -lt 1 ]]; then
|
||||||
|
echo "NC Connector: $name besitzt keine gueltige Legacy-Verbindungs-ID." >&2
|
||||||
|
legacy_failure_count=$((legacy_failure_count + 1))
|
||||||
|
summary_parts+=("$name: ungueltige Legacy-Verbindungs-ID")
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
legacy_seen["$connection_id"]=1
|
||||||
|
|
||||||
piwigo_root="$(read_config_value PIWIGO_ROOT "$config")"
|
piwigo_root="$(read_config_value PIWIGO_ROOT "$config")"
|
||||||
[[ -n "$piwigo_root" ]] || piwigo_root="/var/www/piwigo"
|
[[ -n "$piwigo_root" ]] || piwigo_root="/var/www/piwigo"
|
||||||
tombstone_dir="${piwigo_root%/}/_data/bratonien-tools/nc-connector-status"
|
tombstone_dir="${piwigo_root%/}/_data/bratonien-tools/nc-connector-status"
|
||||||
|
|
||||||
if [[ -n "$connection_id" && -f "$tombstone_dir/deleted-$connection_id" ]]; then
|
if [[ -f "$tombstone_dir/deleted-$connection_id" ]]; then
|
||||||
echo "NC Connector: Verbindung $connection_id wurde geloescht; Laufzeitdateien werden entfernt."
|
echo "NC Connector: Verbindung $connection_id wurde geloescht; Laufzeitdateien werden entfernt."
|
||||||
rm -f -- "$CONFIG_DIR/connection-$connection_id.conf" \
|
rm -f -- "$CONFIG_DIR/connection-$connection_id.conf" \
|
||||||
"$CONFIG_DIR/connection-$connection_id.db-password" \
|
"$CONFIG_DIR/connection-$connection_id.db-password" \
|
||||||
@@ -209,33 +226,68 @@ for config in "${configs[@]}"; do
|
|||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "NC Connector Legacy-Fallback: $name"
|
if [[ -n "${webdav_success_for_legacy[$connection_id]:-}" ]]; then
|
||||||
if ! env PIWIGO_CONFIG="$config" bash "$SCRIPT_DIR/sync.sh"; then
|
echo "NC Connector: Legacy #$connection_id wird nicht ausgefuehrt, weil der zugeordnete WebDAV-Nachfolger #${webdav_success_for_legacy[$connection_id]} erfolgreich war."
|
||||||
legacy_result=1
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
legacy_run_count=$((legacy_run_count + 1))
|
||||||
|
if [[ -n "${webdav_failure_for_legacy[$connection_id]:-}" ]]; then
|
||||||
|
echo "NC Connector Legacy-Fallback #$connection_id nach WebDAV-Fehler: $name"
|
||||||
|
fallback_used=1
|
||||||
|
else
|
||||||
|
echo "NC Connector Legacy #$connection_id: $name"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if env PIWIGO_CONFIG="$config" bash "$SCRIPT_DIR/sync.sh"; then
|
||||||
|
if [[ -n "${webdav_failure_for_legacy[$connection_id]:-}" ]]; then
|
||||||
|
summary_parts+=("WebDAV fuer Legacy #$connection_id fehlgeschlagen; Legacy-Fallback erfolgreich")
|
||||||
|
else
|
||||||
|
summary_parts+=("Legacy #$connection_id erfolgreich")
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
legacy_failure_count=$((legacy_failure_count + 1))
|
||||||
|
summary_parts+=("Legacy #$connection_id fehlgeschlagen")
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ "$legacy_result" -eq 0 ]]; then
|
for legacy_id in "${!webdav_failure_for_legacy[@]}"; do
|
||||||
[[ -n "$webdav_failure_detail" ]] || webdav_failure_detail="WebDAV war nicht erfolgreich; Ursache konnte nicht ermittelt werden."
|
if [[ -z "${legacy_seen[$legacy_id]:-}" ]]; then
|
||||||
write_route_status \
|
echo "NC Connector: WebDAV fuer Legacy #$legacy_id ist fehlgeschlagen, aber die zugeordnete Legacy-Runtime fehlt." >&2
|
||||||
"legacy_fallback" \
|
legacy_failure_count=$((legacy_failure_count + 1))
|
||||||
"LEGACY-FALLBACK AKTIV" \
|
summary_parts+=("Fallback #$legacy_id fehlt")
|
||||||
"WebDAV-Fehler: $webdav_failure_detail Legacy-Fallback wurde erfolgreich ausgefuehrt." \
|
fi
|
||||||
"1" \
|
done
|
||||||
"1"
|
|
||||||
echo "NC Connector: Legacy-Fallback erfolgreich."
|
summary_detail="$(IFS='; '; printf '%s' "${summary_parts[*]}")"
|
||||||
|
[[ -n "$summary_detail" ]] || summary_detail="Keine Connector-Route wurde ausgefuehrt."
|
||||||
|
|
||||||
|
if [[ "$unpaired_webdav_failure" -eq 0 && "$legacy_failure_count" -eq 0 ]]; then
|
||||||
|
if [[ "$fallback_used" -eq 1 ]]; then
|
||||||
|
route="mixed_fallback"
|
||||||
|
label="MIGRATION - FALLBACK AKTIV"
|
||||||
|
elif [[ "$webdav_success_count" -gt 0 && "$legacy_run_count" -gt 0 ]]; then
|
||||||
|
route="mixed"
|
||||||
|
label="WebDAV + Legacy"
|
||||||
|
elif [[ "$webdav_success_count" -gt 0 ]]; then
|
||||||
|
route="webdav"
|
||||||
|
label="WebDAV"
|
||||||
|
else
|
||||||
|
route="legacy"
|
||||||
|
label="Legacy"
|
||||||
|
fi
|
||||||
|
|
||||||
|
write_route_status "$route" "$label" "$summary_detail" "$fallback_used" "1"
|
||||||
|
echo "NC Connector: alle erforderlichen Verbindungen wurden erfolgreich verarbeitet."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ -n "$webdav_failure_detail" ]] || webdav_failure_detail="WebDAV war nicht erfolgreich; Ursache konnte nicht ermittelt werden."
|
|
||||||
write_route_status \
|
write_route_status \
|
||||||
"failed" \
|
"failed" \
|
||||||
"FEHLER - WebDAV und Fallback" \
|
"FEHLER - mindestens eine Verbindung" \
|
||||||
"WebDAV-Fehler: $webdav_failure_detail Legacy-Fallback ist ebenfalls fehlgeschlagen." \
|
"$summary_detail" \
|
||||||
"1" \
|
"$fallback_used" \
|
||||||
"0"
|
"0"
|
||||||
|
|
||||||
if [[ "$webdav_failed" -eq 1 ]]; then
|
echo "NC Connector: mindestens eine erforderliche Verbindung ist fehlgeschlagen." >&2
|
||||||
echo "NC Connector: WebDAV und Legacy-Fallback sind fehlgeschlagen." >&2
|
|
||||||
fi
|
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
Reference in New Issue
Block a user