#!/usr/bin/python3
# LAVA Setup - Copyright 2020 LAVA Controls - Stephen Loeckle

import argparse
import inspect
from lavaconfiglib import getkeys, httpproxysetup, renamebox
import sys

def main():
    gotthefunc = inspect.stack()[0][3]
    msg = ('Entered {} function'.format(gotthefunc))
    parser = argparse.ArgumentParser(description='LAVA Setup')
    configgroup = parser.add_argument_group('config')
    configgroup.add_argument('-hp', '--httpproxy', help = 'Set network http proxy, e.g. http://proxy.lavacontrols.com:8080 (This will cover http and https proxy environment variable). Leave empty to reset proxies to None.', action="store", const='NOPROXY', nargs='?')
    systemgroup = parser.add_argument_group('system')
    systemgroup.add_argument('-k', '--keys', help = 'Download call-home keys', action="store_true")
    systemgroup.add_argument('-n', '--name', metavar = 'NAME', help = 'Setup box name and call-home keys', nargs=1)
    args = parser.parse_args()
#    if (not args.name and not args.httpproxy):
#        parser.print_help()
    if len(sys.argv) == 0:
        parser.print_help()
    elif args.name:
        renamebox(args.name[0])
    elif args.httpproxy:
        httpproxysetup(args.httpproxy)
    elif args.keys:
        getkeys()
    else:
        parser.print_help()

if __name__ == '__main__':
   main()
