This commit is contained in:
Paolo Asperti 2019-05-06 22:14:45 +02:00
parent 949471915c
commit 1caecd5e35
Signed by: paspo
GPG Key ID: 06D46905D19D5182

View File

@ -27,15 +27,15 @@ def update_config_file(config):
config.write(configfile) config.write(configfile)
def set_new_hostname(hostname, domainname, oldhostname): def set_new_hostname(hostname, domainname, oldhostname):
if os.path.isfile('/etc/hosts'):
f1=open('/etc/hosts','r').read()
m1=f1.replace(oldhostname,hostname)
m2=m1.replace(oldhostname+'.'+domainname, hostname+'.'+domainname)
f2=open('/etc/hosts','w')
f2.write(m2)
os.system("hostname -b "+hostname) os.system("hostname -b "+hostname)
with open('/etc/hostname', 'w') as hostnamefile: with open('/etc/hostname', 'w') as hostnamefile:
hostnamefile.write(hostname) hostnamefile.write(hostname)
if not os.path.isfile('/etc/hosts'):
f1=open('/etc/hosts','r').read()
m=f1.replace(oldhostname,hostname)
m=m.replace(oldhostname+'.'+domainname, hostname+'.'+domainname)
f2=open('/etc/hosts','w')
f2.write(m)
return return
config = configparser.ConfigParser() config = configparser.ConfigParser()