135 lines
5.9 KiB
Python
135 lines
5.9 KiB
Python
#!/usr/bin/python3
|
|
|
|
import sys
|
|
import os
|
|
import logging
|
|
|
|
sys.path.insert (0, __file__)
|
|
from boottoolsfunctions import btogGetOsInfo1, btogGetOsInfo2, btogGetVar
|
|
|
|
logging.basicConfig (filename='/tmp/boot-tools_installation.log', filemode='a', format='%(levelname)s %(asctime)s (%(threadName)s) (%(funcName)s) %(message)s', level=logging.INFO)
|
|
logger = logging.getLogger ('boottools')
|
|
|
|
#BRANCH = 'branches/master'
|
|
#svn export --force https://github.com/opengnsys/OpenGnsys/$BRANCH/client /tmp/opengnsys_installer/opengnsys/client
|
|
|
|
type_client = sys.argv[1] if len(sys.argv)>1 else 'host'
|
|
#WORKDIR = '/tmp/opengnsys_installer'
|
|
#INSTALL_TARGET = '/opt/opengnsys'
|
|
#PROGRAMDIR = $(readlink -e $(dirname "$0"))
|
|
|
|
if os.getuid():
|
|
logger.error ('ERROR: this program must run under root privileges!!')
|
|
os._exit (1)
|
|
|
|
os.chdir ('/tmp')
|
|
|
|
#for i in `mount | grep IMGogclient | grep /var | cut -f3 -d" "`; do echo $i; umount $i; done
|
|
#for i in `mount | grep IMGogclient | grep /var | cut -f3 -d" "`; do echo $i; umount $i; done
|
|
#for i in `mount | grep IMGogclient | grep /var | cut -f3 -d" "`; do echo $i; umount $i; done
|
|
|
|
|
|
|
|
####################################################################3
|
|
logger.info ('FASE 1 - Asignación de variables')
|
|
ogclientcfg, osdistrib, oscodename, osrelease, osarch, oshttp = btogGetOsInfo1(type_client)
|
|
print (osarch)
|
|
btdir, bttargetdir, btrootfsimg, btrootfsmnt, btrootfsimglabel, log_file, versionboottools, btvirtualdisksize = btogGetVar(osarch)
|
|
print (btdir)
|
|
gitrelease, nameisoclient, namehostclient = btogGetOsInfo2(type_client, versionboottools, ogclientcfg, osdistrib, oscodename, osrelease, osarch, oshttp)
|
|
print (nameisoclient)
|
|
logger.info ('OpenGnsys CLIENT installation begins')
|
|
|
|
|
|
##########################################################################
|
|
logger.info ('FASE 2 - Instalación de software adicional.')
|
|
"""
|
|
#grep "http://free.nchc.org.tw/drbl-core" /etc/apt/sources.list || echo "deb http://free.nchc.org.tw/drbl-core drbl stable" >> /etc/apt/sources.list
|
|
apt-get update >>/tmp/fase2.out
|
|
[ -n "$(apt-cache search gpxe)" ] && PXEPKG="gpxe"
|
|
[ -n "$(apt-cache search ipxe)" ] && PXEPKG="ipxe"
|
|
apt-get -y install debootstrap subversion schroot squashfs-tools syslinux genisoimage $PXEPKG qemu qemu-utils lsof >>/tmp/fase2.out
|
|
|
|
|
|
###################################################################3
|
|
logger.info ('FASE 3 - Creación del Sistema raiz RootFS (Segundo Sistema archivos (img))')
|
|
logger.info ('Fase 3.1 Generar y formatear el disco virtual. Generar el dispositivo loop.')
|
|
file $BTROOTFSIMG | grep "partition 1: ID=0x83"
|
|
if [ $? == 1 ]:
|
|
btogSetFsVirtual || exit 2
|
|
echo ================= nati after btogSetFsVirtual; ls -la /opt/opengnsys/tftpboot/ogclient/
|
|
|
|
logger.info ('Fase 3.2 Generar sistema de archivos con debootstrap')
|
|
schroot -p -c IMGogclient -- touch /tmp/ogclientOK
|
|
if [ -f /tmp/ogclientOK ]
|
|
then
|
|
rm /tmp/ogclientOK
|
|
else
|
|
btogSetFsBase >>/tmp/fase3.out
|
|
fi
|
|
echo ================= nati after fase 3; ls -la /opt/opengnsys/tftpboot/ogclient/
|
|
|
|
|
|
###################################################################3
|
|
logger.info ('FASE 4 - Configurar acceso schroot al Segundo Sistema de archivos (img)')
|
|
cat /etc/schroot/schroot.conf | grep $BTROOTFSIMG || btogSetFsAccess
|
|
|
|
|
|
###########################################################################
|
|
logger.info ('FASE 5 - Incorporando ficheros OpenGnsys al sistema raíz rootfs')
|
|
cp -a ${BTDIR}/includes/usr/bin/* /tmp >>/tmp/fase5.out
|
|
chmod +x /tmp/boot-tools/*.sh
|
|
# Incluir revisión.
|
|
sed -i "1 s/$/ $GITRELEASE ($OSRELEASE)/" ${BTDIR}/includes/etc/initramfs-tools/scripts/VERSION.txt
|
|
# En Ubuntu 13.04+ es necesario matar proceso de "udev" antes de desmontar.
|
|
umount $BTROOTFSMNT 2>/dev/null || (kill -9 $(lsof -t $BTROOTFSMNT); umount $BTROOTFSMNT) 2>/dev/null
|
|
schroot -p -c IMGogclient -- /tmp/boot-tools/boottoolsFsOpengnsys.sh >>/tmp/fase5.out
|
|
|
|
|
|
############################################################################################
|
|
logger.info ('FASE 6 - Instalar software')
|
|
logger.info ('Fase 6.1 instalar paquetes deb con apt-get')
|
|
schroot -p -c IMGogclient -- /usr/bin/boot-tools/boottoolsSoftwareInstall.sh >>/tmp/fase6.out
|
|
logger.info ('Fase 6.2 compilar software.')
|
|
cd /
|
|
schroot -p -c IMGogclient -- /usr/bin/boot-tools/boottoolsSoftwareCompile.sh >>/tmp/fase6.out
|
|
cd -
|
|
|
|
|
|
############################################################################################
|
|
logger.info ('FASE 7 - Personalizar el sistema creado')
|
|
logger.info ('Fase 7.1 Incorporar la clave publica del servidor')
|
|
cd /
|
|
ssh-keygen -q -f /root/.ssh/id_rsa -N ""
|
|
cp /root/.ssh/id_rsa.pub /tmp
|
|
schroot -p -c IMGogclient -- /usr/bin/boot-tools/boottoolsSshServer.sh
|
|
cd -
|
|
logger.info ('Fase 7.2. Incorpoar la clave publica del propio cliente')
|
|
schroot -p -c IMGogclient -- /usr/bin/boot-tools/boottoolsSshClient.sh
|
|
|
|
logger.info ('Fase 7.3. Configurando las locales')
|
|
schroot -p -c IMGogclient -- /usr/bin/boot-tools/boottoolsFsLocales.sh
|
|
|
|
for i in `mount | grep IMGogclient | grep /var | cut -f3 -d" "`; do echo $i; umount $i; done
|
|
for i in `mount | grep IMGogclient | grep /var | cut -f3 -d" "`; do echo $i; umount $i; done
|
|
for i in `mount | grep IMGogclient | grep /var | cut -f3 -d" "`; do echo $i; umount $i; done
|
|
|
|
echo ================= nati after fase 7; ls -la /opt/opengnsys/tftpboot/ogclient/
|
|
|
|
|
|
#########################################################################
|
|
logger.info ('FASE 8 - Generar distribucion')
|
|
logger.info ('Fase 8.1 Generar el initrd')
|
|
btogFsInitrd >>/tmp/fase8.out
|
|
echo ================= nati after fase 8.1; ls -la /opt/opengnsys/tftpboot/ogclient/
|
|
logger.info ('Fase 8.2 Generar fichero sqfs a partir del fichero img')
|
|
btogFsSqfs
|
|
echo ================= nati after fase 8.2; ls -la /opt/opengnsys/tftpboot/ogclient/
|
|
umount $BTROOTFSMNT 2>/dev/null
|
|
logger.info ('Fase 8.3 Generar la ISO')
|
|
btogIsoGenerator >>/tmp/fase8.out
|
|
echo ================= nati after fase 8.3; ls -la /opt/opengnsys/tftpboot/ogclient/
|
|
|
|
echoAndLog "OpenGnsys installation finished at $(date)"
|
|
"""
|