diff --git a/owrxadmin/__main__.py b/owrxadmin/__main__.py index f92233c..36f7b6e 100644 --- a/owrxadmin/__main__.py +++ b/owrxadmin/__main__.py @@ -1,5 +1,5 @@ from owrx.version import openwebrx_version -from owrxadmin.commands import NewUser, DeleteUser, ResetPassword, ListUsers, DisableUser, EnableUser +from owrxadmin.commands import NewUser, DeleteUser, ResetPassword, ListUsers, DisableUser, EnableUser, HasUser import argparse import sys import traceback @@ -36,6 +36,10 @@ def main(): enableuser_parser.add_argument("user", help="Username to be enabled") enableuser_parser.set_defaults(cls=EnableUser) + hasuser_parser = subparsers.add_parser("hasuser", help="Test if a user exists") + hasuser_parser.add_argument("user", help="Username to be checked") + hasuser_parser.set_defaults(cls=HasUser) + parser.add_argument("-v", "--version", action="store_true", help="Show the software version") parser.add_argument( "--noninteractive", action="store_true", help="Don't ask for any user input (useful for automation)" diff --git a/owrxadmin/commands.py b/owrxadmin/commands.py index 69aad1d..8eca85e 100644 --- a/owrxadmin/commands.py +++ b/owrxadmin/commands.py @@ -97,3 +97,19 @@ class ListUsers(Command): for u in userList.values(): if args.all or u.enabled: print(" {name}".format(name=u.name)) + + +class HasUser(Command): + """ + internal command used by the debian config scripts to test if the admin user has already been created + """ + def run(self, args): + userList = UserList() + if args.user in userList: + if not args.silent: + print('User "{name}" exists.'.format(name=args.user)) + else: + if not args.silent: + print('User "{name}" does not exist.'.format(name=args.user)) + # in bash, a return code > 0 is interpreted as "false" + sys.exit(1)