()
| 37 | } |
| 38 | |
| 39 | func (n *NFSServerSetup) Setup() error { |
| 40 | // Check required tools. |
| 41 | if err := checkServerTools(); err != nil { |
| 42 | return err |
| 43 | } |
| 44 | |
| 45 | // Clean nfs dir. |
| 46 | n.nfsDir = filepath.Clean(n.nfsDir) |
| 47 | |
| 48 | // Validate: Dir must exist and be a directory. |
| 49 | if err := n.validateDir(); err != nil { |
| 50 | return err |
| 51 | } |
| 52 | |
| 53 | // Step 0: Remove append-only attribute so we can modify directories. |
| 54 | // A previous setup may have set chattr +a, which blocks chown/chmod. |
| 55 | if err := n.removeAppendOnlyAttribute(); err != nil { |
| 56 | return err |
| 57 | } |
| 58 | |
| 59 | // Step 1: Create celer system user/group if not exists. |
| 60 | if err := createSystemGroupAndUser(nfsUser, ""); err != nil { |
| 61 | return err |
| 62 | } |
| 63 | |
| 64 | // Step 2: Chown -R celer:celer <nfs-dir>. |
| 65 | if err := n.changeDirOwnership(nfsUser); err != nil { |
| 66 | return err |
| 67 | } |
| 68 | |
| 69 | // Step 3: Chmod 02775 on directories (group writable + setgid), chmod 0664 on files. |
| 70 | if err := n.changeModeForDirsFiles(); err != nil { |
| 71 | return err |
| 72 | } |
| 73 | |
| 74 | // Step 5: Add the invoking user to the celer group. |
| 75 | if err := addCurrentUserToGroup(nfsUser); err != nil { |
| 76 | return err |
| 77 | } |
| 78 | |
| 79 | // Step 6: Export NFS config and reload. |
| 80 | if err := n.exportNFSConfig(); err != nil { |
| 81 | return err |
| 82 | } |
| 83 | |
| 84 | // Step 4: Chattr +a on all directories (append-only: allows new files, blocks deletion). |
| 85 | if err := n.assignAppendOnlyAttribute(); err != nil { |
| 86 | return err |
| 87 | } |
| 88 | |
| 89 | // Step 7: Install cron job to keep new directories with append-only attribute. |
| 90 | if err := n.installChattrCronJob(nfsUser); err != nil { |
| 91 | return err |
| 92 | } |
| 93 | |
| 94 | fmt.Println() // Just a blank line. |
| 95 | color.PrintSuccess("NFS cache server setup complete for %q", n.nfsDir) |
| 96 | return nil |
no test coverage detected