new: user config is now copied from /boot/config.yml

This commit is contained in:
Simone Margaritelli 2019-10-18 16:34:58 +02:00
parent f4a59549fa
commit e220a869e0

View File

@ -31,11 +31,18 @@ def load_config(args):
ref_defaults_file = os.path.join(os.path.dirname(pwnagotchi.__file__), 'defaults.yml') ref_defaults_file = os.path.join(os.path.dirname(pwnagotchi.__file__), 'defaults.yml')
ref_defaults_data = None ref_defaults_data = None
if not os.path.exists(args.config): # check for a config.yml file on /boot/
if os.path.exists("/boot/config.yml"):
# logging not configured here yet # logging not configured here yet
print("installing /boot/config.yml to %s ...", args.user_config)
os.rename("/boot/config.yml", args.user_config)
# if not config is found, copy the defaults
if not os.path.exists(args.config):
print("copying %s to %s ..." % (ref_defaults_file, args.config)) print("copying %s to %s ..." % (ref_defaults_file, args.config))
shutil.copy(ref_defaults_file, args.config) shutil.copy(ref_defaults_file, args.config)
else: else:
# check if the user messed with the defaults
with open(ref_defaults_file) as fp: with open(ref_defaults_file) as fp:
ref_defaults_data = fp.read() ref_defaults_data = fp.read()
@ -46,9 +53,11 @@ def load_config(args):
print("!!! file in %s is different than release defaults, overwriting !!!" % args.config) print("!!! file in %s is different than release defaults, overwriting !!!" % args.config)
shutil.copy(ref_defaults_file, args.config) shutil.copy(ref_defaults_file, args.config)
# load the defaults
with open(args.config) as fp: with open(args.config) as fp:
config = yaml.safe_load(fp) config = yaml.safe_load(fp)
# load the user config
if os.path.exists(args.user_config): if os.path.exists(args.user_config):
with open(args.user_config) as fp: with open(args.user_config) as fp:
user_config = yaml.safe_load(fp) user_config = yaml.safe_load(fp)
@ -131,6 +140,7 @@ def blink(times=1, delay=0.3):
time.sleep(delay) time.sleep(delay)
led(True) led(True)
class WifiInfo(Enum): class WifiInfo(Enum):
""" """
Fields you can extract from a pcap file Fields you can extract from a pcap file
@ -141,6 +151,7 @@ class WifiInfo(Enum):
CHANNEL = 3 CHANNEL = 3
RSSI = 4 RSSI = 4
class FieldNotFoundError(Exception): class FieldNotFoundError(Exception):
pass pass