Refs #202 parameter setting is added
							parent
							
								
									3b536baa7a
								
							
						
					
					
						commit
						6fc10e95df
					
				|  | @ -7,40 +7,31 @@ | ||||||
| 
 | 
 | ||||||
| import platform, os, sys, subprocess, datetime, shutil, pwd, glob, zipfile, urllib.request, logging, distro, re | import platform, os, sys, subprocess, datetime, shutil, pwd, glob, zipfile, urllib.request, logging, distro, re | ||||||
| 
 | 
 | ||||||
| global PACKAGES_TO_INSTALL |  | ||||||
| global UBUNTU_OS_VERSION |  | ||||||
| global PYTHON_VERSION |  | ||||||
| global INSTALL_OGBOOT_TARGET |  | ||||||
| global PROGRAM_DIR |  | ||||||
| global OPENGNSYS_SERVER |  | ||||||
| 
 |  | ||||||
| # Reload variables from bashrc | # Reload variables from bashrc | ||||||
| subprocess.run(['.', '~/.bashrc'], shell=True) | # subprocess.run(['source', '~/.bashrc'], shell=True) | ||||||
| 
 | 
 | ||||||
| # Leer variables de entorno | # Leer variables de entorno | ||||||
| #env_ogCore_ServerIP = os.environ.get('OGCORE_SERVER_IP')	#"172.17.8.82" | env_ogCore_ServerIP = os.getenv('OGCORE_SERVER_IP')		#"172.17.8.82" | ||||||
| #env_ogCore_Server = os.environ.get('OGCORE_SERVER')			#"opengnsys.es" | env_ogCore_Server = os.getenv('OGCORE_SERVER')			#"opengnsys.es" | ||||||
| #env_ogCore_Dir = os.environ.get('OGCORE_DIR')				#{INSTALL_OPENGNSYS_TARGET} | env_ogCore_Dir = os.getenv('OGCORE_DIR')				#{INSTALL_OPENGNSYS_TARGET} | ||||||
| #env_ogBoot_Dir = os.environ.get('OGBOOT_DIR')				#{INSTALL_OGBOOT_TARGET} | env_ogBoot_Dir = os.getenv('OGBOOT_DIR')				#{INSTALL_OGBOOT_TARGET} | ||||||
| #env_ogBoot_GitRepo = os.environ.get('OGBOOT_GIT_REPO')		#"ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git" | env_ogBoot_GitRepo = os.getenv('OGBOOT_GIT_REPO')		#"ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git" | ||||||
| 
 | #env_ogCore_ServerIP = "172.17.8.82" #os.getenv('OGCORE_SERVER_IP')	#"172.17.8.82" | ||||||
| # Leer variables de entorno | #env_ogCore_Server = "opengnsys.es" #os.getenv('OGCORE_SERVER')			#"opengnsys.es" | ||||||
| env_ogCore_ServerIP = "172.17.8.82" #os.getenv('OGCORE_SERVER_IP')	#"172.17.8.82" | #env_ogCore_Dir = "/opt/opengnsys" #os.getenv('OGCORE_DIR')				#{INSTALL_OPENGNSYS_TARGET} | ||||||
| env_ogCore_Server = "opengnsys.es" #os.getenv('OGCORE_SERVER')			#"opengnsys.es" | #env_ogBoot_Dir = "/opt/ogboot" #os.getenv('OGBOOT_DIR')				#{INSTALL_OGBOOT_TARGET} | ||||||
| env_ogCore_Dir = "/opt/opengnsys" #os.getenv('OGCORE_DIR')				#{INSTALL_OPENGNSYS_TARGET} | #env_ogBoot_GitRepo = "ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git" #os.getenv('OGBOOT_GIT_REPO')		#"ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git" | ||||||
| env_ogBoot_Dir = "/opt/ogboot" #os.getenv('OGBOOT_DIR')				#{INSTALL_OGBOOT_TARGET} |  | ||||||
| env_ogBoot_GitRepo = "ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git" #os.getenv('OGBOOT_GIT_REPO')		#"ssh://git@ognproject.evlt.uma.es:21987/opengnsys/ogboot.git" |  | ||||||
| 
 | 
 | ||||||
| PROGRAM = os.path.splitext(os.path.basename(sys.argv[0]))[0] | PROGRAM = os.path.splitext(os.path.basename(sys.argv[0]))[0] | ||||||
| PROGRAM_DIR = os.path.dirname(os.path.realpath(sys.argv[0])) | PROGRAM_DIR = os.path.dirname(os.path.realpath(sys.argv[0])) | ||||||
| PROGRAM_NAME = os.path.basename(sys.argv[0]) | PROGRAM_NAME = os.path.basename(sys.argv[0]) | ||||||
| 
 | 
 | ||||||
