package utility import ( "bufio" "os" "regexp" "strings" ) // Not all of these are going to be used, but just in case. This is more of a // reference just for me. I want to be able to support more than just EL for // example and send to the "right" paste bins or some generic one. var ( regexPrettyName = regexp.MustCompile(`^PRETTY_NAME=(.*)$`) regexID = regexp.MustCompile(`^ID=(.*)$`) regexVersionID = regexp.MustCompile(`^VERSION_ID=(.*)$`) regexRockyName = regexp.MustCompile(`^Rocky( Linux)? release`) regexOtherEL = regexp.MustCompile(`^(CentOS|Fedora|Red Hat Enterprise|AlmaLinux|Scientific)( Linux)? release`) regexRedHatName = regexp.MustCompile(`^(Rocky|CentOS|Fedora|Red Hat Enterprise|AlmaLinux|Scientific)( Linux)? release`) VendorName string SystemVersion string SystemPrettyName string ) func SetPasteOnOS() string { file, err := os.Open("/etc/os-release") if err != nil { return "" } defer file.Close() scanner := bufio.NewScanner(file) for scanner.Scan() { if m := regexID.FindStringSubmatch(scanner.Text()); m != nil { VendorName = strings.Trim(m[1], `"`) } } // default is set to rpaste elsewhere switch VendorName { case "rocky": return "rpaste" //setting.PasteBinService = "rpaste" case "redhat", "fedora", "centos", "almalinux", "scientific": return "fpaste" //setting.PasteBinService = "fpaste" } return "rpaste" }