feat: splitting platforms and maybe fixing shortcut installations as well as admin privileges
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
//go:build linux
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func getInstallDir() (string, error) {
|
||||
return "/opt/logofclient", nil
|
||||
}
|
||||
|
||||
func platformRunPrivileged(config Config, action string) error {
|
||||
// Bereits als root gestartet.
|
||||
if os.Geteuid() == 0 {
|
||||
return runAction(config, action)
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
fmt.Println("Für diese Aktion werden Administratorrechte benötigt.")
|
||||
fmt.Print("Jetzt Administratorrechte anfordern? [J/n]: ")
|
||||
|
||||
var answer string
|
||||
|
||||
if _, err := fmt.Scanln(&answer); err != nil {
|
||||
// Ein leeres Enter kann bei Scanln als Fehler erscheinen.
|
||||
// Das behandeln wir als Zustimmung.
|
||||
answer = ""
|
||||
}
|
||||
|
||||
answer = strings.ToLower(strings.TrimSpace(answer))
|
||||
|
||||
if answer != "" && answer != "j" && answer != "ja" {
|
||||
fmt.Println("Abgebrochen.")
|
||||
return nil
|
||||
}
|
||||
|
||||
exe, err := os.Executable()
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
"Pfad des Installers konnte nicht ermittelt werden: %w",
|
||||
err,
|
||||
)
|
||||
}
|
||||
|
||||
cmd := exec.Command(
|
||||
"sudo",
|
||||
exe,
|
||||
action,
|
||||
)
|
||||
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
return fmt.Errorf(
|
||||
"Ausführung mit Administratorrechten fehlgeschlagen: %w",
|
||||
err,
|
||||
)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user