1 | #!/usr/bin/python3 |
---|
2 | |
---|
3 | import sys |
---|
4 | import os |
---|
5 | import logging |
---|
6 | |
---|
7 | sys.path.insert (0, __file__) |
---|
8 | from boottoolsfunctions import btogGetOsInfo1, btogGetOsInfo2, btogGetVar |
---|
9 | |
---|
10 | logging.basicConfig (filename='/tmp/boot-tools_installation.log', filemode='a', format='%(levelname)s %(asctime)s (%(threadName)s) (%(funcName)s) %(message)s', level=logging.INFO) |
---|
11 | logger = logging.getLogger ('boottools') |
---|
12 | |
---|
13 | #BRANCH = 'branches/master' |
---|
14 | #svn export --force https://github.com/opengnsys/OpenGnsys/$BRANCH/client /tmp/opengnsys_installer/opengnsys/client |
---|
15 | |
---|
16 | type_client = sys.argv[1] if len(sys.argv)>1 else 'host' |
---|
17 | #WORKDIR = '/tmp/opengnsys_installer' |
---|
18 | #INSTALL_TARGET = '/opt/opengnsys' |
---|
19 | #PROGRAMDIR = $(readlink -e $(dirname "$0")) |
---|
20 | |
---|
21 | if os.getuid(): |
---|
22 | logger.error ('ERROR: this program must run under root privileges!!') |
---|
23 | os._exit (1) |
---|
24 | |
---|
25 | os.chdir ('/tmp') |
---|
26 | |
---|
27 | #for i in `mount | grep IMGogclient | grep /var | cut -f3 -d" "`; do echo $i; umount $i; done |
---|
28 | #for i in `mount | grep IMGogclient | grep /var | cut -f3 -d" "`; do echo $i; umount $i; done |
---|
29 | #for i in `mount | grep IMGogclient | grep /var | cut -f3 -d" "`; do echo $i; umount $i; done |
---|
30 | |
---|
31 | |
---|
32 | |
---|
33 | ####################################################################3 |
---|
34 | logger.info ('FASE 1 - Asignación de variables') |
---|
35 | ogclientcfg, osdistrib, oscodename, osrelease, osarch, oshttp = btogGetOsInfo1(type_client) |
---|
36 | print (osarch) |
---|
37 | btdir, bttargetdir, btrootfsimg, btrootfsmnt, btrootfsimglabel, log_file, versionboottools, btvirtualdisksize = btogGetVar(osarch) |
---|
38 | print (btdir) |
---|
39 | gitrelease, nameisoclient, namehostclient = btogGetOsInfo2(type_client, versionboottools, ogclientcfg, osdistrib, oscodename, osrelease, osarch, oshttp) |
---|
40 | print (nameisoclient) |
---|
41 | logger.info ('OpenGnsys CLIENT installation begins') |
---|
42 | |
---|
43 | |
---|
44 | ########################################################################## |
---|
45 | logger.info ('FASE 2 - Instalación de software adicional.') |
---|
46 | """ |
---|
47 | #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 |
---|
48 | apt-get update >>/tmp/fase2.out |
---|
49 | [ -n "$(apt-cache search gpxe)" ] && PXEPKG="gpxe" |
---|
50 | [ -n "$(apt-cache search ipxe)" ] && PXEPKG="ipxe" |
---|
51 | apt-get -y install debootstrap subversion schroot squashfs-tools syslinux genisoimage $PXEPKG qemu qemu-utils lsof >>/tmp/fase2.out |
---|
52 | |
---|
53 | |
---|
54 | ###################################################################3 |
---|
55 | logger.info ('FASE 3 - Creación del Sistema raiz RootFS (Segundo Sistema archivos (img))') |
---|
56 | logger.info ('Fase 3.1 Generar y formatear el disco virtual. Generar el dispositivo loop.') |
---|
57 | file $BTROOTFSIMG | grep "partition 1: ID=0x83" |
---|
58 | if [ $? == 1 ]: |
---|
59 | btogSetFsVirtual || exit 2 |
---|
60 | echo ================= nati after btogSetFsVirtual; ls -la /opt/opengnsys/tftpboot/ogclient/ |
---|
61 | |
---|
62 | logger.info ('Fase 3.2 Generar sistema de archivos con debootstrap') |
---|
63 | schroot -p -c IMGogclient -- touch /tmp/ogclientOK |
---|
64 | if [ -f /tmp/ogclientOK ] |
---|
65 | then |
---|
66 | rm /tmp/ogclientOK |
---|
67 | else |
---|
68 | btogSetFsBase >>/tmp/fase3.out |
---|
69 | fi |
---|
70 | echo ================= nati after fase 3; ls -la /opt/opengnsys/tftpboot/ogclient/ |
---|
71 | |
---|
72 | |
---|
73 | ###################################################################3 |
---|
74 | logger.info ('FASE 4 - Configurar acceso schroot al Segundo Sistema de archivos (img)') |
---|
75 | cat /etc/schroot/schroot.conf | grep $BTROOTFSIMG || btogSetFsAccess |
---|
76 | |
---|
77 | |
---|
78 | ########################################################################### |
---|
79 | logger.info ('FASE 5 - Incorporando ficheros OpenGnsys al sistema raíz rootfs') |
---|
80 | cp -a ${BTDIR}/includes/usr/bin/* /tmp >>/tmp/fase5.out |
---|
81 | chmod +x /tmp/boot-tools/*.sh |
---|
82 | # Incluir revisión. |
---|
83 | sed -i "1 s/$/ $GITRELEASE ($OSRELEASE)/" ${BTDIR}/includes/etc/initramfs-tools/scripts/VERSION.txt |
---|
84 | # En Ubuntu 13.04+ es necesario matar proceso de "udev" antes de desmontar. |
---|
85 | umount $BTROOTFSMNT 2>/dev/null || (kill -9 $(lsof -t $BTROOTFSMNT); umount $BTROOTFSMNT) 2>/dev/null |
---|
86 | schroot -p -c IMGogclient -- /tmp/boot-tools/boottoolsFsOpengnsys.sh >>/tmp/fase5.out |
---|
87 | |
---|
88 | |
---|
89 | ############################################################################################ |
---|
90 | logger.info ('FASE 6 - Instalar software') |
---|
91 | logger.info ('Fase 6.1 instalar paquetes deb con apt-get') |
---|
92 | schroot -p -c IMGogclient -- /usr/bin/boot-tools/boottoolsSoftwareInstall.sh >>/tmp/fase6.out |
---|
93 | logger.info ('Fase 6.2 compilar software.') |
---|
94 | cd / |
---|
95 | schroot -p -c IMGogclient -- /usr/bin/boot-tools/boottoolsSoftwareCompile.sh >>/tmp/fase6.out |
---|
96 | cd - |
---|
97 | |
---|
98 | |
---|
99 | ############################################################################################ |
---|
100 | logger.info ('FASE 7 - Personalizar el sistema creado') |
---|
101 | logger.info ('Fase 7.1 Incorporar la clave publica del servidor') |
---|
102 | cd / |
---|
103 | ssh-keygen -q -f /root/.ssh/id_rsa -N "" |
---|
104 | cp /root/.ssh/id_rsa.pub /tmp |
---|
105 | schroot -p -c IMGogclient -- /usr/bin/boot-tools/boottoolsSshServer.sh |
---|
106 | cd - |
---|
107 | logger.info ('Fase 7.2. Incorpoar la clave publica del propio cliente') |
---|
108 | schroot -p -c IMGogclient -- /usr/bin/boot-tools/boottoolsSshClient.sh |
---|
109 | |
---|
110 | logger.info ('Fase 7.3. Configurando las locales') |
---|
111 | schroot -p -c IMGogclient -- /usr/bin/boot-tools/boottoolsFsLocales.sh |
---|
112 | |
---|
113 | for i in `mount | grep IMGogclient | grep /var | cut -f3 -d" "`; do echo $i; umount $i; done |
---|
114 | for i in `mount | grep IMGogclient | grep /var | cut -f3 -d" "`; do echo $i; umount $i; done |
---|
115 | for i in `mount | grep IMGogclient | grep /var | cut -f3 -d" "`; do echo $i; umount $i; done |
---|
116 | |
---|
117 | echo ================= nati after fase 7; ls -la /opt/opengnsys/tftpboot/ogclient/ |
---|
118 | |
---|
119 | |
---|
120 | ######################################################################### |
---|
121 | logger.info ('FASE 8 - Generar distribucion') |
---|
122 | logger.info ('Fase 8.1 Generar el initrd') |
---|
123 | btogFsInitrd >>/tmp/fase8.out |
---|
124 | echo ================= nati after fase 8.1; ls -la /opt/opengnsys/tftpboot/ogclient/ |
---|
125 | logger.info ('Fase 8.2 Generar fichero sqfs a partir del fichero img') |
---|
126 | btogFsSqfs |
---|
127 | echo ================= nati after fase 8.2; ls -la /opt/opengnsys/tftpboot/ogclient/ |
---|
128 | umount $BTROOTFSMNT 2>/dev/null |
---|
129 | logger.info ('Fase 8.3 Generar la ISO') |
---|
130 | btogIsoGenerator >>/tmp/fase8.out |
---|
131 | echo ================= nati after fase 8.3; ls -la /opt/opengnsys/tftpboot/ogclient/ |
---|
132 | |
---|
133 | echoAndLog "OpenGnsys installation finished at $(date)" |
---|
134 | """ |
---|