| SERVER_OPENGNSYS = env_ogCore_ServerIP | SERVER_OPENGNSYS = f"{env_ogCore_ServerIP}" | ||||||
| OPENGNSYS_SERVER = env_ogCore_Server | OPENGNSYS_SERVER = f"{env_ogCore_Server}" | ||||||
| INSTALL_TARGET = env_ogBoot_Dir | INSTALL_TARGET = f"{env_ogBoot_Dir}" | ||||||
| INSTALL_OPENGNSYS_TARGET = env_ogCore_Dir | INSTALL_OPENGNSYS_TARGET = f"{env_ogCore_Dir}" | ||||||
| INSTALL_OGBOOT_TARGET = env_ogBoot_Dir | INSTALL_OGBOOT_TARGET = f"{env_ogBoot_Dir}" | ||||||
| GIT_REPO = env_ogBoot_GitRepo | GIT_REPO = f"{env_ogBoot_GitRepo}" | ||||||
| 
 | 
 | ||||||
| IPXE_DIR = "/tmp/ipxe" | IPXE_DIR = "/tmp/ipxe" | ||||||
| WORKDIR="/tmp/ogboot_installer" | WORKDIR="/tmp/ogboot_installer" | ||||||
|  | @ -50,7 +41,7 @@ SAMBACFGDIR = "/etc/samba" | ||||||
| TFTPCFGDIR = "/var/lib/tftpboot" | TFTPCFGDIR = "/var/lib/tftpboot" | ||||||
| INETDCFGDIR = "/etc/xinetd.d/" | INETDCFGDIR = "/etc/xinetd.d/" | ||||||
| 
 | 
 | ||||||
