auto daemon-reload where applicable

This commit is contained in:
2026-03-19 19:55:25 +00:00
parent c0ea7bf29e
commit c116ac9444
3 changed files with 24 additions and 0 deletions

View File

@@ -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:

23
app.go
View File

@@ -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)

Binary file not shown.