From dd20ea9552d1eaa8a04b6a144cfb4eb41af8522d Mon Sep 17 00:00:00 2001 From: vsr Date: Tue, 20 May 2008 12:23:58 +0000 Subject: [PATCH] Unify OS version identification procedure --- ...fic_4.2.xml => config_ScientificSL_4.2.xml | 0 ...fic_4.3.xml => config_ScientificSL_4.3.xml | 0 runInstall | 105 ++++++++++-------- 3 files changed, 61 insertions(+), 44 deletions(-) rename config_Scientific_4.2.xml => config_ScientificSL_4.2.xml (100%) rename config_Scientific_4.3.xml => config_ScientificSL_4.3.xml (100%) diff --git a/config_Scientific_4.2.xml b/config_ScientificSL_4.2.xml similarity index 100% rename from config_Scientific_4.2.xml rename to config_ScientificSL_4.2.xml diff --git a/config_Scientific_4.3.xml b/config_ScientificSL_4.3.xml similarity index 100% rename from config_Scientific_4.3.xml rename to config_ScientificSL_4.3.xml diff --git a/runInstall b/runInstall index bb5bdcc..787cee6 100755 --- a/runInstall +++ b/runInstall @@ -920,6 +920,61 @@ def get_tmp_dir(dir): return tmp_dir return "%s/%s%d"%(dir, dir_prefix, random.randint(range_bottom,range_top)) +#============================================================== +# get_os_release : gets OS release; the OS name looks like +# _[_64] +# for example: +# RedHat_8.0 +# Mandriva_2006.0_64 +#=============================================================== +def get_os_release(): + filename = "/etc/issue" + # --- + plt_name = "unknown" + plt_ver = "" + plt_arch = "" + if os.path.exists(filename): + # --- + f = open(filename) + lines = f.readlines() + f.close() + # --- + regvar = re.compile("(.*)\s+[^\s]*[R|r]elease[^\s]*\s+([\d.]*)") + regvar1 = re.compile("(.*)\s+[^\s]*[L|l][I|i][N|n][U|u][X|x][^\s]*(.*)\s+([\d.]*)\s+") + for l in lines: + res = re.search(regvar, l) + if not res: + res = re.search(regvar1, l) + if res: + plt_name = "".join("".join(res.groups()[:len(res.groups())-1]).split()) + # workaround for Mandrake and other platforms + plt_name = plt_name.replace("Linux", "").replace("linux", "").replace("LINUX", "").strip() + # workaround for SuSe + plt_name = plt_name.replace("Welcometo", "").strip() + # --- + plt_ver = res.group(len(res.groups())) + if re.search(r'x86_64', l): + plt_arch = "64" + pass + # workaround for Red Hat Enterprise + if not plt_arch: + try: + import platform + if platform.machine() == "x86_64": + plt_arch = "64" + pass + pass + except: + pass + pass + break + pass + pass + data = [] + for i in plt_name, plt_ver, plt_arch: + if i: data.append(i) + return "_".join(data) + #------------------------------------------------------------------# # # # EXECUTION STARTS HERE # @@ -937,50 +992,12 @@ if __name__ == "__main__": # define xml file to be used if (xml_file is None): - plt_name = "" - plt_ver = "" - plt_bit = "" - xml_file_name = "config.xml" - if os.path.exists("/etc/fedora-release"): - # - Fedora Core 4 - plt_name = "Fedora" - data = open("/etc/fedora-release").readline() - res = re.search(r'Fedora.*release\s+([\d.]*)', data) - if res: - plt_ver = res.group(1) - elif os.path.exists("/etc/redhat-release"): - # - Red Hat Linux 8.0 - # - Red Hat Linux 9 - # - Mandrake Linux 10.1 - # - Scientific Linux 3.0.5 - # - Mandriva 2006.0 32bit/64bit - data = open("/etc/redhat-release").readline() - res = re.search(r'(.*)[L|l]inux.*release\s+([\d.]*)', data) - if res: - plt_name = "".join(res.group(1).split()) - plt_ver = res.group(2) - if re.search(r'x86_64', data): - plt_bit = "_64" - elif os.path.exists("/etc/debian_version"): - # - Debian 3.1 - plt_name = "Debian" - plt_ver = open("/etc/debian_version").readline().strip() - elif os.path.exists("/etc/mandriva-release"): - # - Mandriva 2006 (an additional check if above check fails) - data = open("/etc/mandriva-release").readline() - res = re.search(r'(.*)[L|l]inux.*release\s+([\d.]*)', data) - if res: - plt_name = "".join(res.group(1).split()) - plt_ver = res.group(2) - if re.search(r'x86_64', data): - plt_bit = "_64" - pass - _xml_file_name = "config_%s_%s%s.xml"%(plt_name, plt_ver, plt_bit) - if plt_name and plt_ver and os.path.exists("%s/%s"%(cur_dir, _xml_file_name)): - xml_file_name = _xml_file_name - else: - msg = "Not supported Linux platform!\n" - msg += "Trying to use default configuration file!" + os_release = get_os_release() + xml_file_name = "config_%s.xml"%(os_release) + if not os.path.exists("%s/%s"%(cur_dir, xml_file_name)): + xml_file_name = "config.xml" + msg = "Not supported Linux platform: %s!\n" % " ".join(os_release.split("_")) + msg += "Default configuration file is used!" warning(msg) xml_file = "%s/%s"%(cur_dir, xml_file_name) -- 2.39.2