- Replace log.Fatalln in goroutines with error returns collected via mutex-protected slice, checked at barrier points and after final wait. - Fix WaitGroup race between mountDrive and mountBindfs by removing the separate Add/Done pair and calling mountBindfs as a plain function. - Fix encrypted+already-decrypted path skipping the mount step entirely. - Add LUKS cleanup (cryptsetup close) when mount fails after decryption. - Close cryptsetup stdin pipe after writing password to prevent hangs. - Only pass -o to mount when Flags is non-empty. - Support RAID_MOUNT_ENCRYPTION_PASSWORD env var as alternative to the command-line flag which is visible in the process list. - Replace deprecated ioutil.ReadFile with os.ReadFile. - Standardize error reporting on log package, remove mixed fmt.Printf. - Fix config path resolution to check flag emptiness before stat. - Add parallel semantics documentation to raidtab.example.
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
// Flags holds configuration options for CLI execution.
|
|
type Flags struct {
|
|
ConfigPath string
|
|
EncryptionKey string
|
|
EncryptionPassword string
|
|
}
|
|
|
|
// Init parses configuration options from command-line flags.
|
|
func (f *Flags) Init() {
|
|
flag.Usage = func() {
|
|
fmt.Printf("raid-mount: Mounts raid drives and starts services\n\nUsage:\n")
|
|
flag.PrintDefaults()
|
|
}
|
|
|
|
var printVersion bool
|
|
flag.BoolVar(&printVersion, "v", false, "Print version")
|
|
|
|
var usage string
|
|
usage = "Load configuration from `FILE`"
|
|
flag.StringVar(&f.ConfigPath, "config", "", usage)
|
|
flag.StringVar(&f.ConfigPath, "c", "", usage+" (shorthand)")
|
|
|
|
flag.StringVar(&f.EncryptionKey, "encryption-key", "", "Keyfile to decrypt drives")
|
|
usage = "Password to decrypt drives (visible in process list; prefer RAID_MOUNT_ENCRYPTION_PASSWORD env var)"
|
|
flag.StringVar(&f.EncryptionPassword, "encryption-password", "", usage)
|
|
flag.StringVar(&f.EncryptionPassword, "p", "", usage+" (shorthand)")
|
|
|
|
flag.Parse()
|
|
|
|
if printVersion {
|
|
fmt.Println("raid-mount: 0.1")
|
|
os.Exit(0)
|
|
}
|
|
}
|