import os
print("LXC-KICKSTART - Ajinov : Network Setting")

ip = raw_input("Entrez l'adresse ip > ")
passerelle = raw_input("Entrez la passerelle > ")
hostname = raw_input("Entrez le hostname > ")

os_type = raw_input("Debian ou Ubuntu ? (0/1) > ")
hostname_file = "/etc/hostname"
interface_file = "/etc/network/interfaces"

if os_type == "0":
    resolvconf_file = "/etc/resolv.conf"
else:
    resolvconf_file = "/etc/resolvconf/resolv.conf.d/base"


print("Configuration du hostname \n")
with open(hostname_file, "a") as configfile:
    configfile.write(hostname)

print("Configuration de l'interface eth0 en ip statique : " + ip + " et passerelle : " + passerelle + "\n")
with open(interface_file, "a") as configfile:
    configfile.write("auto eth0 \n" +
                     "iface eth0 inet static \n" +
                     "address  " + ip + " \n" +
                     "netmask 255.255.255.0 \n" +
                     "gateway " + passerelle + "\n")



print("Prise en compte de eth0 \n")
os.system("ifup eth0")

print("Configuration des dns google (8.8.8.8 ; 8.8.4.4)")
with open(resolvconf_file, "a") as configfile:
    configfile.write("nameserver 8.8.8.8 \n" +
                     "nameserver 8.8.4.4 \n")

if os_type != "0":
    print("Prise en compte des serveurs DNS \n")
    os.system("resolvconf -u")

print("Mise a jour du systeme")
os.system("apt-get update -y && apt-get upgrade -y")

print("KICKSTART COMPLETE")