From 66debf1ed5cbee1b47cbb82fb98c57350ea37ca9 Mon Sep 17 00:00:00 2001 From: Emilien Devos <4016501+unixfox@users.noreply.github.com> Date: Sun, 5 Nov 2023 12:48:57 +0100 Subject: [PATCH] allow to skip root check --- smart-ipv6-rotator.py | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/smart-ipv6-rotator.py b/smart-ipv6-rotator.py index 2b815df..bca57a2 100644 --- a/smart-ipv6-rotator.py +++ b/smart-ipv6-rotator.py @@ -34,11 +34,6 @@ def module_not_found_helper(module_name): class SmartIPv6Rotator(object): def __init__(self): - if os.geteuid() != 0: - sys.exit( - "[Error] Please run this script as root! It needs root privileges." - ) - parser = argparse.ArgumentParser( description="IPv6 rotator", usage="""smart-ipv6-rotator.py [] @@ -80,6 +75,21 @@ def check_ipv6_connectivity(self): print("[INFO] You have IPv6 connectivity. Continuing.") def clean_previous_setup(self, existing_settings): + parser = argparse.ArgumentParser(description="Run the IPv6 rotator.") + parser.add_argument( + "--skip-root", + required=False, + dest='skip_root_check', + action=argparse.BooleanOptionalAction, + help="Example: --skip-root for skipping root check", + ) + args = parser.parse_args(sys.argv[2:]) + + if os.geteuid() != 0 and not args.skip_root_check: + sys.exit( + "[Error] Please run this script as root! It needs root privileges." + ) + if ( os.path.isfile(self.location_saved_config_ipv6_configured) or len(existing_settings) > 0 @@ -150,10 +160,22 @@ def run(self): "-r", "--ipv6range", required=True, - help="Example: --ipv6range=2001:861:4501:4a10::/64", + help="Example: --ipv6range=2001:1:1::/64", + ) + parser.add_argument( + "--skip-root", + required=False, + dest='skip_root_check', + action=argparse.BooleanOptionalAction, + help="Example: --skip-root for skipping root check", ) args = parser.parse_args(sys.argv[2:]) + if os.geteuid() != 0 and not args.skip_root_check: + sys.exit( + "[Error] Please run this script as root! It needs root privileges." + ) + self.check_ipv6_connectivity() self.clean_previous_setup({})