refs #1646 add ogSetLinuxName
parent
fb0d520739
commit
ec4f1f8642
|
@ -0,0 +1,37 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
from SystemLib import ogHelp
|
||||||
|
from BootLib import ogSetLinuxName
|
||||||
|
from NetLib import ogGetHostname
|
||||||
|
|
||||||
|
if 2 == len (sys.argv) and 'help' == sys.argv[1]:
|
||||||
|
#parser.print_help() sale en inglés aunque la locale indique otra cosa
|
||||||
|
ogHelp ('ogSetLinuxName', 'ogSetLinuxName int_ndisk int_nfilesys [str_name]', ['ogSetLinuxName 1 1 practica-pc'])
|
||||||
|
sys.exit (0)
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser (add_help=False)
|
||||||
|
if 3 == len (sys.argv):
|
||||||
|
parser.add_argument ('disk')
|
||||||
|
parser.add_argument ('par')
|
||||||
|
elif 4 == len (sys.argv):
|
||||||
|
parser.add_argument ('disk')
|
||||||
|
parser.add_argument ('par')
|
||||||
|
parser.add_argument ('hostname')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if 3 == len (sys.argv):
|
||||||
|
h = ogGetHostname()
|
||||||
|
if h:
|
||||||
|
ret = ogSetLinuxName (args.disk, args.par, h)
|
||||||
|
else:
|
||||||
|
ret = ogSetLinuxName (args.disk, args.par)
|
||||||
|
elif 4 == len (sys.argv):
|
||||||
|
ret = ogSetLinuxName (args.disk, args.par, args.hostname)
|
||||||
|
|
||||||
|
if ret is not None:
|
||||||
|
if ret == True: sys.exit (0)
|
||||||
|
elif ret == False: sys.exit (1)
|
||||||
|
else: print (ret)
|
|
@ -670,6 +670,30 @@ def ogConfigureFstab (disk, par):
|
||||||
#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
|
#@exception OG_ERR_PARTITION Tipo de partición desconocido o no se puede montar.
|
||||||
#@note Si no se indica nombre, se asigna un valor por defecto.
|
#@note Si no se indica nombre, se asigna un valor por defecto.
|
||||||
#*/ ##
|
#*/ ##
|
||||||
|
def ogSetLinuxName (disk, par, hostname='pc'):
|
||||||
|
# Montar el sistema de archivos.
|
||||||
|
mntdir = FileSystemLib.ogMount (disk, par)
|
||||||
|
if not mntdir: return None
|
||||||
|
|
||||||
|
etc = FileLib.ogGetPath (src=f'{disk} {par}', file='/etc')
|
||||||
|
|
||||||
|
if os.path.isdir (etc):
|
||||||
|
#cambio de nombre en hostname
|
||||||
|
with open (f'{etc}/hostname', 'w') as fd:
|
||||||
|
fd.write (f'{hostname}\n')
|
||||||
|
#Opcion A para cambio de nombre en hosts
|
||||||
|
#sed "/127.0.1.1/ c\127.0.1.1 \t $HOSTNAME" $ETC/hosts > /tmp/hosts && cp /tmp/hosts $ETC/ && rm /tmp/hosts
|
||||||
|
#Opcion B componer fichero de hosts
|
||||||
|
with open (f'{etc}/hosts', 'w') as fd:
|
||||||
|
fd.write ('127.0.0.1 localhost\n')
|
||||||
|
fd.write (f'127.0.1.1 {hostname}\n')
|
||||||
|
fd.write ('\n')
|
||||||
|
fd.write ('# The following lines are desirable for IPv6 capable hosts\n')
|
||||||
|
fd.write ('::1 ip6-localhost ip6-loopback\n')
|
||||||
|
fd.write ('fe00::0 ip6-localnet\n')
|
||||||
|
fd.write ('ff00::0 ip6-mcastprefix\n')
|
||||||
|
fd.write ('ff02::1 ip6-allnodes\n')
|
||||||
|
fd.write ('ff02::2 ip6-allrouters\n')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue