private static IdVersionPair ParseOsReleaseFile() { Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)); IdVersionPair ret = new IdVersionPair(); ret.Id = ""; ret.VersionId = ""; if (File.Exists("/etc/os-release")) { foreach (string line in File.ReadLines("/etc/os-release")) { if (line.StartsWith("ID=", System.StringComparison.Ordinal)) { ret.Id = line.Substring("ID=".Length); } else if (line.StartsWith("VERSION_ID=", System.StringComparison.Ordinal)) { ret.VersionId = line.Substring("VERSION_ID=".Length); } } } string versionId = ret.VersionId; if (versionId.Length >= 2 && versionId[0] == '"' && versionId[versionId.Length - 1] == '"') { // Remove Quotes. ret.VersionId = versionId.Substring(1, versionId.Length - 2); } return ret; }
private static bool IsDistroAndVersion(string distroId, string versionId) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { IdVersionPair v = ParseOsReleaseFile(); if (v.Id == distroId && v.VersionId == versionId) { return(true); } } return(false); }
private static bool GetIsUbuntu(string versionId) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { IdVersionPair v = ParseOsReleaseFile(); if (v.Id == "ubuntu" && v.VersionId == versionId) { return(true); } } return(false); }
private static IdVersionPair ParseOsReleaseFile() { Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)); IdVersionPair ret = new IdVersionPair(); ret.Id = ""; ret.VersionId = ""; if (File.Exists("/etc/os-release")) { foreach (string line in File.ReadLines("/etc/os-release")) { if (line.StartsWith("ID=", System.StringComparison.Ordinal)) { ret.Id = line.Substring("ID=".Length); } else if (line.StartsWith("VERSION_ID=", System.StringComparison.Ordinal)) { ret.VersionId = line.Substring("VERSION_ID=".Length); } } } string versionId = ret.VersionId; if (versionId.Length >= 2 && versionId[0] == '"' && versionId[versionId.Length - 1] == '"') { // Remove quotes. ret.VersionId = versionId.Substring(1, versionId.Length - 2); } if (ret.Id.Length >= 2 && ret.Id[0] == '"' && ret.Id[ret.Id.Length - 1] == '"') { // Remove quotes. ret.Id = ret.Id.Substring(1, ret.Id.Length - 2); } return(ret); }