netmaker/netclient/ncwindows/windows.go

46 lines
1.5 KiB
Go
Raw Normal View History

2021-08-31 03:58:23 +08:00
package ncwindows
import (
"log"
"os"
2021-09-20 02:03:47 +08:00
"github.com/gravitl/netmaker/netclient/ncutils"
2021-08-31 03:58:23 +08:00
)
2021-10-09 03:07:12 +08:00
// InitWindows - Initialize windows directory & files and such
2021-08-31 03:58:23 +08:00
func InitWindows() {
2021-09-20 02:03:47 +08:00
_, directoryErr := os.Stat(ncutils.GetNetclientPath()) // Check if data directory exists or not
if os.IsNotExist(directoryErr) { // create a data directory
os.Mkdir(ncutils.GetNetclientPath(), 0755)
2021-08-31 03:58:23 +08:00
}
wdPath, wdErr := os.Getwd() // get the current working directory
if wdErr != nil {
log.Fatal("failed to get current directory..")
}
2021-11-09 01:15:20 +08:00
2022-02-02 13:18:02 +08:00
dataPath := ncutils.GetNetclientPathSpecific() + "netclient.exe"
currentPath := wdPath + "\\netclient.exe"
_, dataNetclientErr := os.Stat(dataPath)
_, currentNetclientErr := os.Stat(currentPath)
if currentPath == dataPath && currentNetclientErr == nil {
ncutils.Log("netclient.exe is in proper location, " + currentPath)
} else if os.IsNotExist(dataNetclientErr) { // check and see if netclient.exe is in appdata
2021-08-31 03:58:23 +08:00
if currentNetclientErr == nil { // copy it if it exists locally
2022-02-02 13:18:02 +08:00
input, err := os.ReadFile(currentPath)
2021-08-31 03:58:23 +08:00
if err != nil {
log.Println("failed to find netclient.exe")
return
}
2022-02-02 13:18:02 +08:00
if err = os.WriteFile(dataPath, input, 0700); err != nil {
2021-09-20 02:03:47 +08:00
log.Println("failed to copy netclient.exe to", ncutils.GetNetclientPath())
2021-08-31 03:58:23 +08:00
return
}
2021-11-09 01:15:20 +08:00
} else {
log.Fatalf("[netclient] netclient.exe not found in current working directory: %s \nexiting.", wdPath)
2021-08-31 03:58:23 +08:00
}
}
log.Println("Gravitl Netclient on Windows started")
}