From b03485d22aa43e159adb8a1b1479a3376cf4fc97 Mon Sep 17 00:00:00 2001 From: Arthur Golubtsov Date: Thu, 17 Oct 2019 13:00:45 +0100 Subject: [PATCH] Client: add new hostname to ssh motd message, do not change hostname if no network restart in config --- Drone/copter_client.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Drone/copter_client.py b/Drone/copter_client.py index 1f2c0a6..4511f0b 100644 --- a/Drone/copter_client.py +++ b/Drone/copter_client.py @@ -182,6 +182,9 @@ def configure_hosts(hostname): return True +def configure_motd(hostname): + with open("/etc/motd", "w") as f: + f.write("\r\n{}\r\n".format(hostname)) def configure_bashrc(hostname): path = "/home/pi/.bashrc" @@ -217,13 +220,13 @@ def _response_id(*args, **kwargs): cfg = client.ConfigOption("PRIVATE", "id", new_id) client.active_client.write_config(True, cfg) if new_id != '/hostname': - hostname = client.active_client.client_id - configure_hostname(hostname) - configure_hosts(hostname) - configure_bashrc(hostname) - execute_command("hostname {}".format(hostname)) if client.active_client.RESTART_DHCPCD: - # client.active_client.server_connection._send_response("new_id") + hostname = client.active_client.client_id + configure_hostname(hostname) + configure_hosts(hostname) + configure_bashrc(hostname) + configure_motd(hostname) + execute_command("hostname {}".format(hostname)) restart_service("dhcpcd") time.sleep(0.5) restart_service("avahi-daemon")