windows.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. _, dataNetclientErr := os.Stat(ncutils.GetNetclientPathSpecific() + "netclient.exe")
  18. _, currentNetclientErr := os.Stat(wdPath + "\\netclient.exe")
  19. if os.IsNotExist(dataNetclientErr) { // check and see if netclient.exe is in appdata
  20. if currentNetclientErr == nil { // copy it if it exists locally
  21. input, err := os.ReadFile(wdPath + "\\netclient.exe")
  22. if err != nil {
  23. log.Println("failed to find netclient.exe")
  24. return
  25. }
  26. if err = os.WriteFile(ncutils.GetNetclientPathSpecific()+"netclient.exe", input, 0644); err != nil {
  27. log.Println("failed to copy netclient.exe to", ncutils.GetNetclientPath())
  28. return
  29. }
  30. } else {
  31. log.Fatalf("[netclient] netclient.exe not found in current working directory: %s \nexiting.", wdPath)
  32. }
  33. }
  34. log.Println("Gravitl Netclient on Windows started")
  35. }