mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-12-24 11:51:13 +08:00
hotfix: fix init dir permission deny
This commit is contained in:
@@ -41,7 +41,6 @@ func CmdDaemon(cmdutil.Factory) *cobra.Command {
|
||||
_ = util.CleanupTempKubeConfigFile()
|
||||
} else {
|
||||
go util.StartupPProf(config.PProfPort)
|
||||
config.Init()
|
||||
}
|
||||
return initLogfile(action.GetDaemonLogPath(opt.IsSudo))
|
||||
},
|
||||
|
||||
@@ -19,8 +19,6 @@ import (
|
||||
)
|
||||
|
||||
func NewKubeVPNCommand() *cobra.Command {
|
||||
config.Init()
|
||||
|
||||
var cmd = &cobra.Command{
|
||||
Use: "kubevpn",
|
||||
Short: i18n.T("KubeVPN offers a Cloud-Native Dev Environment that seamlessly connects to your Kubernetes cluster network."),
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/wencaiwulue/kubevpn/v2/pkg/daemon/elevate"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -29,42 +31,25 @@ const (
|
||||
//go:embed config.yaml
|
||||
var config []byte
|
||||
|
||||
func Init() {
|
||||
err := os.MkdirAll(DaemonPath, 0755)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
func init() {
|
||||
if elevate.IsAdmin() {
|
||||
return
|
||||
}
|
||||
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)
|
||||
}
|
||||
err = os.MkdirAll(GetTempPath(), 0755)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = os.Chmod(GetTempPath(), 0755)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
var paths = []string{DaemonPath, PprofPath, GetSyncthingPath(), GetTempPath()}
|
||||
for _, path := range paths {
|
||||
err := os.MkdirAll(path, 0755)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = os.Chmod(path, 0755)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
path := filepath.Join(HomePath, ConfigFile)
|
||||
_, err = os.Stat(path)
|
||||
_, err := os.Stat(path)
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
err = os.WriteFile(path, config, 0644)
|
||||
}
|
||||
|
||||
@@ -11,9 +11,6 @@ const (
|
||||
|
||||
DefaultRemoteDir = "/kubevpn-data"
|
||||
|
||||
// EnvDisableSyncthingLog disable syncthing log, because it can not set output writer, only write os.Stdout or io.Discard
|
||||
EnvDisableSyncthingLog = "LOGGER_DISCARD"
|
||||
|
||||
SyncthingAPIKey = "kubevpn"
|
||||
)
|
||||
|
||||
|
||||
4
pkg/daemon/elevate/config.go
Normal file
4
pkg/daemon/elevate/config.go
Normal file
@@ -0,0 +1,4 @@
|
||||
package elevate
|
||||
|
||||
// EnvDisableSyncthingLog disable syncthing log, because it can not set output writer, only write os.Stdout or io.Discard
|
||||
const EnvDisableSyncthingLog = "LOGGER_DISCARD"
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"golang.org/x/sys/unix"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
|
||||
"github.com/wencaiwulue/kubevpn/v2/pkg/config"
|
||||
plog "github.com/wencaiwulue/kubevpn/v2/pkg/log"
|
||||
)
|
||||
|
||||
@@ -29,7 +28,7 @@ func RunCmdWithElevated(exe string, args []string) error {
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Env = append(os.Environ(), config.EnvDisableSyncthingLog+"=1")
|
||||
cmd.Env = append(os.Environ(), EnvDisableSyncthingLog+"=1")
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -57,7 +56,7 @@ func RunCmd(exe string, args []string) error {
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Env = append(os.Environ(), config.EnvDisableSyncthingLog+"=1")
|
||||
cmd.Env = append(os.Environ(), EnvDisableSyncthingLog+"=1")
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
|
||||
"github.com/wencaiwulue/kubevpn/v2/pkg/config"
|
||||
plog "github.com/wencaiwulue/kubevpn/v2/pkg/log"
|
||||
)
|
||||
|
||||
@@ -45,7 +44,7 @@ func RunCmdWithElevated(exe string, arg []string) error {
|
||||
//https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow
|
||||
var showCmd int32 = 0 //SW_NORMAL
|
||||
|
||||
os.Setenv(config.EnvDisableSyncthingLog, "1")
|
||||
os.Setenv(EnvDisableSyncthingLog, "1")
|
||||
err = windows.ShellExecute(0, verbPtr, exePtr, argPtr, cwdPtr, showCmd)
|
||||
if err != nil {
|
||||
plog.G(context.Background()).Warn(err)
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
|
||||
"github.com/wencaiwulue/kubevpn/v2/pkg/config"
|
||||
plog "github.com/wencaiwulue/kubevpn/v2/pkg/log"
|
||||
)
|
||||
|
||||
@@ -30,7 +29,7 @@ func RunWithElevated() {
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Env = append(os.Environ(), config.EnvDisableSyncthingLog+"=1")
|
||||
cmd.Env = append(os.Environ(), EnvDisableSyncthingLog+"=1")
|
||||
// while send single CTRL+C, command will quit immediately, but output will cut off and print util quit final
|
||||
// so, mute single CTRL+C, let inner command handle single only
|
||||
go func() {
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
|
||||
"github.com/wencaiwulue/kubevpn/v2/pkg/config"
|
||||
plog "github.com/wencaiwulue/kubevpn/v2/pkg/log"
|
||||
)
|
||||
|
||||
@@ -30,7 +29,7 @@ func RunWithElevated() {
|
||||
|
||||
var showCmd int32 = 1 //SW_NORMAL
|
||||
|
||||
os.Setenv(config.EnvDisableSyncthingLog, "1")
|
||||
os.Setenv(EnvDisableSyncthingLog, "1")
|
||||
err := windows.ShellExecute(0, verbPtr, exePtr, argPtr, cwdPtr, showCmd)
|
||||
if err != nil {
|
||||
plog.G(context.Background()).Warn(err)
|
||||
@@ -49,7 +48,7 @@ func RunWithElevatedInnerExec() error {
|
||||
join := strings.Join(append([]string{executable}, os.Args[1:]...), " ")
|
||||
// Powershell Start C:\Users\naison\Desktop\kubevpn-windows-amd64.exe -Verb Runas -Wait -WindowStyle Hidden
|
||||
c, _ := syscall.UTF16PtrFromString(fmt.Sprintf(`%s Start "%s" -Verb Runas`, path, join))
|
||||
env, _ := syscall.UTF16PtrFromString(config.EnvDisableSyncthingLog + "=1")
|
||||
env, _ := syscall.UTF16PtrFromString(EnvDisableSyncthingLog + "=1")
|
||||
err = windows.CreateProcess(nil, c, nil, nil, true, windows.INHERIT_PARENT_AFFINITY, env, nil, &si, &pi)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user