2023-08-03 00:42:31 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/quexten/goldwarden/agent/systemauth"
|
|
|
|
"github.com/quexten/goldwarden/browserbiometrics"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func setupPolkit() {
|
2023-08-04 00:44:15 +02:00
|
|
|
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()
|
2023-08-03 00:42:31 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
command := exec.Command("pkexec", "mv", "/tmp/goldwarden-policy", "/usr/share/polkit-1/actions/com.quexten.goldwarden.policy")
|
|
|
|
err = command.Run()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2023-08-04 00:44:15 +02:00
|
|
|
fmt.Println("Polkit setup successfully")
|
|
|
|
}
|
|
|
|
|
|
|
|
func IsPolkitSetup() bool {
|
|
|
|
_, err := os.Stat("/usr/share/polkit-1/actions/com.quexten.goldwarden.policy")
|
|
|
|
return !os.IsNotExist(err)
|
2023-08-03 00:42:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var polkitCmd = &cobra.Command{
|
|
|
|
Use: "polkit",
|
|
|
|
Short: "Sets up polkit",
|
|
|
|
Long: "Sets up polkit",
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
setupPolkit()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
const SYSTEMD_SERVICE = `[Unit]
|
|
|
|
Description="Goldwarden daemon"
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
ExecStart=BINARY_PATH daemonize
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=default.target`
|
|
|
|
|
|
|
|
func setupSystemd() {
|
2023-08-04 00:45:13 +02:00
|
|
|
file, err := os.Create("/tmp/goldwarden.service")
|
2023-08-03 00:42:31 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
path, err := os.Executable()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
file.WriteString(strings.ReplaceAll(SYSTEMD_SERVICE, "BINARY_PATH", path))
|
|
|
|
file.Close()
|
|
|
|
|
2023-09-11 22:47:37 +02:00
|
|
|
userDirectory := os.Getenv("HOME")
|
|
|
|
command := exec.Command("pkexec", "mv", "/tmp/goldwarden.service", userDirectory+"/.config/systemd/user/goldwarden.service")
|
2023-08-03 00:42:31 +02:00
|
|
|
err = command.Run()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2023-08-04 00:44:15 +02:00
|
|
|
command2 := exec.Command("systemctl", "--now", "--user", "enable", "goldwarden.service")
|
|
|
|
err = command2.Run()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Systemd setup successfully")
|
2023-08-03 00:42:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var systemdCmd = &cobra.Command{
|
|
|
|
Use: "systemd",
|
|
|
|
Short: "Sets up systemd autostart",
|
|
|
|
Long: "Sets up systemd autostart",
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
setupSystemd()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var browserbiometricsCmd = &cobra.Command{
|
|
|
|
Use: "browserbiometrics",
|
|
|
|
Short: "Sets up browser biometrics",
|
|
|
|
Long: "Sets up browser biometrics",
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
err := browserbiometrics.DetectAndInstallBrowsers()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error: " + err.Error())
|
|
|
|
} else {
|
|
|
|
fmt.Println("Done.")
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var setupCmd = &cobra.Command{
|
|
|
|
Use: "setup",
|
|
|
|
Short: "Sets up Goldwarden integrations",
|
|
|
|
Long: "Sets up Goldwarden integrations",
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
cmd.Help()
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(setupCmd)
|
|
|
|
setupCmd.AddCommand(polkitCmd)
|
|
|
|
setupCmd.AddCommand(systemdCmd)
|
|
|
|
setupCmd.AddCommand(browserbiometricsCmd)
|
|
|
|
}
|