Update jlmkr.py

This commit is contained in:
Basti Qdoba 2023-02-27 20:25:15 +01:00 committed by GitHub
parent 1de5425015
commit eff2592ae5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 0 deletions

View File

@ -613,6 +613,20 @@ def create_jail(jail_name):
start_jail(jail_name) start_jail(jail_name)
def delete_jail(jail_name):
"""
Delete jail with given name.
"""
# stop the jail
os.system(f"machinectl stop {jail_name}")
jail_path = os.path.join(JAILS_DIR_PATH, jail_name)
if os.path.isdir(jail_path):
eprint(f"Cleaning up: {jail_path}")
shutil.rmtree(jail_path)
def main(): def main():
if os.stat(__file__).st_uid != 0: if os.stat(__file__).st_uid != 0:
fail("This script should be owned by the root user...") fail("This script should be owned by the root user...")
@ -629,6 +643,9 @@ def main():
start_parser = subparsers.add_parser(name='start', epilog=DISCLAIMER) start_parser = subparsers.add_parser(name='start', epilog=DISCLAIMER)
start_parser.add_argument('name', help='name of the jail') start_parser.add_argument('name', help='name of the jail')
start_parser = subparsers.add_parser(name='delete', epilog=DISCLAIMER)
start_parser.add_argument('name', help='name of the jail')
parser.usage = f"{parser.format_usage()[7:]}{create_parser.format_usage()}{start_parser.format_usage()}" parser.usage = f"{parser.format_usage()[7:]}{create_parser.format_usage()}{start_parser.format_usage()}"
if os.getuid() != 0: if os.getuid() != 0:
@ -650,6 +667,9 @@ def main():
elif args.subcommand == 'create': elif args.subcommand == 'create':
create_jail(args.name) create_jail(args.name)
elif args.subcommand == 'delete':
delete_jail(args.name)
elif args.subcommand: elif args.subcommand:
parser.print_usage() parser.print_usage()