syscheck.go 1.26 KB
Newer Older
1 2 3 4 5 6 7 8
package main

import (
	"fmt"
	"log"
	"os/exec"

	"github.com/blang/semver"
9
	"github.com/fatih/color"
10 11 12
	"github.com/pbnjay/memory"
)

13
const nodejsSemverRange = ">=8.11.4 <11.0.0"
14 15 16 17 18 19 20 21 22 23 24 25 26
const ramMin = 768

// CheckNodeJs checks if Node.js is installed and has minimal supported version
func CheckNodeJs() bool {
	cmd := exec.Command("node", "-v")
	cmdOutput, err := cmd.CombinedOutput()
	if err != nil {
		log.Fatal(err)
	}

	validRange := semver.MustParseRange(nodejsSemverRange)
	nodeVersion, err := semver.ParseTolerant(string(cmdOutput[:]))
	if !validRange(nodeVersion) {
27
		panic(fmt.Errorf(color.RedString("Error: Installed Node.js version %s is not supported! %s\n"), nodeVersion, nodejsSemverRange))
28 29
	}

30
	fmt.Printf(color.GreenString("✔")+" Node.js %s: OK\n", nodeVersion.String())
31 32 33 34 35 36 37 38

	return true
}

// CheckRAM checks if system total RAM meets requirements
func CheckRAM() bool {
	var totalRAM = memory.TotalMemory() / 1024 / 1024
	if totalRAM < ramMin {
39
		panic(fmt.Errorf(color.RedString("Error: System does not meet RAM requirements. %s MB minimum.\n"), ramMin))
40 41
	}

42
	fmt.Printf(color.GreenString("✔")+" Total System RAM %d MB: OK\n", totalRAM)
43 44 45 46 47 48 49 50 51

	return true
}

// CheckNetworkAccess checks if download server can be reached
func CheckNetworkAccess() bool {
	// TODO
	return true
}