From 1724096ea771d21f56c25fa322f4c2f94b8c46b9 Mon Sep 17 00:00:00 2001 From: he Date: Fri, 14 Aug 2026 10:24:02 -0400 Subject: [PATCH] =?UTF-8?q?fix:=20share=20smb=20client=20list=20=E2=80=94?= =?UTF-8?q?=20show=20persistent=20automount=20units?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit persist uses x-systemd.automount, so the CIFS share is never actually mounted until first access and findmnt -t cifs stays empty — list reported 'No SMB mounts' despite configured persistent units. list now also scans $UNIT_DIR/*.mount for Type=cifs and reports them under 'Persistent (automount)' (where, what). Empty output still prints 'No SMB mounts'. --- DOC/AGENT_Context_Project.md | 2 +- DOC/POS.md | 2 +- DOC/howto/share.md | 9 +++++---- bin/pos-share-smb-client | 29 ++++++++++++++++++++++++----- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/DOC/AGENT_Context_Project.md b/DOC/AGENT_Context_Project.md index f54cc05..f3b6b2e 100644 --- a/DOC/AGENT_Context_Project.md +++ b/DOC/AGENT_Context_Project.md @@ -604,7 +604,7 @@ Use conventional prefixes: `feat:`, `fix:`, `docs:`, `refactor:`, `chore:` | `bin/pos-network-scan` | 271 | Parallel ping sweep of CIDR | | `bin/pos-share-nfs-client` | 138 | Mount NFS shares (ephemeral or persistent systemd mount units) | | `bin/pos-share-nfs-server` | 134 | Manage the NFS kernel server (status, share/unshare exports, enable/disable) | -| `bin/pos-share-smb-client` | 183 | Mount SMB/CIFS shares (ephemeral or persistent systemd mount units) | +| `bin/pos-share-smb-client` | 202 | Mount SMB/CIFS shares (ephemeral or persistent systemd mount units) | | `bin/pos-share-smb-server` | 253 | Manage the Samba server (status, share/unshare exports, users, enable/disable) | | `bin/pos-share-usb-server` | 218 | USB Redirector server control (--ls, --share; prompts when args omitted) | | `bin/pos-ssh-load-keys` | 31 | Load all SSH keys into the agent | diff --git a/DOC/POS.md b/DOC/POS.md index 54a7610..157d504 100644 --- a/DOC/POS.md +++ b/DOC/POS.md @@ -255,7 +255,7 @@ Subcommands that need input prompt interactively when args are omitted. | `pos share nfs server ` | `bin/pos-share-nfs-server` | Manage the NFS kernel server: `status`, `share [client]`, `unshare `, `list`, `reload`, `enable`, `disable` | Requires `nfs-kernel-server` (added to `preinstall.sh` PACKAGES). Exports live in `/etc/exports`; `share` is idempotent (replaces any existing line for the path) and runs `exportfs -ra`. Default client `*(rw,sync,no_subtree_check)` — the tool warns you to restrict it; help prints Tailscale CGNAT (`100.64.0.0/10`), WireGuard (`10.10.0.0/24`) and LAN examples. Mutating commands announce via `lib/notify.sh` | | `pos share nfs client ` | `bin/pos-share-nfs-client` | Mount and manage NFS shares: `mount `, `unmount `, `list`, `persist `, `unpersist ` | Requires `nfs-common` (added to `preinstall.sh` PACKAGES). `persist` writes a systemd `.mount` unit (`systemd-escape --path --suffix=mount`) with `After=network-online.target` / `Wants=network-online.target` — mounts only once all interfaces are up, no fstab edits to break boot — then `daemon-reload` + `enable --now`. `unpersist` stops/disables/removes the unit. `mount`/`persist` announce via `lib/notify.sh` | | `pos share smb server ` | `bin/pos-share-smb-server` | Manage the Samba server: `status`, `share [name] [--read-only|--guest|--users u1,u2]`, `unshare `, `list`, `adduser `, `deluser `, `reload`, `enable`, `disable` | Requires `samba` (added to `preinstall.sh` PACKAGES). Shares are idempotent marker blocks (`# >>> pos-managed share: ` … `# <<< end pos-managed share`) in `/etc/samba/smb.conf` — hand edits outside the markers survive; `share` validates with `testparm` before applying and hot-reloads via `smbcontrol smbd reload-config`. Defaults rw + browsable; warns when unrestricted (guest or no `valid users`). `adduser`/`deluser` manage Samba accounts via `smbpasswd`. Mutating commands announce via `lib/notify.sh` | -| `pos share smb client ` | `bin/pos-share-smb-client` | Mount and manage SMB/CIFS shares: `mount [user]`, `unmount `, `list`, `persist [user]`, `unpersist ` | Requires `cifs-utils` (added to `preinstall.sh` PACKAGES). With a user you are prompted for the Samba password — one-shot mounts use a throwaway chmod-600 credentials file, `persist` keeps one at `/etc/samba/credentials/` (chmod 600). `persist` writes a systemd `.mount` unit (`systemd-escape --path --suffix=mount`) with `x-systemd.automount` + `_netdev` — mounts on first access, never blocks boot — then `daemon-reload` + `enable --now`. `unpersist` stops/disables/removes the unit + credentials. `mount`/`persist` announce via `lib/notify.sh` | +| `pos share smb client ` | `bin/pos-share-smb-client` | Mount and manage SMB/CIFS shares: `mount [user]`, `unmount `, `list`, `persist [user]`, `unpersist ` | Requires `cifs-utils` (added to `preinstall.sh` PACKAGES). With a user you are prompted for the Samba password — one-shot mounts use a throwaway chmod-600 credentials file, `persist` keeps one at `/etc/samba/credentials/` (chmod 600). `persist` writes a systemd `.mount` unit (`systemd-escape --path --suffix=mount`) with `x-systemd.automount` + `_netdev` — mounts on first access, never blocks boot — then `daemon-reload` + `enable --now`. `unpersist` stops/disables/removes the unit + credentials. `list` shows active mounts (`findmnt -t cifs`) **and** persistent units (as automount shares aren't mounted until first access, they'd otherwise be invisible). `mount`/`persist` announce via `lib/notify.sh` | ### communication diff --git a/DOC/howto/share.md b/DOC/howto/share.md index 85d4437..7712c78 100644 --- a/DOC/howto/share.md +++ b/DOC/howto/share.md @@ -220,7 +220,7 @@ Requires `cifs-utils` (in `preinstall.sh` PACKAGES). pos share smb client mount //100.100.100.1/media /mnt/smb/media # guest pos share smb client mount //100.100.100.1/media /mnt/smb/media bob # prompts for password pos share smb client persist //100.100.100.1/media /mnt/smb/media bob # persistent (systemd) -pos share smb client list # active SMB mounts +pos share smb client list # active + persistent SMB mounts pos share smb client unmount /mnt/smb/media pos share smb client unpersist /mnt/smb/media # remove the unit ``` @@ -253,9 +253,10 @@ fstab it could). `enable --now` arms the automount immediately. server and re-run with the right user - Mount fails with `NT_STATUS_ACCESS_DENIED` on a guest mount → the server share has no `guest ok`; use a user or add `--guest` on the server -- Persistent mount doesn't appear until accessed → intended (`x-systemd.automount`); - `pos share smb client list` only shows actively mounted shares, access the - directory to trigger the mount +- Persistent mount doesn't appear under "Active mounts" until accessed → + intended (`x-systemd.automount`); `pos share smb client list` now also lists + persistent units under "Persistent (automount)", so the configured shares are + visible even before their first access --- diff --git a/bin/pos-share-smb-client b/bin/pos-share-smb-client index aae6eb6..cdb4cca 100755 --- a/bin/pos-share-smb-client +++ b/bin/pos-share-smb-client @@ -19,7 +19,7 @@ Mount and manage SMB/CIFS shares from remote servers (cifs-utils). Commands: mount [user] One-shot mount (creates local-dir if needed) unmount Unmount the share - list Show active SMB mounts + list Show active + persistent SMB mounts persist [user] Persistent mount via a systemd .mount unit (automount — never blocks boot) unpersist Stop, disable and remove the mount unit @@ -108,11 +108,30 @@ case "$cmd" in ;; list) - if findmnt -t cifs >/dev/null 2>&1; then - findmnt -t cifs - else - echo "No SMB mounts" + found=0 + active_mounts="$(findmnt -t cifs 2>/dev/null || true)" + if [ -n "$active_mounts" ]; then + printf 'Active mounts:\n' + printf '%s\n' "$active_mounts" + found=1 fi + persistent=() + for unit in "${UNIT_DIR}"/*.mount; do + [ -e "$unit" ] || continue + grep -q '^Type=cifs$' "$unit" || continue + what="$(sed -n 's/^What=//p' "$unit")" + where="$(sed -n 's/^Where=//p' "$unit")" + [ -n "$what" ] && [ -n "$where" ] || continue + persistent+=("$where|$what") + done + if [ "${#persistent[@]}" -gt 0 ]; then + found=1 + printf 'Persistent (automount):\n' + for entry in "${persistent[@]}"; do + printf ' %-44s %s\n' "${entry%%|*}" "${entry#*|}" + done + fi + [ "$found" -eq 1 ] || echo "No SMB mounts" ;; persist)