You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.3 KiB

  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "os/exec"
  6. "github.com/blang/semver"
  7. "github.com/fatih/color"
  8. "github.com/pbnjay/memory"
  9. )
  10. const nodejsSemverRange = ">=8.11.4 <11.0.0"
  11. const ramMin = 768
  12. // CheckNodeJs checks if Node.js is installed and has minimal supported version
  13. func CheckNodeJs() bool {
  14. cmd := exec.Command("node", "-v")
  15. cmdOutput, err := cmd.CombinedOutput()
  16. if err != nil {
  17. log.Fatal(err)
  18. }
  19. validRange := semver.MustParseRange(nodejsSemverRange)
  20. nodeVersion, err := semver.ParseTolerant(string(cmdOutput[:]))
  21. if !validRange(nodeVersion) {
  22. panic(fmt.Errorf(color.RedString("Error: Installed Node.js version %s is not supported! %s\n"), nodeVersion, nodejsSemverRange))
  23. }
  24. fmt.Printf(color.GreenString("✔")+" Node.js %s: OK\n", nodeVersion.String())
  25. return true
  26. }
  27. // CheckRAM checks if system total RAM meets requirements
  28. func CheckRAM() bool {
  29. var totalRAM = memory.TotalMemory() / 1024 / 1024
  30. if totalRAM < ramMin {
  31. panic(fmt.Errorf(color.RedString("Error: System does not meet RAM requirements. %s MB minimum.\n"), ramMin))
  32. }
  33. fmt.Printf(color.GreenString("✔")+" Total System RAM %d MB: OK\n", totalRAM)
  34. return true
  35. }
  36. // CheckNetworkAccess checks if download server can be reached
  37. func CheckNetworkAccess() bool {
  38. // TODO
  39. return true
  40. }