From f41d0b1c648e0b783fcc62f9008559950934b357 Mon Sep 17 00:00:00 2001 From: smj01095381 Date: Tue, 1 Aug 2023 15:34:31 +0800 Subject: [PATCH] Supports different Anolis OS version for getting mount points by lsblk --- ancert | 3 +++ lib/utils.py | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ancert b/ancert index 0152b77..b97d226 100755 --- a/ancert +++ b/ancert @@ -127,6 +127,9 @@ def main(args): if args.category == 'System': print(e) return 1 + except RunCommandError as e: + print(e) + return 1 else: save_device_info(selected_components, dstree, args, logdir) diff --git a/lib/utils.py b/lib/utils.py index 68258f5..68b8499 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -385,6 +385,14 @@ def get_os_version(): print('OS Relase: %s' % re.search('PRETTY_NAME.*', output.strip()).group().split('"')[-2]) +def get_dist_info(): + cmd = 'rpm -E %{?dist}' + _, output = run_local_cmd(cmd, exit_msg='Failed to get dist info!', shell=True) + if output: + return output.strip().replace('\n', '') + raise RunCommandError('Nothig to get, please check it by runnig %s manually' % cmd) + + def has_mount_partition(devname): cmd = 'mount | grep "^%s"' % devname rc, output = run_local_cmd(cmd, shell=True) @@ -394,7 +402,11 @@ def has_mount_partition(devname): def has_swap_partition(devpath): - cmd = 'lsblk %s -no MOUNTPOINTS | grep SWAP' % devpath + # Supports different Anolis OS version for getting mount points by lsblk + if int(get_dist_info().replace('.an', '')) < 23: + cmd = 'lsblk %s -no MOUNTPOINT | grep SWAP' % devpath + else: + cmd = 'lsblk %s -no MOUNTPOINTS | grep SWAP' % devpath rc, output = run_local_cmd(cmd, shell=True) if rc: return False -- Gitee