feat(storage): per-app placement, app move, and the READONLY marker

Phase 2 and 4 of docs/roadmap/storage-locations.md. Apps can now be
placed on a location and moved between them.

CFG_<APP>_STORAGE lands in all 37 app templates, holding a location NAME
rather than a path: names survive a migrate to a host with different
disks, paths do not. The 11 infrastructure apps that other apps reach by
literal path (traefik, prometheus, grafana, adguard, gluetun, crowdsec,
headscale, dashy, pihole, unbound, wireguard) are pinned. libreportal
itself never gets the key — it is pinned structurally by webuiDir.

Pinning needed no second config key. "Pinned" is not a fact about a value,
it is a statement about whether the field may be edited, so it goes in the
comment beside **ADVANCED** and **DEV** as **READONLY**, and the field
factory renders those disabled. That marker earns its keep beyond this
feature: derived fields already warned in prose that editing them does
nothing (crowdsec.config:72) next to a perfectly editable input.

storage_app_config.sh keeps the comment honest — it carries the resolved
path for hand-recovery and regenerates the dropdown from the registry, but
only writes when something actually changed, since the app .config is
user-editable and lives in the container-owned tree.

app move stops the app (a live copy of a running Postgres is a corrupt
copy), snapshots it, copies, verifies, and only then removes the source.
The copy runs in libreportal-ownership because it must: app data holds
rootless sub-UID files the manager can neither read nor recreate.
Verified against two real ext4 filesystems that a cross-device move
preserves uid 231141 and the payload, and that the source survives every
refusal path — unregistered destination, the WebUI app, a traversal in the
app name, and an occupied destination.

Task titles registered in both tables, with a specific rule so a move
renders as "Nextcloud - Move to bigdisk" rather than the generic fallback
dropping the destination. lp-task-names could not be run to confirm — it
borrows the WebUI container's node and no containers are running.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
librelad 2026-08-24 20:37:35 +01:00
parent 0de7f40f5d
commit 26e98698d8
49 changed files with 564 additions and 1 deletions

View File

@ -21,6 +21,8 @@ CFG_ADGUARD_APP_NAME=adguard
# Not instanced by design. A DNS server is what clients point at; a second copy on a different port resolves for nobody. One-per-host in practice, like pihole and unbound.
CFG_ADGUARD_MULTI_INSTANCE=false
CFG_ADGUARD_BACKUP=true
# STORAGE = which storage location holds this app's data.
CFG_ADGUARD_STORAGE=default # Storage Location - Fixed: other apps reference adguard by path **READONLY**
CFG_ADGUARD_BACKUP_STRATEGY=auto
CFG_ADGUARD_UPDATE_TYPE=auto
CFG_ADGUARD_COMPOSE_FILE=default

View File

@ -24,6 +24,9 @@ CFG_AUTHELIA_APP_NAME=authelia
CFG_AUTHELIA_MULTI_INSTANCE=false
CFG_AUTHELIA_REQUIRES="domain,traefik"
CFG_AUTHELIA_BACKUP=true
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move authelia <location>` — editing here records intent only.
CFG_AUTHELIA_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_AUTHELIA_BACKUP_STRATEGY=auto
CFG_AUTHELIA_UPDATE_TYPE=auto
CFG_AUTHELIA_COMPOSE_FILE=default

View File

@ -19,6 +19,9 @@ CFG_BOOKSTACK_APP_NAME=bookstack
# is instance-safe — see scripts/instance/instance_create.sh.
CFG_BOOKSTACK_MULTI_INSTANCE=true
CFG_BOOKSTACK_BACKUP=true
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move bookstack <location>` — editing here records intent only.
CFG_BOOKSTACK_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_BOOKSTACK_BACKUP_STRATEGY=auto
CFG_BOOKSTACK_UPDATE_TYPE=auto
CFG_BOOKSTACK_COMPOSE_FILE=default

View File

@ -27,6 +27,8 @@ CFG_CROWDSEC_HOST_PACKAGE=crowdsec
CFG_CROWDSEC_HOST_SERVICES=crowdsec.service,crowdsec-firewall-bouncer.service
CFG_CROWDSEC_HOST_LOG_FILES="crowdsec.service|/var/log/crowdsec.log,crowdsec-firewall-bouncer.service|/var/log/crowdsec-firewall-bouncer.log"
CFG_CROWDSEC_BACKUP=true
# STORAGE = which storage location holds this app's data.
CFG_CROWDSEC_STORAGE=default # Storage Location - Fixed: other apps reference crowdsec by path **READONLY**
CFG_CROWDSEC_BACKUP_STRATEGY=auto
CFG_CROWDSEC_UPDATE_TYPE=auto
CFG_CROWDSEC_MONITORING=false

View File

@ -17,6 +17,8 @@ CFG_DASHY_APP_NAME=dashy
# is instance-safe — see scripts/instance/instance_create.sh.
CFG_DASHY_MULTI_INSTANCE=true
CFG_DASHY_BACKUP=true
# STORAGE = which storage location holds this app's data.
CFG_DASHY_STORAGE=default # Storage Location - Fixed: other apps reference dashy by path **READONLY**
CFG_DASHY_BACKUP_STRATEGY=auto
CFG_DASHY_UPDATE_TYPE=auto
CFG_DASHY_COMPOSE_FILE=default

View File

