@@ -22,6 +22,11 @@ class LinuxDebian : LinuxDebianCommon
22
22
new DebianLinuxProgram ( "zulu-8" ) ,
23
23
} ;
24
24
25
+ static readonly Dictionary < string , string > DebianUnstableVersionMap = new Dictionary < string , string > ( StringComparer . OrdinalIgnoreCase ) {
26
+ { "bookworm" , "12" } ,
27
+ { "bookworm/sid" , "12" } ,
28
+ } ;
29
+
25
30
protected Version DebianRelease { get ; private set ; } = new Version ( 0 , 0 ) ;
26
31
protected bool IsTesting { get ; private set ; }
27
32
@@ -42,24 +47,49 @@ protected override void InitializeDependencies ()
42
47
Dependencies . AddRange ( packagesPre10 ) ;
43
48
}
44
49
45
- static bool IsDebian10OrNewer ( string [ ] lines )
50
+ static bool IsDebian10OrNewer ( string ? version )
46
51
{
47
- if ( lines == null || lines . Length < 1 )
48
- return false ;
49
-
50
- string version = lines [ 0 ] . Trim ( ) ;
51
- if ( String . IsNullOrEmpty ( version ) )
52
+ if ( String . IsNullOrEmpty ( version ) ) {
52
53
return false ;
54
+ }
53
55
54
56
return
55
57
version . IndexOf ( "bullseye" , StringComparison . OrdinalIgnoreCase ) >= 0 ||
58
+ version . IndexOf ( "bookworm" , StringComparison . OrdinalIgnoreCase ) >= 0 ||
56
59
version . IndexOf ( "sid" , StringComparison . OrdinalIgnoreCase ) >= 0 ;
57
60
}
58
61
59
- protected override bool InitOS ( )
62
+ static string ? ReadDebianVersion ( )
63
+ {
64
+ if ( ! File . Exists ( DebianVersionPath ) ) {
65
+ return null ;
66
+ }
67
+
68
+ string [ ] lines = File . ReadAllLines ( DebianVersionPath ) ;
69
+ return lines [ 0 ] . Trim ( ) ;
70
+ }
71
+
72
+ static bool IsBookwormSidOrNewer ( string ? debian_version )
60
73
{
61
- if ( ! base . InitOS ( ) )
74
+ if ( String . IsNullOrEmpty ( debian_version ) ) {
62
75
return false ;
76
+ }
77
+
78
+ return debian_version ! . IndexOf ( "bookworm" , StringComparison . OrdinalIgnoreCase ) >= 0 ;
79
+ }
80
+
81
+ protected override bool EnsureVersionInformation ( Context context )
82
+ {
83
+ string ? debian_version = null ;
84
+ if ( String . IsNullOrEmpty ( Release ) ) {
85
+ // Debian/unstable "bookworm" (to become Debian 12 eventually) removed
86
+ // VERSION_ID and VERSION_CODENAME from /etc/os-release, so we need to
87
+ // fake it
88
+ debian_version = ReadDebianVersion ( ) ;
89
+ if ( IsBookwormSidOrNewer ( debian_version ) && DebianUnstableVersionMap . TryGetValue ( debian_version ! , out string unstable_version ) ) {
90
+ Release = unstable_version ;
91
+ } ;
92
+ }
63
93
64
94
Version debianRelease ;
65
95
if ( ! Version . TryParse ( Release , out debianRelease ) ) {
@@ -76,7 +106,11 @@ protected override bool InitOS ()
76
106
}
77
107
78
108
if ( debianRelease . Major < 10 && DerivativeDistro && File . Exists ( DebianVersionPath ) ) {
79
- if ( IsDebian10OrNewer ( File . ReadAllLines ( DebianVersionPath ) ) )
109
+ if ( String . IsNullOrEmpty ( debian_version ) ) {
110
+ debian_version = ReadDebianVersion ( ) ;
111
+ }
112
+
113
+ if ( IsDebian10OrNewer ( debian_version ) )
80
114
debianRelease = new Version ( 10 , 0 ) ; // faking it, but it's ok
81
115
}
82
116
0 commit comments