From 304e4b644c47cfbf8bb974f4287f0053821f337c Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 10 Aug 2026 23:08:05 +0000 Subject: [PATCH] Let an already-mounted share be reconfigured instead of blocking on label reuse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Re-running vpn-data-mount for a share that's already mounted hit the label-uniqueness check with no way through it — picking the same share always re-prompted for a label, and the existing label was always already taken by definition, so it just looped rejecting every input. Confirmed live: reported as an infinite "Label 'data1' is already used" loop right after this share had already been mounted in an earlier run. Detect the existing fstab tag for the same host+share up front and reconfigure it in place — currently the one thing safe to redo without touching a working plain mount: the gocryptfs decrypt layer added previously. Skips the label prompt and remount entirely for a share that's already set up. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01H4k6J1qXXyYxhGEgnJaMvn --- services/vpn-data-mount.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/services/vpn-data-mount.sh b/services/vpn-data-mount.sh index e9df47c..d6148ef 100644 --- a/services/vpn-data-mount.sh +++ b/services/vpn-data-mount.sh @@ -332,6 +332,17 @@ _vdm_find_existing_smb_password() { return 1 } +# ── Already mounted? Find its label+mount point instead of re-prompting ─── +# Prints "label|mount_point" if this exact host+share is already tagged in +# /etc/fstab, nothing otherwise. No log_* calls — same $(...) capture +# reason as _vdm_find_existing_smb_password above. +_vdm_find_existing_mount() { + local host="$1" share_name="$2" + grep -E "^${_VDM_TAG_PREFIX} [^ ]+ — ${host}:${share_name} -> " /etc/fstab 2>/dev/null \ + | sed -E "s/^${_VDM_TAG_PREFIX} ([^ ]+) — [^ ]+ -> (.*)\$/\1|\2/" \ + | head -1 +} + # ── Prompt for a password twice, hidden, matching ────────────────────────── # Prints the password on success. No log_* calls — same reason as above; # uses plain stderr output instead so it's visible without corrupting a @@ -648,6 +659,23 @@ _vdm_add_mount() { echo "" log_info "Setting up: [$this_share] -> $this_path" + # Already mounted from an earlier run? Reconfigure it in place + # instead of forcing a new label — this is what "redo it" for an + # existing share means: no remount, no fresh /etc/fstab entry, just + # revisit the one optional step (the decrypt layer) that's actually + # safe to redo without touching an already-working plain mount. + local existing existing_label existing_point + existing="$(_vdm_find_existing_mount "$HOST" "$this_share")" + if [ -n "$existing" ]; then + existing_label="${existing%%|*}" + existing_point="${existing#*|}" + log_info "[$this_share] is already mounted as '$existing_label' at $existing_point." + VDM_LAST_MOUNT_POINT="$existing_point" + picked_any=true + _vdm_setup_decrypt_layer "$HOST" "$SSH_USER" "$existing_label" "$existing_point" + continue + fi + LABEL="" while true; do prompt_text " Local label for this mount:" "$this_share" LABEL