55
66try :
77 from urllib .request import urlopen
8+ from urllib .error import HTTPError , URLError
89except ImportError :
9- from urllib2 import urlopen
10+ from urllib2 import urlopen , HTTPError , URLError
1011
1112__author__ = 'Igor Seletskiy'
1213__copyright__ = "Copyright (c) Cloud Linux GmbH & Cloud Linux Software, Inc"
1819__version__ = '1.0'
1920
2021
22+ SUPPORTED_DISTROS = {
23+ "almalinux" ,
24+ "amzn" ,
25+ "centos" ,
26+ "cloudlinux" ,
27+ "debian" ,
28+ "ol" ,
29+ "raspbian" ,
30+ "rhel" ,
31+ "rocky" ,
32+ "ubuntu" ,
33+ "proxmox" ,
34+ }
35+
36+
2137def get_kernel_hash ():
2238 try :
2339 # noinspection PyCompatibility
@@ -43,13 +59,48 @@ def inside_lxc_container():
4359 return '/lxc/' in open ('/proc/1/cgroup' ).read ()
4460
4561
62+ def get_distro_info ():
63+ """
64+ Get current distribution name and version
65+ :return: distro name or None if detection fails
66+ """
67+
68+ def parse_value (line ):
69+ return line .split ('=' , 1 )[1 ].strip ().strip ('"\' ' )
70+
71+ os_release_path = '/etc/os-release'
72+ if not os .path .exists (os_release_path ):
73+ return None
74+
75+ try :
76+ with open (os_release_path , 'r' ) as f :
77+ for line in f :
78+ line = line .strip ()
79+ if line .startswith ('ID=' ):
80+ return parse_value (line )
81+ except (IOError , OSError ):
82+ return None
83+
84+
85+ def is_distro_supported (distro_name ):
86+ """
87+ Check if the given distro name is supported
88+ """
89+ return distro_name in SUPPORTED_DISTROS
90+
91+
4692def is_compat ():
4793 url = 'http://patches.kernelcare.com/' + get_kernel_hash () + '/version'
4894 try :
4995 urlopen (url )
5096 return True
51- except Exception :
52- return False
97+ except HTTPError as e :
98+ if e .code == 404 :
99+ return False
100+ else :
101+ raise
102+ except URLError :
103+ raise
53104
54105
55106def myprint (silent , message ):
@@ -60,19 +111,41 @@ def myprint(silent, message):
60111def main ():
61112 """
62113 if --silent or -q argument provided, don't print anything, just use exit code
63- otherwise print results (COMPATIBLE or UNSUPPORTED )
114+ otherwise print results (COMPATIBLE or support contact messages )
64115 else exit with 0 if COMPATIBLE, 1 or more otherwise
65116 """
66117 silent = len (sys .argv ) > 1 and (sys .argv [1 ] == '--silent' or sys .argv [1 ] == '-q' )
67118 if inside_vz_container () or inside_lxc_container ():
68119 myprint (silent , "UNSUPPORTED; INSIDE CONTAINER" )
69120 return 2
70- if is_compat ():
71- myprint (silent , "COMPATIBLE" )
72- return 0
73- else :
74- myprint (silent , "UNSUPPORTED" )
75- return 1
121+
122+ try :
123+ if is_compat ():
124+ myprint (silent , "COMPATIBLE" )
125+ return 0
126+ else :
127+ # Handle 404 case - check if distro is supported
128+ distro_name = get_distro_info ()
129+ if distro_name and is_distro_supported (distro_name ):
130+ myprint (silent , "NEEDS REVIEW" )
131+ myprint (
silent ,
"We support your distribution, but we're having trouble detecting your precise kernel configuration. Please, contact CloudLinux Inc. support by email at [email protected] or by request form at https://www.cloudlinux.com/index.php/support" )
132+ return 1
133+ else :
134+ myprint (silent , "NEEDS REVIEW" )
135+ myprint (
silent ,
"Please contact CloudLinux Inc. support by email at [email protected] or by request form at https://www.cloudlinux.com/index.php/support" )
136+ return 1
137+ except HTTPError as e :
138+ myprint (silent , "CONNECTION ERROR; HTTP %d" % e .code )
139+ return 3
140+ except URLError as e :
141+ myprint (silent , "CONNECTION ERROR; %s" % str (e .reason ))
142+ return 3
143+ except (IOError , OSError ) as e :
144+ myprint (silent , "SYSTEM ERROR; %s" % str (e ))
145+ return 4
146+ except Exception as e :
147+ myprint (silent , "UNEXPECTED ERROR; %s" % str (e ))
148+ return 5
76149
77150
78151if __name__ == "__main__" :
0 commit comments