add distro detection function
This commit is contained in:
parent
d072aa36ae
commit
31bca6e058
3 changed files with 36 additions and 3 deletions
2
go.mod
2
go.mod
|
@ -1,3 +1,5 @@
|
|||
module example/server_setup
|
||||
|
||||
go 1.22.3
|
||||
|
||||
require github.com/go-ini/ini v1.67.0
|
||||
|
|
2
go.sum
Normal file
2
go.sum
Normal file
|
@ -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=
|
|
@ -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())
|
||||
|
||||
}
|
Loading…
Reference in a new issue