53 lines
No EOL
1.1 KiB
Go
53 lines
No EOL
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/user"
|
|
"github.com/go-ini/ini"
|
|
"github.com/shirou/gopsutil/v3/mem"
|
|
)
|
|
|
|
func checkRoot() {
|
|
currentUser, err := user.Current()
|
|
if err != nil {
|
|
fmt.Println("Error getting current user:", err)
|
|
os.Exit(1)
|
|
}
|
|
if currentUser.Uid != "0" {
|
|
fmt.Println("You must be root to run this script")
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func checkSettings() {
|
|
if numberOfContainers < 1 && numberOfContainers > 7 {
|
|
fmt.Println("Number of containers must be between 1 and 7")
|
|
os.Exit(2)
|
|
}
|
|
|
|
}
|
|
|
|
func ReadOSRelease(configfile string) map[string]string {
|
|
cfg, err := ini.Load(configfile)
|
|
if err != nil {
|
|
fmt.Println("Fail to read file: ", err)
|
|
}
|
|
|
|
ConfigParams := make(map[string]string)
|
|
ConfigParams["ID"] = cfg.Section("").Key("ID").String()
|
|
|
|
return ConfigParams
|
|
}
|
|
|
|
func getDistro() string {
|
|
OSInfo := ReadOSRelease("/etc/os-release")
|
|
OSRelease := OSInfo["ID"]
|
|
return OSRelease
|
|
}
|
|
|
|
func getMemory() string {
|
|
system_mem, _ := mem.VirtualMemory()
|
|
mem_gb := fmt.Sprintf("%.2f", (float64(system_mem.Total)/1073741824)*(float64(maxMemAllocPercent)/(float64(numberOfContainers)*100)))
|
|
return mem_gb
|
|
} |