2022-05-07 13:09:19 +02:00
|
|
|
#!/bin/python
|
|
|
|
|
|
|
|
import os
|
2022-08-25 18:56:26 +02:00
|
|
|
import sys
|
2022-05-07 13:46:48 +02:00
|
|
|
import subprocess
|
2022-05-07 13:09:19 +02:00
|
|
|
|
2022-05-07 13:46:48 +02:00
|
|
|
ssh_config = os.path.expanduser('~') + "/.ssh/config"
|
2022-05-07 13:09:19 +02:00
|
|
|
|
2022-05-07 13:46:48 +02:00
|
|
|
with open(ssh_config) as file:
|
|
|
|
file_content = list(file)
|
2022-05-07 13:09:19 +02:00
|
|
|
|
|
|
|
#ping -c 1 -w 1
|
|
|
|
|
2022-08-25 18:56:26 +02:00
|
|
|
if sys.argv[1] != None:
|
|
|
|
ssh_host = sys.argv[1]
|
|
|
|
command = f"infocmp | ssh {ssh_host} 'tic -x /dev/stdin'"
|
|
|
|
return_value = subprocess.call(command, shell=True, stdout=open(os.devnull, "w"), stderr=subprocess.STDOUT)
|
|
|
|
if return_value == 1:
|
|
|
|
print(f"Could not send terminfo to {ssh_host}")
|
2022-05-07 13:46:48 +02:00
|
|
|
|
2022-08-25 18:56:26 +02:00
|
|
|
else:
|
|
|
|
for l in file_content:
|
|
|
|
if "host " in l:
|
|
|
|
l_index = file_content.index(l)
|
|
|
|
index = l_index + 1
|
|
|
|
host_ip = file_content[index].split()[1]
|
2022-05-07 13:46:48 +02:00
|
|
|
|
2022-08-25 18:56:26 +02:00
|
|
|
return_value = subprocess.call(["ping", "-c1", "-w1", host_ip], stdout=open(os.devnull, "w"), stderr=subprocess.STDOUT)
|
2022-05-07 13:46:48 +02:00
|
|
|
|
2022-08-25 18:56:26 +02:00
|
|
|
if return_value == 0:
|
|
|
|
ssh_host = l.split()[1]
|
2022-05-07 13:46:48 +02:00
|
|
|
|
2022-08-25 18:56:26 +02:00
|
|
|
print(f"Host {ssh_host} ({host_ip}) is up. Sending terminfo..")
|
2022-05-07 13:46:48 +02:00
|
|
|
|
2022-08-25 18:56:26 +02:00
|
|
|
command = f"infocmp | ssh {ssh_host} 'tic -x /dev/stdin'"
|
2022-05-07 13:46:48 +02:00
|
|
|
|
2022-08-25 18:56:26 +02:00
|
|
|
return_value = subprocess.call(command, shell=True, stdout=open(os.devnull, "w"), stderr=subprocess.STDOUT)
|
|
|
|
|
|
|
|
if return_value == 1:
|
|
|
|
print(f"Could not send terminfo to {ssh_host}")
|