| DEFAULTDEV = "" | DEFAULTDEV = "enp0s3" | ||||||
| PACKAGES_TO_INSTALL = ["htop"] | PACKAGES_TO_INSTALL = ["htop"] | ||||||
| DEVICE = [] | DEVICE = [] | ||||||
| SERVERIP = [] | SERVERIP = [] | ||||||
|  | @ -163,34 +154,33 @@ def get_missing_packages(): | ||||||
| 		case "ubuntu": | 		case "ubuntu": | ||||||
| 			match OSVERSION: | 			match OSVERSION: | ||||||
| 				case "20.04": | 				case "20.04": | ||||||
| 					PACKAGES = ["vim", "curl", "htop"] | 					PACKAGES_TO_INSTALL = ["vim", "curl", "htop"] | ||||||
| 				case "18.04": | 				case "18.04": | ||||||
| 					PACKAGES = ["nano", "wget", "tree"] | 					PACKAGES_TO_INSTALL = ["nano", "wget", "tree"] | ||||||
| 				case "22.04": | 				case "22.04": | ||||||
| 					PACKAGES_TO_INSTALL = ["xorriso", "genisoimage", "syslinux", "liblzma-dev", "nginx", "arp-scan", "automake", "build-essential", "btrfs-progs", "composer", "curl", "ctorrent", "debootstrap", "g++-multilib", "gawk", "gettext", "graphviz", "grub-efi-amd64-signed", "jq", "libapache2-mod-php", "libdbi-dev", "libdbi1", "libev-dev", "libjansson-dev", "liblz4-tool", "libssl-dev", "moreutils", "netpipes", "php", "php-bcmath", "php-cli", "php-curl", "php-fpm", "php-gd", "php-json", "php-ldap", "php-mbstring", "php-mysql", "php8.1-common", "php-pear", "php-xml", "php-zip", "procps", "coreutils", "rsync", "samba", "schroot", "shim-signed", "squashfs-tools", "subversion", "tftpd-hpa", "udpcast", "unzip", "wakeonlan", "wget", "xinetd", "jq", "moreutils", "net-tools"] | 					PACKAGES_TO_INSTALL = ["nfs-common", "xorriso", "genisoimage", "syslinux", "liblzma-dev", "nginx", "arp-scan", "automake", "build-essential", "btrfs-progs", "composer", "curl", "ctorrent", "debootstrap", "g++-multilib", "gawk", "gettext", "graphviz", "grub-efi-amd64-signed", "jq", "libapache2-mod-php", "libdbi-dev", "libdbi1", "libev-dev", "libjansson-dev", "liblz4-tool", "libssl-dev", "moreutils", "netpipes", "php", "php-bcmath", "php-cli", "php-curl", "php-fpm", "php-gd", "php-json", "php-ldap", "php-mbstring", "php-mysql", "php8.1-common", "php-pear", "php-xml", "php-zip", "procps", "coreutils", "rsync", "samba", "schroot", "shim-signed", "squashfs-tools", "subversion", "tftpd-hpa", "udpcast", "unzip", "wakeonlan", "wget", "xinetd", "jq", "moreutils", "net-tools"] | ||||||
| 				case _: | 				case _: | ||||||
| 					PACKAGES = ["bash", "nc", "rsync"] | 					PACKAGES_TO_INSTALL = ["bash", "nc", "rsync"] | ||||||
| 		case "suse": | 		case "suse": | ||||||
| 			match OSVERSION: | 			match OSVERSION: | ||||||
| 				case "15": | 				case "15": | ||||||
| 					PACKAGES = ["zypper", "mc", "gcc"] | 					PACKAGES_TO_INSTALL = ["zypper", "mc", "gcc"] | ||||||
| 				case "12": | 				case "12": | ||||||
| 					PACKAGES = ["perl", "tar", "man"] | 					PACKAGES_TO_INSTALL = ["perl", "tar", "man"] | ||||||
| 				case _: | 				case _: | ||||||
| 					PACKAGES = ["openssl", "ncurses", "zip"] | 					PACKAGES_TO_INSTALL = ["openssl", "ncurses", "zip"] | ||||||
| 		case "redhat": | 		case "redhat": | ||||||
| 			match OSVERSION: | 			match OSVERSION: | ||||||
| 				case "8": | 				case "8": | ||||||
| 					PACKAGES = ["yum", "tar", "perl"] | 					PACKAGES_TO_INSTALL = ["yum", "tar", "perl"] | ||||||
| 				case "7": | 				case "7": | ||||||
| 					PACKAGES = ["bash", "rpm", "tcpdump"] | 					PACKAGES_TO_INSTALL = ["bash", "rpm", "tcpdump"] | ||||||
| 				case _: | 				case _: | ||||||
| 					PACKAGES = ["grep", "sed", "awk"] | 					PACKAGES_TO_INSTALL = ["grep", "sed", "awk"] | ||||||
| 		case _: | 		case _: | ||||||
| 			logger.error("Distribution not supported by ogBoot.") | 			logger.error("Distribution not supported by ogBoot.") | ||||||
| 			exit(1) | 			exit(1) | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 	for package in PACKAGES_TO_INSTALL: | 	for package in PACKAGES_TO_INSTALL: | ||||||
| 		if not is_installed(package): | 		if not is_installed(package): | ||||||
| 			faltantes.append(package) | 			faltantes.append(package) | ||||||
|  | @ -218,6 +208,7 @@ def install_packages(missing, log_packages_file=f"/tmp/installed_packages.log"): | ||||||
| 			os.environ['DEBIAN_FRONTEND'] = original_debian_frontend | 			os.environ['DEBIAN_FRONTEND'] = original_debian_frontend | ||||||
| 		else: | 		else: | ||||||
| 			del os.environ['DEBIAN_FRONTEND'] | 			del os.environ['DEBIAN_FRONTEND'] | ||||||
|  | 
 | ||||||
| def autoConfigure(): | def autoConfigure(): | ||||||
| 	#distribution = platform.linux_distribution() | 	#distribution = platform.linux_distribution() | ||||||
| 	#distribution = distro.linux_distribution() | 	#distribution = distro.linux_distribution() | ||||||
|  | @ -229,20 +220,6 @@ def autoConfigure(): | ||||||
| 	logger.info(f"OSVERSION: {OSVERSION}") | 	logger.info(f"OSVERSION: {OSVERSION}") | ||||||
| 	# Configuración según la distribución OSDISTRIB | 	# Configuración según la distribución OSDISTRIB | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| def generate_config_url(): | def generate_config_url(): | ||||||
| 	with open('/etc/os-release', 'r') as file: | 	with open('/etc/os-release', 'r') as file: | ||||||
| 		lines = file.readlines() | 		lines = file.readlines() | ||||||
|  | @ -692,6 +669,21 @@ def mask2cidr(mask): | ||||||
| 		cidr += bin(int(i)).count("1") | 		cidr += bin(int(i)).count("1") | ||||||
| 	return cidr | 	return cidr | ||||||
| 
 | 
 | ||||||
