mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-09-26 19:31:17 +08:00
88 lines
1.4 KiB
Go
88 lines
1.4 KiB
Go
package config
|
|
|
|
import (
|
|
_ "embed"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
const (
|
|
HOME = ".kubevpn"
|
|
Daemon = "daemon"
|
|
|
|
SockPath = "daemon.sock"
|
|
SudoSockPath = "sudo_daemon.sock"
|
|
|
|
PidPath = "daemon.pid"
|
|
SudoPidPath = "sudo_daemon.pid"
|
|
|
|
LogFile = "daemon.log"
|
|
|
|
ConfigFile = "config.yaml"
|
|
)
|
|
|
|
//go:embed config.yaml
|
|
var config []byte
|
|
|
|
func init() {
|
|
err := os.MkdirAll(DaemonPath, 0755)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
err = os.Chmod(DaemonPath, 0755)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
err = os.MkdirAll(PprofPath, 0755)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
err = os.Chmod(PprofPath, 0755)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
err = os.MkdirAll(GetSyncthingPath(), 0755)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
err = os.Chmod(GetSyncthingPath(), 0755)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
path := filepath.Join(HomePath, ConfigFile)
|
|
_, err = os.Stat(path)
|
|
if errors.Is(err, os.ErrNotExist) {
|
|
err = os.WriteFile(path, config, 0644)
|
|
}
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func GetSockPath(isSudo bool) string {
|
|
name := SockPath
|
|
if isSudo {
|
|
name = SudoSockPath
|
|
}
|
|
return filepath.Join(DaemonPath, name)
|
|
}
|
|
|
|
func GetPidPath(isSudo bool) string {
|
|
name := PidPath
|
|
if isSudo {
|
|
name = SudoPidPath
|
|
}
|
|
return filepath.Join(DaemonPath, name)
|
|
}
|
|
|
|
func GetSyncthingPath() string {
|
|
return filepath.Join(DaemonPath, SyncthingDir)
|
|
}
|
|
|
|
func GetConfigFilePath() string {
|
|
return filepath.Join(HomePath, ConfigFile)
|
|
}
|