windows.go 1.5 KB

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