diff --git a/README.md b/README.md index c4becb0..aa08579 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ The program: - If saving the Samba config or its backup needs admin rights, explains the issue and offers to retry with `sudo`. - Writes a timestamped backup before saving changes. - Can append a CIFS mount entry to `/etc/fstab`, including an inline username and password if that is the setup you want. +- If it updates `/etc/fstab` on a systemd system, it reloads systemd before attempting the mount. If you create a local account for a Samba-authenticated share, you may still need to add the Samba password separately: diff --git a/app.go b/app.go index e88af2a..0012b44 100644 --- a/app.go +++ b/app.go @@ -253,6 +253,9 @@ func (a *App) setupClientMount() error { return err } if mountNow { + if err := a.reloadSystemdIfNeeded(); err != nil { + return err + } if err := a.mountCIFS(cfg.MountPoint); err != nil { return err } @@ -779,6 +782,26 @@ func (a *App) mountCIFS(path string) error { return nil } +func (a *App) reloadSystemdIfNeeded() error { + if _, err := os.Stat("/run/systemd/system"); err != nil { + if os.IsNotExist(err) { + return nil + } + return fmt.Errorf("check for systemd: %w", err) + } + + if a.lookPath != nil { + if _, err := a.lookPath("systemctl"); err != nil { + return nil + } + } + + if err := a.runPrivilegedOrLocal("systemctl", []string{"daemon-reload"}, "Refreshing system mount settings needs administrator permission."); err != nil { + return fmt.Errorf("reload systemd after updating /etc/fstab: %w", err) + } + return nil +} + func (a *App) ensureShareDirectories(doc *Document) error { for _, section := range doc.ShareSections() { cfg := ShareFromSection(section) diff --git a/samba-configer b/samba-configer index 4ab23c4..3b171e5 100755 Binary files a/samba-configer and b/samba-configer differ