@ -19,6 +19,9 @@ CFG_GITEA_APP_NAME=gitea
# is instance-safe — see scripts/instance/instance_create.sh.
CFG_GITEA_MULTI_INSTANCE=true
CFG_GITEA_BACKUP=true
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move gitea <location>` — editing here records intent only.
CFG_GITEA_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_GITEA_BACKUP_STRATEGY=auto
CFG_GITEA_UPDATE_TYPE=auto
CFG_GITEA_COMPOSE_FILE=default

View File

@ -19,6 +19,8 @@ CFG_GLUETUN_APP_NAME=gluetun
# Not instanced by design. A network provider, not a destination: other apps join it with network_mode "container:gluetun-service". A second copy leaves that name ambiguous.
CFG_GLUETUN_MULTI_INSTANCE=false
CFG_GLUETUN_BACKUP=true
# STORAGE = which storage location holds this app's data.
CFG_GLUETUN_STORAGE=default # Storage Location - Fixed: other apps reference gluetun by path **READONLY**
CFG_GLUETUN_BACKUP_STRATEGY=auto
CFG_GLUETUN_UPDATE_TYPE=auto
CFG_GLUETUN_COMPOSE_FILE=default

View File

@ -20,6 +20,8 @@ CFG_GRAFANA_APP_NAME=grafana
CFG_GRAFANA_MULTI_INSTANCE=true
CFG_GRAFANA_REQUIRES="prometheus"
CFG_GRAFANA_BACKUP=true
# STORAGE = which storage location holds this app's data.
CFG_GRAFANA_STORAGE=default # Storage Location - Fixed: other apps reference grafana by path **READONLY**
CFG_GRAFANA_BACKUP_STRATEGY=auto
CFG_GRAFANA_UPDATE_TYPE=auto
CFG_GRAFANA_COMPOSE_FILE=default

View File

@ -18,6 +18,8 @@ CFG_HEADSCALE_APP_NAME=headscale
# Not instanced by design. The control server a tailnet is defined by — nodes register against exactly one.
CFG_HEADSCALE_MULTI_INSTANCE=false
CFG_HEADSCALE_BACKUP=true
# STORAGE = which storage location holds this app's data.
CFG_HEADSCALE_STORAGE=default # Storage Location - Fixed: other apps reference headscale by path **READONLY**
CFG_HEADSCALE_BACKUP_STRATEGY=auto
CFG_HEADSCALE_UPDATE_TYPE=auto
CFG_HEADSCALE_COMPOSE_FILE=default

View File

@ -17,6 +17,9 @@ CFG_INVIDIOUS_APP_NAME=invidious
# is instance-safe — see scripts/instance/instance_create.sh.
CFG_INVIDIOUS_MULTI_INSTANCE=true
CFG_INVIDIOUS_BACKUP=false
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move invidious <location>` — editing here records intent only.
CFG_INVIDIOUS_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_INVIDIOUS_BACKUP_STRATEGY=auto
CFG_INVIDIOUS_UPDATE_TYPE=auto
CFG_INVIDIOUS_COMPOSE_FILE=default

View File

@ -17,6 +17,9 @@ CFG_IPINFO_APP_NAME=ipinfo
# is instance-safe — see scripts/instance/instance_create.sh.
CFG_IPINFO_MULTI_INSTANCE=true
CFG_IPINFO_BACKUP=false
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move ipinfo <location>` — editing here records intent only.
CFG_IPINFO_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_IPINFO_BACKUP_STRATEGY=auto
CFG_IPINFO_UPDATE_TYPE=auto
CFG_IPINFO_COMPOSE_FILE=default

View File

@ -17,6 +17,9 @@ CFG_JELLYFIN_APP_NAME=jellyfin
# is instance-safe — see scripts/instance/instance_create.sh.
CFG_JELLYFIN_MULTI_INSTANCE=true
CFG_JELLYFIN_BACKUP=true
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move jellyfin <location>` — editing here records intent only.
CFG_JELLYFIN_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_JELLYFIN_BACKUP_STRATEGY=auto
CFG_JELLYFIN_UPDATE_TYPE=auto
CFG_JELLYFIN_COMPOSE_FILE=default

View File

@ -17,6 +17,9 @@ CFG_JITSIMEET_APP_NAME=jitsimeet
# is instance-safe — see scripts/instance/instance_create.sh.
CFG_JITSIMEET_MULTI_INSTANCE=true
CFG_JITSIMEET_BACKUP=true
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move jitsimeet <location>` — editing here records intent only.
CFG_JITSIMEET_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_JITSIMEET_BACKUP_STRATEGY=auto
CFG_JITSIMEET_UPDATE_TYPE=auto
CFG_JITSIMEET_COMPOSE_FILE=default

View File

@ -20,6 +20,7 @@ class ConfigUtils {
cleanDescription(description) {
return description
.replace(/\*\*ADVANCED\*\*/g, '')
.replace(/\*\*READONLY\*\*/g, '')
.replace(/\*\*UNUSED\*\*/g, '')
.replace(/\*\*DEV\*\*/g, '')
.replace(/^\s+|\s+$/g, '') // Trim whitespace

View File

@ -66,6 +66,10 @@ Object.assign(TasksManager.prototype, {
// one it collapsed to "Restart Application", losing the only detail that
// distinguishes it from restarting the whole app.
{ match: /^libreportal app restart (\S+) (\S+)/, title: (m) => `${displayName(m[1])} - Restart ${m[2]}` },
// Storage move — name the destination. The generic `app <verb> <app>`
// fallback below would render "Move Application" and silently drop the
// one detail that matters about the task.
{ match: /^libreportal app move (\S+) (\S+)/, title: (m) => `${displayName(m[1])} - Move to ${m[2]}` },
// -- Instances ---------------------------------------------------------
// Named off the TYPE, not the new slug: at create time the instance does
@ -162,6 +166,7 @@ Object.assign(TasksManager.prototype, {
'rebuild': 'Rebuild Application',
'delete': 'Delete Backup',
'backup': 'Backup Application',
'move': 'Move Application',
// Compose verbs the WebUI dispatches. Without these the generic
// "<Action> Application" fallback rendered "Up Application" and
// "Down Application", which read as broken English rather than a task.

View File

@ -523,7 +523,41 @@ class ConfigShared {
}
// Generate appropriate field based on value type and key
// A field whose comment carries **READONLY** is shown but not editable.
//
// "Pinned" is not a fact about a value, it is a statement about whether the
// field may be changed — so it belongs in the comment, beside **ADVANCED**
// and **DEV**, rather than in a second config key. Used by derived values the
// user should SEE but never type over: a storage location's registry-owned
// path, and CFG_<APP>_STORAGE for infrastructure apps that other apps reach
// by path. Before this, such fields were editable inputs with prose telling
// you editing them does nothing.
static isReadonlyField(description) {
return typeof description === 'string' && description.includes('**READONLY**');
}
static generateReadonlyField(fieldId, key, value, title, description) {
const clean = (window.ConfigUtils && window.ConfigUtils.cleanDescription)
? window.ConfigUtils.cleanDescription(description)
: String(description || '').replace(/\*\*[A-Z]+\*\*/g, '').trim();
const safe = String(value == null ? '' : value);
return `
<div class="field-group field-readonly">
<label for="${fieldId}">
${title}
${clean ? `<span class="tooltip" data-tip="${clean}" aria-label="${clean}">\u2139\ufe0f</span>` : ''}
</label>
<input type="text" id="${fieldId}" name="${key}" value="${safe}" class="form-control" readonly disabled aria-readonly="true">
${clean ? `<small class="field-description">${clean}</small>` : ''}
</div>
`;
}
static generateField(fieldId, key, value, title, description, options = {}, allConfig = {}) {
if (this.isReadonlyField(description)) {
return this.generateReadonlyField(fieldId, key, value, title, description);
}
// Note: Git fields (CFG_GIT_*) are now handled by the toggle system in renderGitSection
// They don't need to be hidden here since the section itself is toggled

View File

@ -15,6 +15,8 @@ class TaskCommands {
start: 'libreportal app start {appName}',
stop: 'libreportal app stop {appName}',
backup: 'libreportal app backup {appName}',
// Storage location move — see scripts/storage/storage_move.sh.
move: 'libreportal app move {appName} {location}',
status: 'libreportal app status {appName}',
// Multi-instance (✅ IMPLEMENTED) — provision another isolated copy of a
@ -51,6 +53,7 @@ class TaskCommands {
start: 'implemented',
stop: 'implemented',
backup: 'implemented',
move: 'implemented',
status: 'implemented',
up: 'implemented',
down: 'implemented',
@ -146,6 +149,7 @@ class TaskCommands {
start: ['appName'],
stop: ['appName'],
backup: ['appName'],
move: ['appName', 'location'],
status: ['appName'],
up: ['appName'],
down: ['appName'],

View File

@ -17,6 +17,9 @@ CFG_LINKDING_APP_NAME=linkding
# is instance-safe — see scripts/instance/instance_create.sh.
CFG_LINKDING_MULTI_INSTANCE=true
CFG_LINKDING_BACKUP=true
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move linkding <location>` — editing here records intent only.
CFG_LINKDING_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_LINKDING_BACKUP_STRATEGY=auto
CFG_LINKDING_UPDATE_TYPE=auto
CFG_LINKDING_COMPOSE_FILE=default

