custom config override file
This commit is contained in:
parent
5968030ed3
commit
f6605640b3
@ -95,7 +95,7 @@ ui:
|
|||||||
# IMPORTANT: The lifespan of an eINK display depends on the cumulative amount of refreshes. If you want to
|
# IMPORTANT: The lifespan of an eINK display depends on the cumulative amount of refreshes. If you want to
|
||||||
# preserve your display over time, you should set this value to 0.0 so that the display will be refreshed only
|
# preserve your display over time, you should set this value to 0.0 so that the display will be refreshed only
|
||||||
# if any of the important data fields changed (the uptime and blinking cursor won't trigger a refresh).
|
# if any of the important data fields changed (the uptime and blinking cursor won't trigger a refresh).
|
||||||
fps: 0.3
|
fps: 0.0
|
||||||
display:
|
display:
|
||||||
enabled: true
|
enabled: true
|
||||||
rotation: 180
|
rotation: 180
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
import yaml
|
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
|
||||||
import core
|
import core
|
||||||
import pwnagotchi, pwnagotchi.plugins as plugins
|
import pwnagotchi
|
||||||
|
import pwnagotchi.utils as utils
|
||||||
|
import pwnagotchi.version as version
|
||||||
|
import pwnagotchi.plugins as plugins
|
||||||
|
|
||||||
from pwnagotchi.log import SessionParser
|
from pwnagotchi.log import SessionParser
|
||||||
from pwnagotchi.voice import Voice
|
from pwnagotchi.voice import Voice
|
||||||
@ -14,53 +19,52 @@ from pwnagotchi.ui.display import Display
|
|||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
parser.add_argument('-C', '--config', action='store', dest='config', default='/root/pwnagotchi/config.yml')
|
parser.add_argument('-C', '--config', action='store', dest='config', default='/root/pwnagotchi/config.yml',
|
||||||
|
help='Main configuration file.')
|
||||||
|
parser.add_argument('-U', '--user-config', action='store', dest='user_config', default='/root/pwnagotchi.yml',
|
||||||
|
help='If this file exists, configuration will be merged and this will override default values.')
|
||||||
|
|
||||||
parser.add_argument('--manual', dest="do_manual", action="store_true", default=False, help="Manual mode.")
|
parser.add_argument('--manual', dest="do_manual", action="store_true", default=False, help="Manual mode.")
|
||||||
parser.add_argument('--clear', dest="do_clear", action="store_true", default=False,
|
parser.add_argument('--clear', dest="do_clear", action="store_true", default=False,
|
||||||
help="Clear the ePaper display and exit.")
|
help="Clear the ePaper display and exit.")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
config = utils.load_config(args)
|
||||||
|
|
||||||
if args.do_clear:
|
if args.do_clear:
|
||||||
print("clearing the display ...")
|
print("clearing the display ...")
|
||||||
with open(args.config, 'rt') as fp:
|
cleardisplay = config['ui']['display']['type']
|
||||||
config = yaml.safe_load(fp)
|
if cleardisplay in ('inkyphat', 'inky'):
|
||||||
cleardisplay = config['ui']['display']['type']
|
print("inky display")
|
||||||
if cleardisplay in ('inkyphat', 'inky'):
|
from inky import InkyPHAT
|
||||||
print("inky display")
|
|
||||||
from inky import InkyPHAT
|
|
||||||
|
|
||||||
epd = InkyPHAT(config['ui']['display']['color'])
|
epd = InkyPHAT(config['ui']['display']['color'])
|
||||||
epd.set_border(InkyPHAT.BLACK)
|
epd.set_border(InkyPHAT.BLACK)
|
||||||
self._render_cb = self._inky_render
|
self._render_cb = self._inky_render
|
||||||
elif cleardisplay in ('papirus', 'papi'):
|
elif cleardisplay in ('papirus', 'papi'):
|
||||||
print("papirus display")
|
print("papirus display")
|
||||||
from pwnagotchi.ui.papirus.epd import EPD
|
from pwnagotchi.ui.papirus.epd import EPD
|
||||||
|
|
||||||
os.environ['EPD_SIZE'] = '2.0'
|
os.environ['EPD_SIZE'] = '2.0'
|
||||||
epd = EPD()
|
epd = EPD()
|
||||||
epd.clear()
|
epd.clear()
|
||||||
elif cleardisplay in ('waveshare_1', 'ws_1', 'waveshare1', 'ws1'):
|
elif cleardisplay in ('waveshare_1', 'ws_1', 'waveshare1', 'ws1'):
|
||||||
print("waveshare v1 display")
|
print("waveshare v1 display")
|
||||||
from pwnagotchi.ui.waveshare.v1.epd2in13 import EPD
|
from pwnagotchi.ui.waveshare.v1.epd2in13 import EPD
|
||||||
|
|
||||||
epd = EPD()
|
epd = EPD()
|
||||||
epd.init(epd.lut_full_update)
|
epd.init(epd.lut_full_update)
|
||||||
epd.Clear(0xFF)
|
epd.Clear(0xFF)
|
||||||
elif cleardisplay in ('waveshare_2', 'ws_2', 'waveshare2', 'ws2'):
|
elif cleardisplay in ('waveshare_2', 'ws_2', 'waveshare2', 'ws2'):
|
||||||
print("waveshare v2 display")
|
print("waveshare v2 display")
|
||||||
from pwnagotchi.ui.waveshare.v2.waveshare import EPD
|
from pwnagotchi.ui.waveshare.v2.waveshare import EPD
|
||||||
|
|
||||||
epd = EPD()
|
epd = EPD()
|
||||||
epd.init(epd.FULL_UPDATE)
|
epd.init(epd.FULL_UPDATE)
|
||||||
epd.Clear(0xff)
|
epd.Clear(0xff)
|
||||||
else:
|
else:
|
||||||
print("unknown display type %s" % cleardisplay)
|
print("unknown display type %s" % cleardisplay)
|
||||||
quit()
|
quit()
|
||||||
|
|
||||||
with open(args.config, 'rt') as fp:
|
|
||||||
config = yaml.safe_load(fp)
|
|
||||||
|
|
||||||
plugins.load_from_path(plugins.default_path)
|
plugins.load_from_path(plugins.default_path)
|
||||||
if 'plugins' in config['main'] and config['main']['plugins'] is not None:
|
if 'plugins' in config['main'] and config['main']['plugins'] is not None:
|
||||||
@ -71,7 +75,7 @@ plugins.on('loaded')
|
|||||||
display = Display(config=config, state={'name': '%s>' % pwnagotchi.name()})
|
display = Display(config=config, state={'name': '%s>' % pwnagotchi.name()})
|
||||||
agent = Agent(view=display, config=config)
|
agent = Agent(view=display, config=config)
|
||||||
|
|
||||||
core.log("%s@%s (v%s)" % (pwnagotchi.name(), agent._identity, pwnagotchi.version))
|
core.log("%s@%s (v%s)" % (pwnagotchi.name(), agent._identity, version.version))
|
||||||
# for key, value in config['personality'].items():
|
# for key, value in config['personality'].items():
|
||||||
# core.log(" %s: %s" % (key, value))
|
# core.log(" %s: %s" % (key, value))
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
import _thread
|
import _thread
|
||||||
|
|
||||||
import core
|
import core
|
||||||
import pwnagotchi, pwnagotchi.plugins as plugins
|
import pwnagotchi
|
||||||
|
import pwnagotchi.version as version
|
||||||
|
import pwnagotchi.plugins as plugins
|
||||||
from pwnagotchi.mesh import get_identity
|
from pwnagotchi.mesh import get_identity
|
||||||
|
|
||||||
|
|
||||||
@ -22,7 +24,7 @@ class AsyncAdvertiser(object):
|
|||||||
self._advertiser = Advertiser(
|
self._advertiser = Advertiser(
|
||||||
self._config['main']['iface'],
|
self._config['main']['iface'],
|
||||||
pwnagotchi.name(),
|
pwnagotchi.name(),
|
||||||
pwnagotchi.version,
|
version.version,
|
||||||
self._identity,
|
self._identity,
|
||||||
period=0.3,
|
period=0.3,
|
||||||
data=self._config['personality'])
|
data=self._config['personality'])
|
||||||
|
24
sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/utils.py
Normal file
24
sdcard/rootfs/root/pwnagotchi/scripts/pwnagotchi/utils.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import yaml
|
||||||
|
import os
|
||||||
|
|
||||||
|
# https://stackoverflow.com/questions/823196/yaml-merge-in-python
|
||||||
|
def merge_config(user, default):
|
||||||
|
if isinstance(user, dict) and isinstance(default, dict):
|
||||||
|
for k, v in default.items():
|
||||||
|
if k not in user:
|
||||||
|
user[k] = v
|
||||||
|
else:
|
||||||
|
user[k] = merge_config(user[k], v)
|
||||||
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
def load_config(args):
|
||||||
|
with open(args.config, 'rt') as fp:
|
||||||
|
config = yaml.safe_load(fp)
|
||||||
|
|
||||||
|
if os.path.exists(args.user_config):
|
||||||
|
with open(args.user_config, 'rt') as fp:
|
||||||
|
user_config = yaml.safe_load(fp)
|
||||||
|
config = merge_config(user_config, config)
|
||||||
|
|
||||||
|
return config
|
Loading…
x
Reference in New Issue
Block a user