new: unit's name can be now set via main.name configuration parameter
This commit is contained in:
parent
61b957ac77
commit
0f171c35ce
@ -37,6 +37,8 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
logging.debug("effective configuration:\n\n%s\n\n" % yaml.dump(config, default_flow_style=False))
|
logging.debug("effective configuration:\n\n%s\n\n" % yaml.dump(config, default_flow_style=False))
|
||||||
|
|
||||||
|
pwnagotchi.set_name(config['main']['name'])
|
||||||
|
|
||||||
plugins.load(config)
|
plugins.load(config)
|
||||||
|
|
||||||
display = Display(config=config, state={'name': '%s>' % pwnagotchi.name()})
|
display = Display(config=config, state={'name': '%s>' % pwnagotchi.name()})
|
||||||
|
@ -9,6 +9,37 @@ version = '1.1.0b'
|
|||||||
_name = None
|
_name = None
|
||||||
|
|
||||||
|
|
||||||
|
def set_name(new_name):
|
||||||
|
if new_name is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
new_name = new_name.strip()
|
||||||
|
if new_name == '':
|
||||||
|
return
|
||||||
|
|
||||||
|
current = name()
|
||||||
|
if new_name != current:
|
||||||
|
global _name
|
||||||
|
|
||||||
|
logging.info("setting unit hostname '%s' -> '%s'" % (current, new_name))
|
||||||
|
with open('/etc/hostname', 'wt') as fp:
|
||||||
|
fp.write(new_name)
|
||||||
|
|
||||||
|
with open('/etc/hosts', 'rt') as fp:
|
||||||
|
prev = fp.read()
|
||||||
|
logging.debug("old hosts:\n%s\n" % prev)
|
||||||
|
|
||||||
|
with open('/etc/hosts', 'wt') as fp:
|
||||||
|
patched = prev.replace(current, new_name, -1)
|
||||||
|
logging.debug("new hosts:\n%s\n" % patched)
|
||||||
|
fp.write(patched)
|
||||||
|
|
||||||
|
_name = new_name
|
||||||
|
logging.info("restarting avahi ...")
|
||||||
|
os.system("service avahi-daemon restart")
|
||||||
|
logging.info("hostname set")
|
||||||
|
|
||||||
|
|
||||||
def name():
|
def name():
|
||||||
global _name
|
global _name
|
||||||
if _name is None:
|
if _name is None:
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#
|
#
|
||||||
# main algorithm configuration
|
# main algorithm configuration
|
||||||
main:
|
main:
|
||||||
|
# if set this will set the hostname of the unit
|
||||||
|
name: 'pwnagotchi'
|
||||||
# currently implemented: en (default), de, el, fr, it, mk, nl, ru, se, pt-BR, es, pt
|
# currently implemented: en (default), de, el, fr, it, mk, nl, ru, se, pt-BR, es, pt
|
||||||
lang: en
|
lang: en
|
||||||
# custom plugins path, if null only default plugins with be loaded
|
# custom plugins path, if null only default plugins with be loaded
|
||||||
|
Loading…
x
Reference in New Issue
Block a user