Improve polkit setup

This commit is contained in:
Bernd Schoolmann 2023-08-04 00:44:15 +02:00
parent 51b50ce894
commit 8b4a76c20b
No known key found for this signature in database
2 changed files with 30 additions and 4 deletions

View File

@ -12,12 +12,18 @@ import (
)
func setupPolkit() {
file, err := os.OpenFile("/tmp/goldwarden-policy", os.O_CREATE, 0644)
file, err := os.Create("/tmp/goldwarden-policy")
if err != nil {
panic(err)
}
_, err = file.WriteString(systemauth.POLICY)
if err != nil {
panic(err)
}
err = file.Close()
if err != nil {
panic(err)
}
file.WriteString(systemauth.POLICY)
file.Close()
command := exec.Command("pkexec", "mv", "/tmp/goldwarden-policy", "/usr/share/polkit-1/actions/com.quexten.goldwarden.policy")
err = command.Run()
@ -25,7 +31,12 @@ func setupPolkit() {
panic(err)
}
os.Remove("/tmp/goldwarden-policy")
fmt.Println("Polkit setup successfully")
}
func IsPolkitSetup() bool {
_, err := os.Stat("/usr/share/polkit-1/actions/com.quexten.goldwarden.policy")
return !os.IsNotExist(err)
}
var polkitCmd = &cobra.Command{
@ -67,6 +78,14 @@ func setupSystemd() {
}
os.Remove("/tmp/goldwarden.service")
command2 := exec.Command("systemctl", "--now", "--user", "enable", "goldwarden.service")
err = command2.Run()
if err != nil {
panic(err)
}
fmt.Println("Systemd setup successfully")
}
var systemdCmd = &cobra.Command{

View File

@ -1,8 +1,10 @@
package main
import (
"fmt"
"os"
"strings"
"time"
"github.com/quexten/goldwarden/browserbiometrics"
"github.com/quexten/goldwarden/cmd"
@ -14,5 +16,10 @@ func main() {
return
}
if !cmd.IsPolkitSetup() {
fmt.Println("Polkit is not setup. Run 'goldwarden setup polkit' to set it up.")
time.Sleep(3 * time.Second)
}
cmd.Execute()
}