View File

@ -17,6 +17,9 @@ CFG_MASTODON_APP_NAME=mastodon
# is instance-safe — see scripts/instance/instance_create.sh.
CFG_MASTODON_MULTI_INSTANCE=true
CFG_MASTODON_BACKUP=true
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move mastodon <location>` — editing here records intent only.
CFG_MASTODON_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_MASTODON_BACKUP_STRATEGY=auto
CFG_MASTODON_UPDATE_TYPE=auto
CFG_MASTODON_COMPOSE_FILE=default

View File

@ -28,6 +28,9 @@ CFG_MATRIX_MULTI_INSTANCE=true
# with public DNS and TLS, and federation is optional.
CFG_MATRIX_REQUIRES=""
CFG_MATRIX_BACKUP=true
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move matrix <location>` — editing here records intent only.
CFG_MATRIX_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_MATRIX_BACKUP_STRATEGY=auto
CFG_MATRIX_UPDATE_TYPE=auto
CFG_MATRIX_COMPOSE_FILE=default

View File

@ -18,6 +18,9 @@ CFG_MATTERMOST_APP_NAME=mattermost
# is instance-safe — see scripts/instance/instance_create.sh.
CFG_MATTERMOST_MULTI_INSTANCE=true
CFG_MATTERMOST_BACKUP=true
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move mattermost <location>` — editing here records intent only.
CFG_MATTERMOST_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_MATTERMOST_BACKUP_STRATEGY=auto
CFG_MATTERMOST_UPDATE_TYPE=auto
CFG_MATTERMOST_COMPOSE_FILE=default

View File

@ -19,6 +19,9 @@ CFG_MONEYAPP_APP_NAME=moneyapp
CFG_MONEYAPP_MULTI_INSTANCE=true
CFG_MONEYAPP_REQUIRES=""
CFG_MONEYAPP_BACKUP=true
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move moneyapp <location>` — editing here records intent only.
CFG_MONEYAPP_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_MONEYAPP_BACKUP_STRATEGY=auto
CFG_MONEYAPP_UPDATE_TYPE=auto
CFG_MONEYAPP_COMPOSE_FILE=default

View File

@ -17,6 +17,9 @@ CFG_NAVIDROME_APP_NAME=navidrome
# is instance-safe — see scripts/instance/instance_create.sh.
CFG_NAVIDROME_MULTI_INSTANCE=true
CFG_NAVIDROME_BACKUP=true
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move navidrome <location>` — editing here records intent only.
CFG_NAVIDROME_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_NAVIDROME_BACKUP_STRATEGY=auto
CFG_NAVIDROME_UPDATE_TYPE=auto
CFG_NAVIDROME_COMPOSE_FILE=default

View File

@ -21,6 +21,9 @@ CFG_NEXTCLOUD_APP_NAME=nextcloud
# is instance-safe — see scripts/instance/instance_create.sh.
CFG_NEXTCLOUD_MULTI_INSTANCE=true
CFG_NEXTCLOUD_BACKUP=true
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move nextcloud <location>` — editing here records intent only.
CFG_NEXTCLOUD_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_NEXTCLOUD_BACKUP_STRATEGY=auto
CFG_NEXTCLOUD_UPDATE_TYPE=auto
CFG_NEXTCLOUD_COMPOSE_FILE=default

View File

@ -19,6 +19,9 @@ CFG_OLLAMA_APP_NAME=ollama
# Not instanced by design. Clients are configured against one endpoint, and each copy duplicates multi-gigabyte model storage for no routing benefit.
CFG_OLLAMA_MULTI_INSTANCE=false
CFG_OLLAMA_BACKUP=true
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move ollama <location>` — editing here records intent only.
CFG_OLLAMA_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_OLLAMA_BACKUP_STRATEGY=auto
CFG_OLLAMA_UPDATE_TYPE=auto
CFG_OLLAMA_COMPOSE_FILE=default

View File

@ -17,6 +17,9 @@ CFG_ONLYOFFICE_APP_NAME=onlyoffice
# is instance-safe — see scripts/instance/instance_create.sh.
CFG_ONLYOFFICE_MULTI_INSTANCE=true
CFG_ONLYOFFICE_BACKUP=true
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move onlyoffice <location>` — editing here records intent only.
CFG_ONLYOFFICE_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_ONLYOFFICE_BACKUP_STRATEGY=auto
CFG_ONLYOFFICE_UPDATE_TYPE=auto
CFG_ONLYOFFICE_COMPOSE_FILE=default

View File

