The main sweep — ~260 call sites across ~100 files move from string
concatenation on a single root to appDir/storageAppDirs/storageAppConfigs.
On a single-root install the resolved paths are identical, so this is a
no-op until a location is registered.
Enumerators were the interesting half. `for d in "$containers_dir"/*/`
appears in the menus, the registry/artifact scanners and the DNS setup —
and a shell glob cannot list a rootless 751 tree at all, which is the
same bug config_find_file.sh already documents in a comment. Routing them
through storageAppDirs (which enumerates as the owning user) fixes that
alongside the multi-root work.
Three places needed judgement rather than substitution:
db_app_scan.sh deletes database rows and port allocations for apps whose
folder is missing, and reaps "empty" app dirs. With a storage location
unmounted, every app on it looks exactly like that. Each of those
branches now gates on appStorageAvailable first — an app on an unplugged
drive is skipped with a notice, never deleted.
instance_create.sh rewrites cloned hooks so an instance touches its own
directory instead of the base app's. Its sed matched ${containers_dir}<type>,
which this sweep just replaced with $(appDir <type>) — so it would have
silently stopped redirecting, and an instance would have written to the
original's files (the adguard auth adapter case its own comment warns
about). Now matches both appDir forms, verified against bare, quoted,
unrelated-app, legacy and prose cases.
peer_shell/peer_pull streamed and extracted relative to the primary root.
Both now use the app's own root, and peer_shell keeps a single-root
fallback since it runs as a restricted SSH shell with no LibrePortal env.
Also fixes a pre-existing bug found on the way: webui_app_config.sh
tested "$containers_dir/frontend/data/last_update", one level short of the
real tree under the libreportal app dir, so the WebUI refresh trigger
after a config update has never once fired.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
82 lines
2.7 KiB
Bash
82 lines
2.7 KiB
Bash
#!/bin/bash
|
|
|
|
manifestCollect()
|
|
{
|
|
local app_name="$1"
|
|
local app_dir="$(appDir "$app_name")"
|
|
|
|
local libreportal_commit
|
|
libreportal_commit=$(git -C "${install_scripts_dir%/scripts/}" rev-parse --short HEAD 2>/dev/null || echo "unknown")
|
|
|
|
local compose_file=""
|
|
for candidate in "$app_dir/docker-compose.yml" "$app_dir/compose.yml"; do
|
|
[[ -f "$candidate" ]] && compose_file="$candidate" && break
|
|
done
|
|
|
|
local compose_hash="unknown"
|
|
[[ -n "$compose_file" ]] && compose_hash=$(sha256sum "$compose_file" 2>/dev/null | cut -d' ' -f1)
|
|
|
|
local images_json="[]"
|
|
if [[ -n "$compose_file" ]]; then
|
|
local images=()
|
|
while IFS= read -r line; do
|
|
local img
|
|
img=$(echo "$line" | sed -E 's/^[[:space:]]*image:[[:space:]]*["'\'']?([^"'\'' ]+)["'\'']?.*/\1/')
|
|
[[ -n "$img" ]] && images+=("\"$img\"")
|
|
done < <(grep -E '^[[:space:]]+image:' "$compose_file" 2>/dev/null)
|
|
if [[ ${#images[@]} -gt 0 ]]; then
|
|
images_json="[$(IFS=,; echo "${images[*]}")]"
|
|
fi
|
|
fi
|
|
|
|
local volumes_json="[]"
|
|
if [[ -d "$app_dir" ]]; then
|
|
local vols=()
|
|
while IFS= read -r d; do
|
|
[[ -n "$d" ]] && vols+=("\"$(basename "$d")\"")
|
|
done < <(find "$app_dir" -mindepth 1 -maxdepth 1 -type d 2>/dev/null)
|
|
if [[ ${#vols[@]} -gt 0 ]]; then
|
|
volumes_json="[$(IFS=,; echo "${vols[*]}")]"
|
|
fi
|
|
fi
|
|
|
|
local size_bytes
|
|
size_bytes=$(runFileOp du -sb "$app_dir" 2>/dev/null | awk '{print $1}')
|
|
[[ -z "$size_bytes" ]] && size_bytes=0
|
|
|
|
local file_count
|
|
file_count=$(runFileOp find "$app_dir" -type f 2>/dev/null | wc -l | tr -d ' ')
|
|
|
|
local strategy="${CFG_BACKUP_STRATEGY:-auto}"
|
|
declare -f backupResolveStrategy >/dev/null 2>&1 && strategy=$(backupResolveStrategy "$app_name")
|
|
|
|
local databases_json="[]"
|
|
if declare -f backupDbDescriptors >/dev/null 2>&1; then
|
|
local dbs=() desc kind container datadir path
|
|
while IFS= read -r desc; do
|
|
[[ -z "$desc" ]] && continue
|
|
IFS=':' read -r kind container datadir path <<< "$desc"
|
|
dbs+=("{\"kind\":\"$kind\",\"container\":\"$container\",\"path\":\"$path\"}")
|
|
done < <(backupDbDescriptors "$app_name")
|
|
[[ ${#dbs[@]} -gt 0 ]] && databases_json="[$(IFS=,; echo "${dbs[*]}")]"
|
|
fi
|
|
|
|
cat <<EOF
|
|
{
|
|
"version": 2,
|
|
"app": "$app_name",
|
|
"host": "${CFG_INSTALL_NAME:-libreportal}",
|
|
"created_at": "$(date -Iseconds)",
|
|
"libreportal_commit": "$libreportal_commit",
|
|
"engine": "restic",
|
|
"compose_hash": "$compose_hash",
|
|
"images": $images_json,
|
|
"volumes": $volumes_json,
|
|
"size_bytes": $size_bytes,
|
|
"file_count": $file_count,
|
|
"strategy": "$strategy",
|
|
"databases": $databases_json
|
|
}
|
|
EOF
|
|
}
|