@@ -13,13 +13,14 @@ class LinuxUtil extends UnixUtil
1313 * Get current linux distro name and version.
1414 *
1515 * @noinspection PhpMissingBreakStatementInspection
16- * @return array{dist: string, ver: string} Linux distro info (unknown if not found)
16+ * @return array{dist: string, ver: string, family: string } Linux distro info (unknown if not found)
1717 */
1818 public static function getOSRelease (): array
1919 {
2020 $ ret = [
2121 'dist ' => 'unknown ' ,
2222 'ver ' => 'unknown ' ,
23+ 'family ' => 'unknown ' ,
2324 ];
2425 switch (true ) {
2526 case file_exists ('/etc/centos-release ' ):
@@ -44,6 +45,9 @@ public static function getOSRelease(): array
4445 if (preg_match ('/^ID=(.*)$/ ' , $ line , $ matches )) {
4546 $ ret ['dist ' ] = $ matches [1 ];
4647 }
48+ if (preg_match ('/^ID_LIKE=(.*)$/ ' , $ line , $ matches )) {
49+ $ ret ['family ' ] = $ matches [1 ];
50+ }
4751 if (preg_match ('/^VERSION_ID=(.*)$/ ' , $ line , $ matches )) {
4852 $ ret ['ver ' ] = $ matches [1 ];
4953 }
@@ -103,6 +107,16 @@ public static function getSupportedDistros(): array
103107 ];
104108 }
105109
110+ /**
111+ * Check if current linux distro is debian-based.
112+ */
113+ public static function isDebianDist (): bool
114+ {
115+ $ dist = static ::getOSRelease ()['dist ' ];
116+ $ family = explode (' ' , static ::getOSRelease ()['family ' ]);
117+ return in_array ($ dist , ['debian ' , 'ubuntu ' , 'Deepin ' , 'neon ' ]) || in_array ('debian ' , $ family );
118+ }
119+
106120 /**
107121 * Get libc version string from ldd.
108122 */
0 commit comments