ogclone-engine/client/etc/preinit/fileslinks.py

74 lines
2.6 KiB
Python

import os
import shutil
import stat
# Si está configurado OpenGnsys ...
if os.getenv("OPENGNSYS"):
print(os.getenv("MSG_MAKELINKS", "."))
# Shell BASH por defecto (para usar "runtest")
try:
os.symlink('/bin/bash', '/bin/sh')
except FileExistsError:
pass
# Crear directorio de bloqueos
os.makedirs('/var/lock', exist_ok=True)
if not os.path.exists('/var/lock'):
os.makedirs('/run/lock', exist_ok=True)
# Crear ficheros temporales.
oglogcommand = os.getenv("OGLOGCOMMAND")
oglogsession = os.getenv("OGLOGSESSION")
temp_files = [oglogcommand, f"{oglogcommand}.tmp", oglogsession, "/tmp/menu.tmp"]
for temp_file in temp_files:
with open(temp_file, 'a'):
os.utime(temp_file, None)
os.chmod(temp_file, 0o777)
#####################################################################################
##### Pendiente instalar Qt5 en el sistema y crear enlaces simbólicos a las librerías
# Enlaces para Qt Embeded. ######################################################
qtdir = "/usr/local"
os.makedirs(os.path.join(qtdir, 'etc'), exist_ok=True)
os.makedirs(os.path.join(qtdir, 'lib'), exist_ok=True)
os.makedirs(os.path.join(qtdir, 'plugins'), exist_ok=True)
oglib = os.getenv("OGLIB")
for i in os.listdir(os.path.join(oglib, 'qtlib')) + [os.path.join(oglib, 'fonts')]:
src = os.path.join(oglib, 'qtlib', i)
dst = os.path.join(qtdir, 'lib', i)
if not os.path.exists(dst):
try:
os.symlink(src, dst)
except FileExistsError:
pass
for i in os.listdir(os.path.join(oglib, 'qtplugins')):
src = os.path.join(oglib, 'qtplugins', i)
dst = os.path.join(qtdir, 'plugins', i)
if not os.path.exists(dst):
try:
os.symlink(src, dst)
except FileExistsError:
pass
ogetc = os.getenv("OGETC")
for i in os.listdir(ogetc):
if i.endswith('.qmap'):
src = os.path.join(ogetc, i)
dst = os.path.join(qtdir, 'etc', i)
if not os.path.exists(dst):
try:
os.symlink(src, dst)
except FileExistsError:
pass
# Autenticación con clave pública para SSH
if os.path.isfile('/scripts/ssl/authorized_keys'):
for file in os.listdir('/scripts/ssl'):
shutil.copy(os.path.join('/scripts/ssl', file), '/root/.ssh')
else:
# FIXME Error: entorno de OpenGnsys no configurado.
print("Error: OpenGnsys environment is not configured.") # FIXME: definir mensaje.
exit(1)