Przeglądaj źródła

removing automated Windows Daemon install

afeiszli 3 lat temu
rodzic
commit
b10fde47f1

+ 1 - 1
netclient/daemon/common.go

@@ -15,7 +15,7 @@ func InstallDaemon(cfg *config.ClientConfig) error {
 
 	switch os {
 	case "windows":
-		err = SetupWindowsDaemon()
+		//err = SetupWindowsDaemon()
 	case "darwin":
 		err = SetupMacDaemon()
 	case "linux":

+ 0 - 122
netclient/daemon/windows.go

@@ -1,40 +1,12 @@
 package daemon
 
 import (
-	"fmt"
-	"log"
-	"os"
 	"strings"
 
 	"github.com/gravitl/netmaker/logger"
 	"github.com/gravitl/netmaker/netclient/ncutils"
 )
 
-// SetupWindowsDaemon - sets up the Windows daemon service
-func SetupWindowsDaemon() error {
-
-	if !ncutils.FileExists(ncutils.GetNetclientPathSpecific() + "winsw.xml") {
-		if err := writeServiceConfig(); err != nil {
-			return err
-		}
-	}
-
-	if !ncutils.FileExists(ncutils.GetNetclientPathSpecific() + "winsw.exe") {
-		logger.Log(0, "performing first time daemon setup")
-		err := ncutils.GetEmbedded()
-		if err != nil {
-			return err
-		}
-		logger.Log(0, "finished daemon setup")
-	}
-	// install daemon, will not overwrite
-	ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe install`, false)
-	// start daemon, will not restart or start another
-	ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe start`, false)
-	logger.Log(0, strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe start`)
-	return nil
-}
-
 // RestartWindowsDaemon - restarts windows service
 func RestartWindowsDaemon() {
 	StopWindowsDaemon()
@@ -42,38 +14,6 @@ func RestartWindowsDaemon() {
 	ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe start`, false)
 }
 
-// CleanupWindows - cleans up windows files
-func CleanupWindows() {
-	if !ncutils.FileExists(ncutils.GetNetclientPathSpecific() + "winsw.xml") {
-		writeServiceConfig()
-	}
-	StopWindowsDaemon()
-	RemoveWindowsDaemon()
-	os.RemoveAll(ncutils.GetNetclientPath())
-	log.Println("Netclient on Windows, uninstalled")
-}
-
-func writeServiceConfig() error {
-	serviceConfigPath := ncutils.GetNetclientPathSpecific() + "winsw.xml"
-	scriptString := fmt.Sprintf(`<service>
-<id>netclient</id>
-<name>Netclient</name>
-<description>Connects Windows nodes to one or more Netmaker networks.</description>
-<executable>%v</executable>
-<arguments>daemon</arguments>
-<log mode="roll"></log>
-</service>
-`, strings.Replace(ncutils.GetNetclientPathSpecific()+"netclient.exe", `\\`, `\`, -1))
-	if !ncutils.FileExists(serviceConfigPath) {
-		err := os.WriteFile(serviceConfigPath, []byte(scriptString), 0600)
-		if err != nil {
-			return err
-		}
-		logger.Log(0, "wrote the daemon config file to the Netclient directory")
-	}
-	return nil
-}
-
 // == Daemon ==
 
 // StopWindowsDaemon - stops the Windows daemon
@@ -82,65 +22,3 @@ func StopWindowsDaemon() {
 	// stop daemon, will not overwrite
 	ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe stop`, true)
 }
-
-// RemoveWindowsDaemon - removes the Windows daemon
-func RemoveWindowsDaemon() {
-	// uninstall daemon, will not restart or start another
-	ncutils.RunCmd(strings.Replace(ncutils.GetNetclientPathSpecific(), `\\`, `\`, -1)+`winsw.exe uninstall`, true)
-	logger.Log(0, "uninstalled Windows, Netclient daemon")
-}
-
-// func copyWinswOver() error {
-
-// 	input, err := ioutil.ReadFile(".\\winsw.exe")
-// 	if err != nil {
-// 		logger.Log(0, "failed to find winsw.exe")
-// 		return err
-// 	}
-// 	if err = ioutil.WriteFile(ncutils.GetNetclientPathSpecific()+"winsw.exe", input, 0644); err != nil {
-// 		logger.Log(0, "failed to copy winsw.exe to " + ncutils.GetNetclientPath())
-// 		return err
-// 	}
-// 	if err = os.Remove(".\\winsw.exe"); err != nil {
-// 		logger.Log(0, "failed to cleanup local winsw.exe, feel free to delete it")
-// 		return err
-// 	}
-// 	logger.Log(0, "finished copying winsw.exe")
-// 	return nil
-// }
-
-// func downloadWinsw() error {
-// 	fullURLFile := "https://github.com/winsw/winsw/releases/download/v2.11.0/WinSW-x64.exe"
-// 	fileName := "winsw.exe"
-
-// 	// Create the file
-// 	file, err := os.Create(fileName)
-// 	if err != nil {
-// 		logger.Log(0, "could not create file on OS for Winsw")
-// 		return err
-// 	}
-// 	defer file.Close()
-
-// 	client := http.Client{
-// 		CheckRedirect: func(r *http.Request, via []*http.Request) error {
-// 			r.URL.Opaque = r.URL.Path
-// 			return nil
-// 		},
-// 	}
-// 	// Put content on file
-// 	logger.Log(0, "downloading service tool...")
-// 	resp, err := client.Get(fullURLFile)
-// 	if err != nil {
-// 		logger.Log(0, "could not GET Winsw")
-// 		return err
-// 	}
-// 	defer resp.Body.Close()
-
-// 	_, err = io.Copy(file, resp.Body)
-// 	if err != nil {
-// 		logger.Log(0, "could not mount winsw.exe")
-// 		return err
-// 	}
-// 	logger.Log(0, "finished downloading Winsw")
-// 	return nil
-// }

+ 1 - 1
netclient/functions/common.go

@@ -136,7 +136,7 @@ func Uninstall() error {
 	err = nil
 	// clean up OS specific stuff
 	if ncutils.IsWindows() {
-		daemon.CleanupWindows()
+		// daemon.CleanupWindows()
 	} else if ncutils.IsMac() {
 		daemon.CleanupMac()
 	} else if ncutils.IsLinux() {

+ 1 - 1
netclient/ncutils/netclientutils.go

@@ -42,7 +42,7 @@ const NO_DB_RECORDS = "could not find any records"
 const LINUX_APP_DATA_PATH = "/etc/netclient"
 
 // WINDOWS_APP_DATA_PATH - windows path
-const WINDOWS_APP_DATA_PATH = "C:\\ProgramData\\Netclient"
+const WINDOWS_APP_DATA_PATH = "C:\\Program Files (x86)\\Netclient"
 
 // WINDOWS_APP_DATA_PATH - windows path
 //const WINDOWS_WG_DPAPI_PATH = "C:\\Program Files\\WireGuard\\Data\\Configurations"

+ 0 - 5
netclient/ncutils/netclientutils_darwin.go

@@ -23,8 +23,3 @@ func RunCmd(command string, printerr bool) (string, error) {
 func RunCmdFormatted(command string, printerr bool) (string, error) {
 	return "", nil
 }
-
-// GetEmbedded - if files required for MacOS, put here
-func GetEmbedded() error {
-	return nil
-}

+ 0 - 5
netclient/ncutils/netclientutils_freebsd.go

@@ -25,11 +25,6 @@ func RunCmdFormatted(command string, printerr bool) (string, error) {
 	return string(out), err
 }
 
-// GetEmbedded - if files required for freebsd, put here
-func GetEmbedded() error {
-	return nil
-}
-
 // Runs Commands for FreeBSD
 func RunCmd(command string, printerr bool) (string, error) {
 	args := strings.Fields(command)

+ 0 - 5
netclient/ncutils/netclientutils_linux.go

@@ -25,8 +25,3 @@ func RunCmd(command string, printerr bool) (string, error) {
 func RunCmdFormatted(command string, printerr bool) (string, error) {
 	return "", nil
 }
-
-// GetEmbedded - if files required for linux, put here
-func GetEmbedded() error {
-	return nil
-}

+ 0 - 20
netclient/ncutils/netclientutils_windows.go

@@ -1,8 +1,6 @@
 package ncutils
 
 import (
-	"embed"
-	"fmt"
 	"os"
 	"os/exec"
 	"strings"
@@ -11,9 +9,6 @@ import (
 	"github.com/gravitl/netmaker/logger"
 )
 
-//go:embed windowsdaemon/winsw.exe
-var winswContent embed.FS
-
 // RunCmd - runs a local command
 func RunCmd(command string, printerr bool) (string, error) {
 	args := strings.Fields(command)
@@ -44,18 +39,3 @@ func RunCmdFormatted(command string, printerr bool) (string, error) {
 	}
 	return string(out), err
 }
-
-// GetEmbedded - Gets the Windows daemon creator
-func GetEmbedded() error {
-	data, err := winswContent.ReadFile("windowsdaemon/winsw.exe")
-	if err != nil {
-		return err
-	}
-	fileName := fmt.Sprintf("%swinsw.exe", GetNetclientPathSpecific())
-	err = os.WriteFile(fileName, data, 0700)
-	if err != nil {
-		logger.Log(0, "could not mount winsw.exe")
-		return err
-	}
-	return nil
-}