This repository has been archived on 2025-06-02. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
Os/root-fs/usr/bin/wallaby_set_hostname.py
2018-04-07 23:26:16 +02:00

23 lines
602 B
Python
Executable file

#!/usr/bin/env python3
from subprocess import check_output, call
bot_id = "bot"
for i2c in range(4):
bot_id += check_output("i2cget -y 0 0x50 0x4%i" % i2c, shell=True).decode()[-2]
new_hosts_content = ""
for line in open("/etc/hosts", "r").read().split("\n"):
if line.startswith("127.0.1.1"):
new_hosts_content += "127.0.1.1\t%s\n" % bot_id
elif line != "":
new_hosts_content += "%s\n" % line
open("/etc/hosts", "w").write(new_hosts_content)
call("hostnamectl set-hostname %s" % bot_id, shell=True)
call("systemctl restart avahi-daemon", shell=True)
print("Hostname set: '%s'" % bot_id)