MCPcopy Index your code
hub / github.com/tailscale/tailscale / linuxVersionMeta

Function linuxVersionMeta

hostinfo/hostinfo_linux.go:85–162  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

83}
84
85func linuxVersionMeta() (meta versionMeta) {
86 dist := distro.Get()
87 meta.DistroName = string(dist)
88
89 propFile := "/etc/os-release"
90 switch dist {
91 case distro.Synology:
92 propFile = "/etc.defaults/VERSION"
93 case distro.OpenWrt:
94 propFile = "/etc/openwrt_release"
95 case distro.Unraid:
96 propFile = "/etc/unraid-version"
97 case distro.WDMyCloud:
98 slurp, _ := os.ReadFile("/etc/version")
99 meta.DistroVersion = string(bytes.TrimSpace(slurp))
100 return
101 case distro.QNAP:
102 slurp, _ := os.ReadFile("/etc/version_info")
103 meta.DistroVersion = getQnapQtsVersion(string(slurp))
104 return
105 }
106
107 m := map[string]string{}
108 for lr := range lineiter.File(propFile) {
109 line, err := lr.Value()
110 if err != nil {
111 break
112 }
113 before, after, ok := bytes.Cut(line, []byte{'='})
114 if !ok {
115 continue
116 }
117 k, v := string(before), strings.Trim(string(after), `"'`)
118 m[k] = v
119 }
120
121 if v := m["VERSION_CODENAME"]; v != "" {
122 meta.DistroCodeName = v
123 }
124 if v := m["VERSION_ID"]; v != "" {
125 meta.DistroVersion = v
126 }
127 id := m["ID"]
128 if id != "" {
129 meta.DistroName = id
130 }
131 switch id {
132 case "debian":
133 // Debian's VERSION_ID is just like "11". But /etc/debian_version has "11.5" normally.
134 // Or "bookworm/sid" on sid/testing.
135 slurp, _ := os.ReadFile("/etc/debian_version")
136 if v := string(bytes.TrimSpace(slurp)); v != "" {
137 if '0' <= v[0] && v[0] <= '9' {
138 meta.DistroVersion = v
139 } else if meta.DistroCodeName == "" {
140 meta.DistroCodeName = v
141 }
142 }

Callers

nothing calls this directly

Calls 5

GetFunction · 0.92
FileFunction · 0.92
getQnapQtsVersionFunction · 0.85
ReadFileMethod · 0.65
ValueMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…