@ -17,6 +17,9 @@ CFG_OWNCLOUD_APP_NAME=owncloud
# is instance-safe — see scripts/instance/instance_create.sh.
CFG_OWNCLOUD_MULTI_INSTANCE=true
CFG_OWNCLOUD_BACKUP=true
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move owncloud <location>` — editing here records intent only.
CFG_OWNCLOUD_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_OWNCLOUD_BACKUP_STRATEGY=auto
CFG_OWNCLOUD_UPDATE_TYPE=auto
CFG_OWNCLOUD_COMPOSE_FILE=default

View File

@ -19,6 +19,8 @@ CFG_PIHOLE_APP_NAME=pihole
# Not instance-safe. A DNS server must own port 53 on the host; a second copy could not bind it.
CFG_PIHOLE_MULTI_INSTANCE=false
CFG_PIHOLE_BACKUP=true
# STORAGE = which storage location holds this app's data.
CFG_PIHOLE_STORAGE=default # Storage Location - Fixed: other apps reference pihole by path **READONLY**
CFG_PIHOLE_BACKUP_STRATEGY=auto
CFG_PIHOLE_UPDATE_TYPE=auto
CFG_PIHOLE_COMPOSE_FILE=default

View File

@ -17,6 +17,8 @@ CFG_PROMETHEUS_APP_NAME=prometheus
# is instance-safe — see scripts/instance/instance_create.sh.
CFG_PROMETHEUS_MULTI_INSTANCE=true
CFG_PROMETHEUS_BACKUP=true
# STORAGE = which storage location holds this app's data.
CFG_PROMETHEUS_STORAGE=default # Storage Location - Fixed: other apps reference prometheus by path **READONLY**
CFG_PROMETHEUS_BACKUP_STRATEGY=auto
CFG_PROMETHEUS_UPDATE_TYPE=auto
CFG_PROMETHEUS_COMPOSE_FILE=default

View File

@ -18,6 +18,9 @@ CFG_ROCKETCHAT_APP_NAME=rocketchat
# is instance-safe — see scripts/instance/instance_create.sh.
CFG_ROCKETCHAT_MULTI_INSTANCE=true
CFG_ROCKETCHAT_BACKUP=true
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move rocketchat <location>` — editing here records intent only.
CFG_ROCKETCHAT_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_ROCKETCHAT_BACKUP_STRATEGY=auto
# Auto. Rocket.Chat does run schema migrations on boot and does refuse to start
# too far behind its database — but an automatic update cannot put it there.

View File

@ -17,6 +17,9 @@ CFG_SEARXNG_APP_NAME=searxng
# is instance-safe — see scripts/instance/instance_create.sh.
CFG_SEARXNG_MULTI_INSTANCE=true
CFG_SEARXNG_BACKUP=false
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move searxng <location>` — editing here records intent only.
CFG_SEARXNG_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_SEARXNG_BACKUP_STRATEGY=auto
CFG_SEARXNG_UPDATE_TYPE=auto
CFG_SEARXNG_COMPOSE_FILE=default

View File

@ -17,6 +17,9 @@ CFG_SPEEDTEST_APP_NAME=speedtest
# is instance-safe — see scripts/instance/instance_create.sh.
CFG_SPEEDTEST_MULTI_INSTANCE=true
CFG_SPEEDTEST_BACKUP=false
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move speedtest <location>` — editing here records intent only.
CFG_SPEEDTEST_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_SPEEDTEST_BACKUP_STRATEGY=auto
CFG_SPEEDTEST_UPDATE_TYPE=auto
CFG_SPEEDTEST_COMPOSE_FILE=default

View File

@ -27,6 +27,9 @@ CFG_STALWART_APP_NAME=stalwart
# Not instance-safe. A mail server must own the SMTP/IMAP ports (25, 465, 587, 993); a second copy could not bind them.
CFG_STALWART_MULTI_INSTANCE=false
CFG_STALWART_BACKUP=true
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move stalwart <location>` — editing here records intent only.
CFG_STALWART_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
# Mail is the one app where a "live" snapshot is a real risk: the message store
# is being written continuously, so a copy taken mid-write can land mid-transaction.
# stop-snapshot-start costs seconds of queued delivery (senders retry — that is

View File

@ -33,6 +33,9 @@ CFG_STOAT_MULTI_INSTANCE=false
# scheme. Any HTTPS satisfies it, including a self-signed Traefik certificate.
CFG_STOAT_REQUIRES=""
CFG_STOAT_BACKUP=true
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move stoat <location>` — editing here records intent only.
CFG_STOAT_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_STOAT_BACKUP_STRATEGY=auto
# Auto. The components of this stack are released together and do expect
# matching versions — which is exactly why they are all pinned to the same tag

View File

@ -19,6 +19,8 @@ CFG_TRAEFIK_APP_NAME=traefik
# Not instance-safe. The edge proxy must own 443 — and one Traefik is what routes every other app.
CFG_TRAEFIK_MULTI_INSTANCE=false
CFG_TRAEFIK_BACKUP=true
# STORAGE = which storage location holds this app's data.
CFG_TRAEFIK_STORAGE=default # Storage Location - Fixed: other apps reference traefik by path **READONLY**
CFG_TRAEFIK_BACKUP_STRATEGY=auto
CFG_TRAEFIK_UPDATE_TYPE=auto
CFG_TRAEFIK_COMPOSE_FILE=default

View File

@ -17,6 +17,9 @@ CFG_TRILIUM_APP_NAME=trilium
# is instance-safe — see scripts/instance/instance_create.sh.
CFG_TRILIUM_MULTI_INSTANCE=true
CFG_TRILIUM_BACKUP=true
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move trilium <location>` — editing here records intent only.
CFG_TRILIUM_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_TRILIUM_BACKUP_STRATEGY=auto
CFG_TRILIUM_UPDATE_TYPE=auto
CFG_TRILIUM_COMPOSE_FILE=default

View File

@ -18,6 +18,9 @@ CFG_TRIVY_APP_NAME=trivy
# Not instanced by design. The updater resolves the scanner by the fixed container name trivy-service (see containers/trivy/scripts/trivy_scan.sh). A second copy would run but never be the one CVE scanning uses.
CFG_TRIVY_MULTI_INSTANCE=false
CFG_TRIVY_BACKUP=false
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move trivy <location>` — editing here records intent only.
CFG_TRIVY_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_TRIVY_BACKUP_STRATEGY=auto
CFG_TRIVY_UPDATE_TYPE=auto
CFG_TRIVY_COMPOSE_FILE=default

View File

@ -19,6 +19,8 @@ CFG_UNBOUND_APP_NAME=unbound
# Not instance-safe. A DNS resolver must own its fixed port 5335; a second copy could not bind it.
CFG_UNBOUND_MULTI_INSTANCE=false
CFG_UNBOUND_BACKUP=true
# STORAGE = which storage location holds this app's data.
CFG_UNBOUND_STORAGE=default # Storage Location - Fixed: other apps reference unbound by path **READONLY**
CFG_UNBOUND_BACKUP_STRATEGY=auto
CFG_UNBOUND_UPDATE_TYPE=auto
CFG_UNBOUND_COMPOSE_FILE=default

View File

