windows.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package ncwindows
  2. import (
  3. "log"
  4. "os"
  5. "github.com/gravitl/netmaker/logger"
  6. "github.com/gravitl/netmaker/netclient/ncutils"
  7. )
  8. // InitWindows - Initialize windows directory & files and such
  9. func InitWindows() {
  10. _, directoryErr := os.Stat(ncutils.GetNetclientPath()) // Check if data directory exists or not
  11. if os.IsNotExist(directoryErr) { // create a data directory
  12. os.Mkdir(ncutils.GetNetclientPath(), 0755)
  13. }
  14. wdPath, wdErr := os.Getwd() // get the current working directory
  15. if wdErr != nil {
  16. log.Fatal("failed to get current directory..")
  17. }
  18. dataPath := ncutils.GetNetclientPathSpecific() + "netclient.exe"
  19. currentPath := wdPath + "\\netclient.exe"
  20. _, dataNetclientErr := os.Stat(dataPath)
  21. _, currentNetclientErr := os.Stat(currentPath)
  22. if currentPath == dataPath && currentNetclientErr == nil {
  23. logger.Log(0, "netclient.exe is in proper location, "+currentPath)
  24. } else if os.IsNotExist(dataNetclientErr) { // check and see if netclient.exe is in appdata
  25. if currentNetclientErr == nil { // copy it if it exists locally
  26. input, err := os.ReadFile(currentPath)
  27. if err != nil {
  28. log.Println("failed to find netclient.exe")
  29. return
  30. }
  31. if err = os.WriteFile(dataPath, input, 0700); err != nil {
  32. log.Println("failed to copy netclient.exe to", ncutils.GetNetclientPath())
  33. return
  34. }
  35. } else {
  36. log.Fatalf("[netclient] netclient.exe not found in current working directory: %s \nexiting.", wdPath)
  37. }
  38. }
  39. log.Println("Gravitl Netclient on Windows started")
  40. }