|  | def get_first_network_interface_with_traffic(): | ||||||
|  |     with open('/proc/net/dev') as f: | ||||||
|  |         for line in f: | ||||||
|  |             if ':' in line: | ||||||
|  |                 parts = line.split(':') | ||||||
|  |                 if len(parts) > 1: | ||||||
|  |                     interface = parts[0].strip() | ||||||
|  |                     if interface != "lo": | ||||||
|  |                         traffic_data = parts[1].strip().split() | ||||||
|  |                         # Recibidos y enviados | ||||||
|  |                         received_bytes = int(traffic_data[0]) | ||||||
|  |                         transmitted_bytes = int(traffic_data[8]) | ||||||
|  |                         if received_bytes > 0 or transmitted_bytes > 0: | ||||||
|  |                             return interface | ||||||
|  | 
 | ||||||
| def getNetworkSettings(): | def getNetworkSettings(): | ||||||
| 	DHCPNET = "127.0.0.1" | 	DHCPNET = "127.0.0.1" | ||||||
| 	#print("getNetworkSettings(): Detecting network parameters.") | 	#print("getNetworkSettings(): Detecting network parameters.") | ||||||
|  | @ -724,6 +716,7 @@ def getNetworkSettings(): | ||||||
| 		return (0) | 		return (0) | ||||||
| 
 | 
 | ||||||
| def openGnsysConfigure(): | def openGnsysConfigure(): | ||||||
|  | 	global DEFAULTDEV | ||||||
| 	i = 0 | 	i = 0 | ||||||
| 	dev = "" | 	dev = "" | ||||||
| 	CONSOLEURL = "" | 	CONSOLEURL = "" | ||||||
|  | @ -732,9 +725,9 @@ def openGnsysConfigure(): | ||||||
| 		content = file.read() | 		content = file.read() | ||||||
| 		content = content.replace("SERVERIP", SERVER_OPENGNSYS) | 		content = content.replace("SERVERIP", SERVER_OPENGNSYS) | ||||||
| 		content = content.replace("OPENGNSYSURL", CONSOLEURL) | 		content = content.replace("OPENGNSYSURL", CONSOLEURL) | ||||||
| 		with open(f"{INSTALL_TARGET}/client/etc/ogAdmClient-ens160.cfg", "w") as outfile: | 		with open(f"{INSTALL_TARGET}/client/etc/ogAdmClient-{DEFAULTDEV}.cfg", "w") as outfile: | ||||||
| 			outfile.write(content) | 			outfile.write(content) | ||||||
| 	os.symlink(f"{INSTALL_TARGET}/client/etc/ogAdmClient-ens160.cfg", f"{INSTALL_TARGET}/client/etc/ogAdmClient.cfg") | 	os.symlink(f"{INSTALL_TARGET}/client/etc/ogAdmClient-{DEFAULTDEV}.cfg", f"{INSTALL_TARGET}/client/etc/ogAdmClient.cfg") | ||||||
| 	TZ = subprocess.check_output(["timedatectl", "status"]).decode().split("\n")[2].split(":")[1].strip() | 	TZ = subprocess.check_output(["timedatectl", "status"]).decode().split("\n")[2].split(":")[1].strip() | ||||||
| 	with open(f"{INSTALL_TARGET}/client/etc/engine.cfg", "a") as file: | 	with open(f"{INSTALL_TARGET}/client/etc/engine.cfg", "a") as file: | ||||||
| 		file.write(f"# OpenGnsys Server timezone.\nTZ=\"{TZ.replace(' ', '')}\"\n") | 		file.write(f"# OpenGnsys Server timezone.\nTZ=\"{TZ.replace(' ', '')}\"\n") | ||||||
|  | @ -746,7 +739,7 @@ def mount_NFS(): | ||||||
| 	else: | 	else: | ||||||
| 		logger.error("Could not mount the NFS system.") | 		logger.error("Could not mount the NFS system.") | ||||||
| 		exit(1) | 		exit(1) | ||||||
| 	logger.info("copy ipxe::::::::::::::::::::::::::::") | 	logger.info("copying tftp and ipxe files") | ||||||
| 	#subprocess.call(["ls", "/mnt/"]) | 	#subprocess.call(["ls", "/mnt/"]) | ||||||
| 	subprocess.call(["sudo", "cp", "-r", "/mnt/srv/artefactos/ogboot/tftpboot/", "/tmp"]) | 	subprocess.call(["sudo", "cp", "-r", "/mnt/srv/artefactos/ogboot/tftpboot/", "/tmp"]) | ||||||
| 	if not os.path.exists(IPXE_DIR + "/tftpboot"): | 	if not os.path.exists(IPXE_DIR + "/tftpboot"): | ||||||
|  | @ -781,7 +774,8 @@ def mount_NFS(): | ||||||
| 	subprocess.call(["sudo", "cp", "bin-x86_64-efi/ipxe.efi", f"{INSTALL_OPENGNSYS_TARGET}/tftpboot"]) | 	subprocess.call(["sudo", "cp", "bin-x86_64-efi/ipxe.efi", f"{INSTALL_OPENGNSYS_TARGET}/tftpboot"]) | ||||||
| 
 | 
 | ||||||
