Skip to content

Commit

Permalink
system: create missing users during restore
Browse files Browse the repository at this point in the history
  • Loading branch information
sj14 committed May 5, 2024
1 parent d29d94a commit 2834b43
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions controller/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"math/rand/v2"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -108,6 +109,37 @@ func (c *Controller) SystemRestore(backupDir string, unplayed, unfav bool) error
return err
}

var backupUsernames []string
for _, dirEntry := range dirEntries {
backupUsernames = append(backupUsernames, dirEntry.Name())
}

// create missing users
// TODO: use user.json from backup for settings (e.g. admin, hidden, disabled, ...)
for _, backupUser := range backupUsernames {
found := false
for _, systemUser := range users {
if systemUser.GetName() == backupUser {
found = true
break
}
}
if !found {
pass := fmt.Sprint(rand.Int())
fmt.Printf("creating new user %q with (unsafe) password %q\n", backupUser, pass)
err := c.UserAdd(backupUser, pass)
if err != nil {
return err
}
}
}

// reload users as missing ones might have been created
users, _, err = c.client.UserAPI.GetUsers(c.ctx).Execute()
if err != nil {
return err
}

for _, dirEntry := range dirEntries {
userName := dirEntry.Name()

Expand Down

0 comments on commit 2834b43

Please sign in to comment.