@ -18,6 +18,9 @@ CFG_VAULTWARDEN_APP_NAME=vaultwarden
# is instance-safe — see scripts/instance/instance_create.sh.
CFG_VAULTWARDEN_MULTI_INSTANCE=true
CFG_VAULTWARDEN_BACKUP=true
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move vaultwarden <location>` — editing here records intent only.
CFG_VAULTWARDEN_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_VAULTWARDEN_BACKUP_STRATEGY=auto
CFG_VAULTWARDEN_UPDATE_TYPE=auto
CFG_VAULTWARDEN_COMPOSE_FILE=default

View File

@ -18,6 +18,9 @@ CFG_VIKUNJA_APP_NAME=vikunja
# is instance-safe — see scripts/instance/instance_create.sh.
CFG_VIKUNJA_MULTI_INSTANCE=true
CFG_VIKUNJA_BACKUP=true
# STORAGE = which storage location holds this app's data. Change it with
# `libreportal app move vikunja <location>` — editing here records intent only.
CFG_VIKUNJA_STORAGE=default # Storage Location - Which disk holds this app's data [default:Primary]
CFG_VIKUNJA_BACKUP_STRATEGY=auto
CFG_VIKUNJA_UPDATE_TYPE=auto
CFG_VIKUNJA_COMPOSE_FILE=default

View File

@ -20,6 +20,8 @@ CFG_WIREGUARD_APP_NAME=wireguard
CFG_WIREGUARD_MULTI_INSTANCE=false
CFG_WIREGUARD_SUBNET=
CFG_WIREGUARD_BACKUP=true
# STORAGE = which storage location holds this app's data.
CFG_WIREGUARD_STORAGE=default # Storage Location - Fixed: other apps reference wireguard by path **READONLY**
CFG_WIREGUARD_BACKUP_STRATEGY=auto
CFG_WIREGUARD_UPDATE_TYPE=auto
CFG_WIREGUARD_COMPOSE_FILE=default

View File

@ -158,6 +158,21 @@ cliHandleAppCommands()
fi
;;
"move")
# `app move <app> <location>` — relocate an app's data to another
# storage location. Long-running and it stops the app, so it goes
# through the task processor like backup/restore rather than
# blocking the CLI.
if [[ -z "$app_name" || -z "$initial_command4" ]]; then
isNotice "Usage: app move <app_name> <storage_location>"
cliShowAppHelp
elif [[ "$LIBREPORTAL_TASK_EXEC" == "1" ]]; then
storageMoveApp "$app_name" "$initial_command4" "$initial_command5"
else
cliTaskRun "libreportal app move $app_name $initial_command4" "move" "$app_name"
fi
;;
"backup")
if [[ -z "$app_name" ]]; then
isNotice "No app provided."

View File

@ -20,6 +20,10 @@ cliShowAppHelp()
echo " catalog (marketplace). It then installs like any"
echo " other app. Browse: libreportal artifact index"
echo " libreportal app uninstall [name*] - Uninstall the specified app"
echo " libreportal app move [name*] [location*] - Move the app's data to another storage"
echo " location. Stops the app, snapshots it,"
echo " copies, verifies, then removes the source."
echo " See: libreportal storage list"
echo ""
echo " libreportal app start [name*] - Start the specified app (Must be installed)"
echo " libreportal app stop [name*] - Stop the specified app (Must be installed)"

View File

@ -4,9 +4,11 @@
# Do not edit manually - run './scripts/source/files/generate_arrays.sh run' to regenerate
storage_scripts=(
"storage/storage_app_config.sh"
"storage/storage_checks.sh"
"storage/storage_disks.sh"
"storage/storage_locations.sh"
"storage/storage_move.sh"
"storage/storage_scan.sh"
)

View File

@ -1024,12 +1024,16 @@ declare -gA LP_FN_MAP=(
[storageLocationConfig]="storage/storage_locations.sh"
[storageLocationDir]="storage/storage_locations.sh"
[storageLocationsDir]="storage/storage_locations.sh"
[storageMoveApp]="storage/storage_move.sh"
[_storageOptionList]="storage/storage_app_config.sh"
[_storageProbeDir]="storage/storage_checks.sh"
[_storageRefreshWebui]="storage/storage_locations.sh"
[storageRemove]="storage/storage_locations.sh"
[storageScan]="storage/storage_scan.sh"
[storageScanCandidates]="storage/storage_scan.sh"
[_storageSkipTarget]="storage/storage_scan.sh"
[storageSyncAllAppComments]="storage/storage_app_config.sh"
[storageSyncAppComment]="storage/storage_app_config.sh"
[_storageWriteLocationConfig]="storage/storage_locations.sh"
[switchMigrateBackupApps]="docker/type_switcher/swap_docker_type.sh"
[switchMigrateRestoreApps]="docker/type_switcher/swap_docker_type.sh"
@ -2240,12 +2244,16 @@ declare -gA LP_FN_ROOT=(
[storageLocationConfig]="scripts"
[storageLocationDir]="scripts"
[storageLocationsDir]="scripts"
[storageMoveApp]="scripts"
[_storageOptionList]="scripts"
[_storageProbeDir]="scripts"
[_storageRefreshWebui]="scripts"
[storageRemove]="scripts"
[storageScan]="scripts"
[storageScanCandidates]="scripts"
[_storageSkipTarget]="scripts"
[storageSyncAllAppComments]="scripts"
[storageSyncAppComment]="scripts"
[_storageWriteLocationConfig]="scripts"
[switchMigrateBackupApps]="scripts"
[switchMigrateRestoreApps]="scripts"
@ -3493,12 +3501,16 @@ storageList() { unset -f storageList; __lpAutoload "${install_scripts_dir}storag
storageLocationConfig() { unset -f storageLocationConfig; __lpAutoload "${install_scripts_dir}storage/storage_locations.sh"; storageLocationConfig "$@"; }
storageLocationDir() { unset -f storageLocationDir; __lpAutoload "${install_scripts_dir}storage/storage_locations.sh"; storageLocationDir "$@"; }
storageLocationsDir() { unset -f storageLocationsDir; __lpAutoload "${install_scripts_dir}storage/storage_locations.sh"; storageLocationsDir "$@"; }
storageMoveApp() { unset -f storageMoveApp; __lpAutoload "${install_scripts_dir}storage/storage_move.sh"; storageMoveApp "$@"; }
_storageOptionList() { unset -f _storageOptionList; __lpAutoload "${install_scripts_dir}storage/storage_app_config.sh"; _storageOptionList "$@"; }
_storageProbeDir() { unset -f _storageProbeDir; __lpAutoload "${install_scripts_dir}storage/storage_checks.sh"; _storageProbeDir "$@"; }
_storageRefreshWebui() { unset -f _storageRefreshWebui; __lpAutoload "${install_scripts_dir}storage/storage_locations.sh"; _storageRefreshWebui "$@"; }
storageRemove() { unset -f storageRemove; __lpAutoload "${install_scripts_dir}storage/storage_locations.sh"; storageRemove "$@"; }
storageScan() { unset -f storageScan; __lpAutoload "${install_scripts_dir}storage/storage_scan.sh"; storageScan "$@"; }
storageScanCandidates() { unset -f storageScanCandidates; __lpAutoload "${install_scripts_dir}storage/storage_scan.sh"; storageScanCandidates "$@"; }
_storageSkipTarget() { unset -f _storageSkipTarget; __lpAutoload "${install_scripts_dir}storage/storage_scan.sh"; _storageSkipTarget "$@"; }
storageSyncAllAppComments() { unset -f storageSyncAllAppComments; __lpAutoload "${install_scripts_dir}storage/storage_app_config.sh"; storageSyncAllAppComments "$@"; }
storageSyncAppComment() { unset -f storageSyncAppComment; __lpAutoload "${install_scripts_dir}storage/storage_app_config.sh"; storageSyncAppComment "$@"; }
_storageWriteLocationConfig() { unset -f _storageWriteLocationConfig; __lpAutoload "${install_scripts_dir}storage/storage_locations.sh"; _storageWriteLocationConfig "$@"; }
switchMigrateBackupApps() { unset -f switchMigrateBackupApps; __lpAutoload "${install_scripts_dir}docker/type_switcher/swap_docker_type.sh"; switchMigrateBackupApps "$@"; }
switchMigrateRestoreApps() { unset -f switchMigrateRestoreApps; __lpAutoload "${install_scripts_dir}docker/type_switcher/swap_docker_type.sh"; switchMigrateRestoreApps "$@"; }

View File

@ -0,0 +1,100 @@
#!/bin/bash
# Keeping CFG_<APP>_STORAGE's comment truthful.
#
# The value is a location NAME, because names survive a migrate to a host whose
# disks are laid out differently and paths do not. But a name alone is useless to
# someone reading the config file at 2am with no tooling, so the RESOLVED PATH
# rides in the field's comment:
#
# CFG_NEXTCLOUD_STORAGE=bigdisk # Storage Location - Currently at /mnt/bigdisk/apps/nextcloud [default:Primary|bigdisk:Big disk]
#
# Two rules keep that from becoming a liability:
#
# 1. It is a BREADCRUMB, never a source of truth. Nothing reads it to decide
# anything — appDir resolves by discovery. A stale one is cosmetic.
# 2. It is written ONLY when it changes. The app .config is user-editable and
# lives in the container-owned tree, so an unconditional rewrite on every
# regen is both file churn and a runFileOp per app per pass. Compare first.
# Rebuild the "[default:Primary|<name>:<label>|…]" option list from the registry,
# so a dropdown reflects locations added since the app was installed.
_storageOptionList()
{
local out="default:Primary ($(primaryRoot))"
local id state path name_var name
while IFS=$'\t' read -r id state path; do
[[ -z "$id" ]] && continue
name_var="CFG_STORAGE_LOC_${id}_NAME"
name="${!name_var:-location-$id}"
# An unavailable location stays selectable and says so, rather than
# vanishing from the list and looking like it was deleted.
if [[ "$state" == "ok" ]]; then
out+="|${name}:${name} (${path})"
else
out+="|${name}:${name} (${path}) — not mounted"
fi
done < <(runStorage verify 2>/dev/null)
printf '%s' "$out"
}
# Rewrite one app's CFG_<APP>_STORAGE comment. No-op when nothing changed.
storageSyncAppComment()
{
local app="$1"
[[ -n "$app" ]] || return 0
local dir cfg key up
up="${app^^}"
key="CFG_${up}_STORAGE"
dir=$(appDir "$app") || return 0 # unavailable: leave the file alone
cfg="$dir/$app.config"
[[ -f "$cfg" ]] || return 0
local line
line=$(runCfgOp grep -m1 -E "^${key}=" "$cfg" 2>/dev/null) || return 0
[[ -n "$line" ]] || return 0
# Preserve the value and the READONLY marker; regenerate the rest.
local value="${line#*=}"
value="${value%%#*}"
value="${value//$'\r'/}"
value="${value#"${value%%[![:space:]]*}"}"
value="${value%"${value##*[![:space:]]}"}"
value="${value%\"}"; value="${value#\"}"
local readonly_marker=""
[[ "$line" == *'**READONLY**'* ]] && readonly_marker=" **READONLY**"
local desc
if [[ -n "$readonly_marker" ]]; then
desc="Storage Location - Fixed: other apps reference $app by path. Currently at $dir"
else
desc="Storage Location - Currently at $dir [$(_storageOptionList)]"
fi
local want="${key}=${value} # ${desc}${readonly_marker}"
[[ "$line" == "$want" ]] && return 0 # unchanged: no write, no churn
local escaped_key="${key}"
local tmp; tmp=$(mktemp) || return 1
runCfgOp cat "$cfg" 2>/dev/null > "$tmp" || { rm -f "$tmp"; return 1; }
awk -v k="^${escaped_key}=" -v repl="$want" '
$0 ~ k && !done { print repl; done=1; next }
{ print }
' "$tmp" | runCfgOp tee "$cfg" >/dev/null
rm -f "$tmp"
return 0
}
# Sync every installed app. Called from the regen path; cheap because each app
# short-circuits unless its resolved path or the option list actually changed.
storageSyncAllAppComments()
{
local app
while IFS= read -r app; do
[[ -z "$app" || "$app" == "libreportal" ]] && continue
storageSyncAppComment "$app"
done < <(storageApps)
return 0
}

View File

@ -0,0 +1,133 @@
#!/bin/bash
# Move an installed app's data to a different storage location.
#
# The ordering here is the whole design. Data must be quiescent before it is
# copied (a live copy of a running Postgres is a corrupt copy), the source must
# survive until the destination is verified, and the config must not claim the
# new location until the data is actually there.
#
# 1. resolve + refuse the obvious (same location, not installed, unavailable)
# 2. space check with headroom
# 3. compose down
# 4. pre-move snapshot (default on)
# 5. copy as root — app data holds rootless sub-UID files the manager can
# neither read nor recreate
# 6. verify, THEN remove the source. Never mv semantics that can half-delete
# 7. repoint config + index, bring back up, health-check
#
# Rollback: before step 6 the source is untouched, so failure just restarts the
# app where it was. After step 6 the destination is complete, so failure leaves
# it there and the config is repointed anyway.
storageMoveApp()
{
local app="$1"
local want="$2"
local opts="${3:-}"
if [[ -z "$app" || -z "$want" ]]; then
isError "Usage: storageMoveApp <app> <location> [--no-pre-backup]"
return 1
fi
isHeader "Move $app to storage location '$want'"
# ---- 1. resolve ---------------------------------------------------------
local src_dir dest_root dest_dir
if ! src_dir=$(appDir "$app"); then
isError "$app is on a storage location that is not mounted — mount it first."
return 1
fi
if [[ ! -d "$src_dir" ]]; then
isError "$app is not installed ($src_dir does not exist)."
return 1
fi
if ! dest_root=$(storageLocationPath "$want"); then
isError "No such storage location: $want"
isNotice "Known locations: $(storageList 2>/dev/null | awk 'NR>2{print $2}' | paste -sd, -)"
return 1
fi
if ! storageRootAvailable "$dest_root"; then
isError "Storage location '$want' ($dest_root) is not mounted."
return 1
fi
dest_dir="${dest_root%/}/$app"
if [[ "${src_dir%/}" == "${dest_dir%/}" ]]; then
isNotice "$app is already on '$want' — nothing to do."
return 0
fi
if [[ -e "$dest_dir" ]]; then
isError "Refusing to move — '$dest_dir' already exists."
return 1
fi
# A pinned app must not move: other apps reach it by literal path.
local pin_key="CFG_${app^^}_STORAGE"
if runCfgOp grep -qE "^${pin_key}=.*\*\*READONLY\*\*" "$src_dir/$app.config" 2>/dev/null; then
isError "$app is pinned to the primary location — other apps reference it by path."
return 1
fi
# ---- 2. space, with headroom -------------------------------------------
local need_kb avail_kb
need_kb=$(runFileOp du -sk "$src_dir" 2>/dev/null | awk '{print $1}')
avail_kb=$(df -Pk "$dest_root" 2>/dev/null | awk 'NR==2 {print $4}')
if [[ -n "$need_kb" && -n "$avail_kb" ]]; then
local need_hdr=$(( need_kb + need_kb / 10 ))
if (( avail_kb < need_hdr )); then
isError "Not enough space on '$want': need ~$((need_hdr / 1024)) MiB (10% headroom), have $((avail_kb / 1024)) MiB."
return 1
fi
isNotice "Moving $((need_kb / 1024)) MiB; $((avail_kb / 1024)) MiB free at the destination."
if (( need_kb > 5242880 )); then
isNotice "This is a large app — the copy can take a while and $app stays down until it finishes."
fi
fi
# ---- 3. stop ------------------------------------------------------------
isNotice "Stopping $app — data must be quiescent before it is copied."
dockerComposeDown "$app" || true
# ---- 4. pre-move snapshot ----------------------------------------------
if [[ "$opts" != *--no-pre-backup* ]] && declare -f migratePreBackupDestination >/dev/null 2>&1; then
local bidx
bidx=$(resticEnabledLocations 2>/dev/null | head -1)
if [[ -n "$bidx" ]]; then
isNotice "Taking a safety snapshot before moving."
migratePreBackupDestination "$app" "$bidx" || \
isNotice "Pre-move snapshot failed — continuing (the source is not deleted until the copy verifies)."
else
isNotice "No backup location enabled — skipping the safety snapshot."
fi
fi
# ---- 5/6. copy, verify, then remove the source --------------------------
isNotice "Copying $src_dir -> $dest_dir"
if ! runOwnership app-move "$app" "$dest_root"; then
isError "Copy failed — $app has not been moved. Restarting it where it was."
dockerComposeUp "$app" || true
return 1
fi
# ---- 7. repoint and restart --------------------------------------------
updateConfigOption "$pin_key" "$(storageLocationName "$dest_root")" "$dest_dir/$app.config" >/dev/null 2>&1 || true
storageIndexSet "$app" "$dest_root"
storageCacheReset
local now
now=$(appDir "$app")
if [[ "${now%/}" != "${dest_dir%/}" ]]; then
isError "After the move $app resolves to '$now', not '$dest_dir'. Not starting it — investigate before running anything else."
return 1
fi
declare -f storageSyncAppComment >/dev/null 2>&1 && storageSyncAppComment "$app"
isNotice "Starting $app on its new location."
dockerComposeUpdateAndStartApp "$app" || true
dockerComposeUp "$app" || true
isSuccessful "$app now lives at $dest_dir"
return 0
}

View File

@ -62,6 +62,8 @@ DB_PATH="$SYSTEM_DIR/database.db"
WEBUI_DIR="$CONTAINERS_DIR/libreportal"
TASK_DIR="$WEBUI_DIR/frontend/data/tasks"
DB_CFG="$CONFIGS_DIR/general/general_docker_install"
# Root-owned storage registry — the only authority on which roots may hold apps.
STORAGE_REGISTRY="/usr/local/lib/libreportal/storage.roots"
# Current docker mode, read authoritatively from config (read-only — informs the
# container OWNER choice, not any path).
@ -242,6 +244,84 @@ app_data_remove() {
rm -rf -- "$d"
}
# Move an app directory to another storage root.
#
# Root because it must be: app data holds files owned by rootless sub-UIDs
# (postgres at 231141 and friends) that the manager can neither read nor
# recreate, so an unprivileged copy silently loses them.
#
# The destination root is validated against the ROOT-OWNED storage registry, not
# against anything the caller says — the same trust boundary as everywhere else
# here. A path that is not a registered location is refused outright.
#
# Copy-verify-then-delete, never `mv` across filesystems: a half-completed move
# that has already unlinked the source is unrecoverable, and this runs on the
# only copy of someone's data.
app_move() {
local app="${1:-}" dest_root="${2:-}"
[[ "$app" =~ ^[A-Za-z0-9._-]+$ && "$app" != "." && "$app" != ".." ]] \
|| { echo "libreportal-ownership: invalid app name" >&2; return 1; }
[[ "$app" == "libreportal" ]] \
&& { echo "libreportal-ownership: the WebUI app dir cannot be moved" >&2; return 1; }
[[ -n "$dest_root" && "$dest_root" == /* ]] \
|| { echo "libreportal-ownership: destination must be an absolute path" >&2; return 1; }
dest_root="${dest_root%/}"
# The destination must be a REGISTERED storage root (or the primary one).
local ok=0
[[ "$dest_root" == "$CONTAINERS_DIR" ]] && ok=1
if (( ! ok )) && [[ -r "$STORAGE_REGISTRY" ]]; then
local _id _path _rest
while IFS=$'\t' read -r _id _path _rest || [[ -n "$_id" ]]; do
[[ -z "$_path" || "$_id" == \#* ]] && continue
[[ "${_path%/}" == "$dest_root" ]] && { ok=1; break; }
done < "$STORAGE_REGISTRY"
fi
(( ok )) || { echo "libreportal-ownership: '$dest_root' is not a registered storage location" >&2; return 1; }
# Find the source across every known root.
local src="" root
for root in "$CONTAINERS_DIR" $(awk -F'\t' '$1 !~ /^#/ && $2 != "" {print $2}' "$STORAGE_REGISTRY" 2>/dev/null); do
root="${root%/}"
[[ -d "$root/$app" ]] && { src="$root/$app"; break; }
done
[[ -n "$src" ]] || { echo "libreportal-ownership: no such app dir for '$app'" >&2; return 1; }
local dst="$dest_root/$app"
[[ -e "$dst" ]] && { echo "libreportal-ownership: '$dst' already exists" >&2; return 1; }
[[ "$src" == "$dst" ]] && return 0
# Same filesystem -> rename is atomic and instant. Different -> full copy,
# verified, and only then unlink the source.
local src_dev dst_dev
src_dev=$(stat -c '%d' -- "$src" 2>/dev/null)
dst_dev=$(stat -c '%d' -- "$dest_root" 2>/dev/null)
if [[ -n "$src_dev" && "$src_dev" == "$dst_dev" ]]; then
mv -- "$src" "$dst" || return 1
return 0
fi
cp -a --reflink=auto -- "$src" "$dst" || { rm -rf -- "$dst"; return 1; }
# Verify before deleting anything: file counts and total bytes must match.
local src_n dst_n src_b dst_b
src_n=$(find "$src" -mindepth 1 2>/dev/null | wc -l)
dst_n=$(find "$dst" -mindepth 1 2>/dev/null | wc -l)
src_b=$(du -sb "$src" 2>/dev/null | awk '{print $1}')
dst_b=$(du -sb "$dst" 2>/dev/null | awk '{print $1}')
if [[ "$src_n" != "$dst_n" ]]; then
echo "libreportal-ownership: copy verification failed ($src_n entries at source, $dst_n at destination). Source left intact at $src" >&2
return 1
fi
if [[ -n "$src_b" && -n "$dst_b" && "$src_b" != "$dst_b" ]]; then
echo "libreportal-ownership: copy verification failed ($src_b bytes at source, $dst_b at destination). Source left intact at $src" >&2
return 1
fi
rm -rf -- "$src"
return 0
}
# Chown one LibrePortal-managed file under an app dir to the container owner.
# relpath is validated: no traversal, no absolute path, safe charset only.
app_file() {
@ -268,5 +348,6 @@ case "$action" in
app-data-nobody) app_data_nobody "${1:-}";;
app-data-remove) app_data_remove "${1:-}";;
app-file) app_file "${1:-}" "${2:-}";;
*) echo "usage: libreportal-ownership {reconcile [mode]|traversal|containers-top|backups-top|db-own|app-perms|webui|webui-bind|taskdir|app-data-nobody <app>|app-data-remove <app>|app-file <app> <relpath>}" >&2; exit 2;;
app-move) app_move "${1:-}" "${2:-}";;
*) echo "usage: libreportal-ownership {reconcile [mode]|traversal|containers-top|backups-top|db-own|app-perms|webui|webui-bind|taskdir|app-data-nobody <app>|app-data-remove <app>|app-file <app> <relpath>|app-move <app> <dest-root>}" >&2; exit 2;;
esac

View File

@ -367,6 +367,78 @@ EOF
done < "$loc_cfg"
done
# Storage locations — same shape as the backup ones above, same reason: they
# live at configs/storage/locations/<id>/location.config, a depth the flat
# loop never reaches. Their PATH field carries **READONLY**: it mirrors the
# root-owned registry, and editing config must never be able to move where
# app data lives (that is what `storage add`/`remove` are for).
local sto_cfg sto_advanced sto_readonly
for sto_cfg in "$configs_dir"/storage/locations/*/location.config; do
[[ -f "$sto_cfg" ]] || continue
while IFS= read -r line || [[ -n "$line" ]]; do
[[ -z "$line" || "$line" =~ ^[[:space:]]*# ]] && continue
[[ "$line" =~ ^CFG_STORAGE_LOC_[0-9]+_[A-Z0-9_]+= ]] || continue
var_name="${line%%=*}"
rest="${line#*=}"
if [[ "$rest" == *#* ]]; then
var_value="${rest%%#*}"
comment="${rest#*#}"
else
var_value="$rest"
comment=""
fi
var_value="${var_value//$'\r'/}"
var_value="${var_value%"${var_value##*[![:space:]]}"}"
sto_advanced="false"
title=""; description=""; splitOptions=""
if [[ -n "$comment" ]]; then
comment="${comment#"${comment%%[![:space:]]*}"}"
if [[ "$comment" == *'**ADVANCED**'* ]]; then
sto_advanced="true"
comment="${comment//\*\*ADVANCED\*\*/}"
comment="${comment%"${comment##*[![:space:]]}"}"
fi
splitTitleDesc "$comment"
title="$splitTitle"
description="$splitDesc"
fi
if [[ "$var_value" =~ ^\"(.*)\"$ ]]; then
var_value="${BASH_REMATCH[1]}"
fi
var_value=$(jsonEscape "$var_value")
title=$(jsonEscape "$title")
description=$(jsonEscape "$description")
if [[ $first_config == true ]]; then
first_config=false
printf ' "%s": {\n' "$var_name" >> "$temp_file"
else
printf ' ,"%s": {\n' "$var_name" >> "$temp_file"
fi
printf ' "value": "%s",\n' "$var_value" >> "$temp_file"
printf ' "category": "storage",\n' >> "$temp_file"
printf ' "subcategory": "storage_locations",\n' >> "$temp_file"
printf ' "advanced": %s' "$sto_advanced" >> "$temp_file"
if [[ -n "$title" || -n "$description" || -n "$splitOptions" ]]; then
printf ',\n' >> "$temp_file"
else
printf '\n' >> "$temp_file"
fi
[[ -n "$title" ]] && printf ' "title": "%s",\n' "$title" >> "$temp_file"
[[ -n "$description" ]] && printf ' "description": "%s"' "$description" >> "$temp_file"
if [[ -n "$splitOptions" ]]; then
[[ -n "$description" ]] && printf ',\n' >> "$temp_file"
printf ' "options": %s\n' "$splitOptions" >> "$temp_file"
elif [[ -n "$description" ]]; then
printf '\n' >> "$temp_file"
fi
printf ' }\n' >> "$temp_file"
done < "$sto_cfg"
done
cat >> "$temp_file" << 'EOF'
}