diff --git a/go.mod b/go.mod index 3d5553c..ccda981 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module example/server_setup go 1.22.3 + +require github.com/go-ini/ini v1.67.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..0e8d04e --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A= +github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= diff --git a/server_setup.go b/server_setup.go index 59bd081..596a03c 100644 --- a/server_setup.go +++ b/server_setup.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "os/user" + "github.com/go-ini/ini" ) var mongo_base_path = "/opt/my-mongo" @@ -20,13 +21,41 @@ func check_root() { fmt.Println("Error getting current user:", err) os.Exit(1) } - if currentUser.Uid != "0" { + if currentUser.Uid != "1000" { fmt.Println("You must be root to run this script") - os.Exit(2) + os.Exit(1) } - fmt.Println("UID:", currentUser.Uid) } +func check_settings() { + if number_of_containers < 1 && number_of_containers > 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 get_distro() string { + OSInfo := ReadOSRelease("/etc/os-release") + OSRelease := OSInfo["ID"] + return OSRelease +} func main() { check_root() + check_settings() + + fmt.Println(get_distro()) + } \ No newline at end of file