| def generate_ipxe_script(): | def generate_ipxe_script(): | ||||||
| 	ip_address_server = subprocess.check_output(["ifconfig", "ens160"]).decode().split("\n")[1].split()[1] | 	global DEFAULTDEV | ||||||
|  | 	ip_address_server = subprocess.check_output(["ifconfig", DEFAULTDEV]).decode().split("\n")[1].split()[1] | ||||||
| 	template = os.path.join(WORKDIR, "ogboot/etc/dhcp_boot.ipxe.tmpl") | 	template = os.path.join(WORKDIR, "ogboot/etc/dhcp_boot.ipxe.tmpl") | ||||||
| 	ipxe_output = f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe" | 	ipxe_output = f"{INSTALL_OGBOOT_TARGET}/tftpboot/ipxe_scripts/dhcp_boot.ipxe" | ||||||
| 	os.makedirs(os.path.dirname(ipxe_output), mode=0o750, exist_ok=True) | 	os.makedirs(os.path.dirname(ipxe_output), mode=0o750, exist_ok=True) | ||||||
|  | @ -847,25 +841,11 @@ def smbConfigure(): | ||||||
| 	logger.info(f"Added Samba configuration.") | 	logger.info(f"Added Samba configuration.") | ||||||
| 	return 0 | 	return 0 | ||||||
| 
 | 
 | ||||||
| def get_network_interfaces(): |  | ||||||
| 	interfaces = [] |  | ||||||
| 	with open('/proc/net/dev') as f: |  | ||||||
| 		for line in f: |  | ||||||
| 			if ':' in line: |  | ||||||
| 				parts = line.split(':') |  | ||||||
| 				if len(parts) > 1: |  | ||||||
| 					if parts[0].strip() != "lo": |  | ||||||
| 						interface = parts[0].strip()  # Accessing the first part as the interface name |  | ||||||
| 						interfaces.append(interface) |  | ||||||
| 	return interfaces |  | ||||||
| 
 |  | ||||||
| print(get_network_interfaces()) |  | ||||||
| #exit (0) |  | ||||||
| 
 |  | ||||||
| def setup_nginx(): | def setup_nginx(): | ||||||
|  | 	global DEFAULTDEV | ||||||
| 	try: | 	try: | ||||||
| 		# Obtener la IP del servidor | 		# Obtener la IP del servidor | ||||||
| 		ip_address_server = subprocess.check_output(["ifconfig", "ens160"]).decode().split("\n")[1].split()[1] | 		ip_address_server = subprocess.check_output(["ifconfig", DEFAULTDEV]).decode().split("\n")[1].split()[1] | ||||||
| 		 | 		 | ||||||
| 		# Leer y modificar la plantilla de configuración de nginx | 		# Leer y modificar la plantilla de configuración de nginx | ||||||
| 		template_path = os.path.join(WORKDIR, "ogboot/etc/nginxServer.conf.tmpl") | 		template_path = os.path.join(WORKDIR, "ogboot/etc/nginxServer.conf.tmpl") | ||||||
|  | @ -1002,7 +982,6 @@ def install_oglive_daemon(): | ||||||
| ###:::::::::::::::::::::::::::::::: MAIN :::::::::::::::::::::::::::::::::::### | ###:::::::::::::::::::::::::::::::: MAIN :::::::::::::::::::::::::::::::::::### | ||||||
| ############################################################################### | ############################################################################### | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| logger.info(f"Starting installation of ogBoot.") | logger.info(f"Starting installation of ogBoot.") | ||||||
| if os.geteuid() != 0: | if os.geteuid() != 0: | ||||||
| 	logger.error("This program must be run with root privileges..") | 	logger.error("This program must be run with root privileges..") | ||||||
|  | @ -1023,6 +1002,8 @@ Missing = get_missing_packages () | ||||||
| install_packages(Missing) | install_packages(Missing) | ||||||
| 
 | 
 | ||||||
| logger.info("Obtaining the default network configuration.") | logger.info("Obtaining the default network configuration.") | ||||||
|  | DEFAULTDEV = get_first_network_interface_with_traffic() | ||||||
|  | logger.info(f"Network interface default:[{DEFAULTDEV}]") | ||||||
| if getNetworkSettings() != 0: | if getNetworkSettings() != 0: | ||||||
| 	logger.error("Error reading default network settings.") | 	logger.error("Error reading default network settings.") | ||||||
| 	exit(1) | 	exit(1) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue