This commit is contained in:
@@ -27,8 +27,28 @@ func New() *Service {
|
||||
}
|
||||
|
||||
// execCommand executes a shell command and returns output
|
||||
// For ZFS operations that require elevated privileges, it uses sudo
|
||||
func (s *Service) execCommand(name string, args ...string) (string, error) {
|
||||
cmd := exec.Command(name, args...)
|
||||
// Commands that require root privileges
|
||||
privilegedCommands := []string{"zpool", "zfs"}
|
||||
useSudo := false
|
||||
|
||||
for _, cmd := range privilegedCommands {
|
||||
if strings.Contains(name, cmd) {
|
||||
useSudo = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
var cmd *exec.Cmd
|
||||
if useSudo {
|
||||
// Use sudo for privileged commands
|
||||
sudoArgs := append([]string{name}, args...)
|
||||
cmd = exec.Command("sudo", sudoArgs...)
|
||||
} else {
|
||||
cmd = exec.Command(name, args...)
|
||||
}
|
||||
|
||||
var stdout, stderr bytes.Buffer
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
|
||||
Reference in New Issue
Block a user