zookeeper/distro.go

69 lines
1.6 KiB
Go
Raw Normal View History

2024-11-15 18:49:52 -06:00
// Copyright 2016 The go-qemu Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"bufio"
"fmt"
"os"
"runtime"
"strings"
)
func initDistro() string {
switch runtime.GOOS {
case "windows":
return "windows"
case "macos":
return "macos"
case "linux":
// Detect the Linux distribution
distro := detectDistro()
if distro == "" {
fmt.Println("Unable to detect Linux distribution.")
distro = "fixme"
}
fmt.Printf("Detected distribution: %s\n", distro)
return distro
default:
return runtime.GOOS
}
}
// detectDistro returns the Linux distribution name (if possible)
func detectDistro() string {
// Check if we're on Linux
// Try to read /etc/os-release to determine the distro
file, err := os.Open("/etc/os-release")
if err != nil {
return ""
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "ID=") {
parts := strings.SplitN(line, "=", 2)
if len(parts) == 2 {
return strings.Trim(parts[1], `"`)
}
}
}
return ""
}