new: defaults are now copied into /etc/pwnagotchi/defaults.yml if it doesn't exist or different from release defaults
This commit is contained in:
parent
bd8f2936c5
commit
d222935aea
@ -15,8 +15,7 @@ if __name__ == '__main__':
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
parser.add_argument('-C', '--config', action='store', dest='config',
|
||||
default=os.path.join(os.path.dirname(pwnagotchi.__file__), 'defaults.yml'),
|
||||
parser.add_argument('-C', '--config', action='store', dest='config', default='/etc/pwnagotchi/default.yml',
|
||||
help='Main configuration file.')
|
||||
parser.add_argument('-U', '--user-config', action='store', dest='user_config', default='/etc/pwnagotchi/config.yml',
|
||||
help='If this file exists, configuration will be merged and this will override default values.')
|
||||
|
@ -7,6 +7,9 @@ import time
|
||||
import subprocess
|
||||
import yaml
|
||||
import json
|
||||
import shutil
|
||||
|
||||
import pwnagotchi
|
||||
|
||||
|
||||
# https://stackoverflow.com/questions/823196/yaml-merge-in-python
|
||||
@ -21,6 +24,28 @@ def merge_config(user, default):
|
||||
|
||||
|
||||
def load_config(args):
|
||||
default_config_path = os.path.dirname(args.config)
|
||||
if not os.path.exists(default_config_path):
|
||||
os.makedirs(default_config_path)
|
||||
|
||||
ref_defaults_file = os.path.join(os.path.dirname(pwnagotchi.__file__), 'defaults.yml')
|
||||
ref_defaults_data = None
|
||||
|
||||
if not os.path.exists(args.config):
|
||||
# logging not configured here yet
|
||||
print("copying %s to %s ..." % (ref_defaults_file, args.config))
|
||||
shutil.copy(ref_defaults_file, args.config)
|
||||
else:
|
||||
with open(ref_defaults_file) as fp:
|
||||
ref_defaults_data = fp.read()
|
||||
|
||||
with open(args.config) as fp:
|
||||
defaults_data = fp.read()
|
||||
|
||||
if ref_defaults_data != defaults_data:
|
||||
print("!!! file in %s is different than release defaults, overwriting !!!" % args.config)
|
||||
shutil.copy(ref_defaults_file, args.config)
|
||||
|
||||
with open(args.config) as fp:
|
||||
config = yaml.safe_load(fp)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user