Skip to content

Commit

Permalink
allow to skip root check
Browse files Browse the repository at this point in the history
  • Loading branch information
unixfox committed Nov 5, 2023
1 parent b76e890 commit 66debf1
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions smart-ipv6-rotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <command> [<args>]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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({})

Expand Down

0 comments on commit 66debf1

Please sign in to comment.