1 | import platform |
---|
2 | import os |
---|
3 | import time |
---|
4 | import logging |
---|
5 | import subprocess |
---|
6 | import shutil |
---|
7 | import glob |
---|
8 | import datetime |
---|
9 | |
---|
10 | from . import utils |
---|
11 | |
---|
12 | logger = logging.getLogger ('boottools') |
---|
13 | |
---|
14 | def GetVar (osarch): |
---|
15 | bttargetdir = '/var/lib/tftpboot/ogclient/' |
---|
16 | btrootfsimg = os.path.join (bttargetdir, 'ogclient.img') |
---|
17 | btrootfsmnt = os.path.join (bttargetdir, 'ogclientmount') |
---|
18 | if 'i386' == osarch: |
---|
19 | btvirtualdisksize = '2000' # tamaño maximo limitado por schroot 2GB para 32 bits |
---|
20 | else: |
---|
21 | btvirtualdisksize = '5G' |
---|
22 | return bttargetdir, btrootfsimg, btrootfsmnt, btvirtualdisksize |
---|
23 | |
---|
24 | def GetOsInfo (type_client='host'): |
---|
25 | if 'precise' == type_client: # ogLive 1.0.4-rc2 basado en Ubuntu 12.04 LTS. |
---|
26 | osdistrib='ubuntu' |
---|
27 | oscodename='precise' |
---|
28 | osrelease='3.2.0-23-generic' |
---|
29 | osarch='i386' |
---|
30 | oshttp='http://es.archive.ubuntu.com/ubuntu/' |
---|
31 | elif 'wheezy' == type_client: # ogLive basado en Debian 7.3. |
---|
32 | osdistrib='debian' |
---|
33 | oscodename='wheezy' |
---|
34 | osrelease='3.2.0-4-i386' |
---|
35 | osarch='i386' |
---|
36 | oshttp='http://ftp.es.debian.org/debian/' |
---|
37 | elif 'quantal' == type_client: # ogLive 1.0.5-rc2 basado en Ubuntu 12.10 con Kernel descargado. |
---|
38 | osdistrib='ubuntu' |
---|
39 | oscodename='quantal' |
---|
40 | osrelease='3.7.6-030706-generic' |
---|
41 | osarch='i386' |
---|
42 | oshttp='http://es.archive.ubuntu.com/ubuntu/' |
---|
43 | elif 'raring' == type_client: # ogLive 1.0.5-rc3 basado en Ubuntu 13.04. |
---|
44 | osdistrib='ubuntu' |
---|
45 | oscodename='raring' |
---|
46 | osrelease='3.8.0-22-generic' |
---|
47 | osarch='i386' |
---|
48 | oshttp='http://es.archive.ubuntu.com/ubuntu/' |
---|
49 | elif 'trusty' == type_client: # ogLive 1.0.5-rc4 basado en Ubuntu 14.04. |
---|
50 | osdistrib='ubuntu' |
---|
51 | oscodename='trusty' |
---|
52 | osrelease='3.13.0-24-generic' |
---|
53 | osarch='i386' |
---|
54 | oshttp='http://es.archive.ubuntu.com/ubuntu/' |
---|
55 | elif 'vivid' == type_client: # ogLive 1.1.0-rc2 basado en Ubuntu 15.04. |
---|
56 | osdistrib='ubuntu' |
---|
57 | oscodename='vivid' |
---|
58 | osrelease='3.19.0-49-generic' |
---|
59 | osarch='i386' |
---|
60 | oshttp='http://es.archive.ubuntu.com/ubuntu/' |
---|
61 | elif 'wily' == type_client: # ogLive 1.1.0-rc1 basado en Ubuntu 15.10. |
---|
62 | osdistrib='ubuntu' |
---|
63 | oscodename='wily' |
---|
64 | osrelease='4.2.0-35-generic' |
---|
65 | osarch='i386' |
---|
66 | oshttp='http://es.archive.ubuntu.com/ubuntu/' |
---|
67 | elif 'xenial' == type_client or 'xenial-4.4' == type_client: # ogLive 1.1.0-rc4 basado en Ubuntu 16.04 y Kernel 4.4. |
---|
68 | osdistrib='ubuntu' |
---|
69 | oscodename='xenial' |
---|
70 | osrelease='4.4.0-34-generic' |
---|
71 | osarch='i386' |
---|
72 | oshttp='http://es.archive.ubuntu.com/ubuntu/' |
---|
73 | elif 'xenial-4.8' == type_client: # ogLive 1.1.0-rc5 basado en Ubuntu 16.04 y Kernel 4.8. |
---|
74 | osdistrib='ubuntu' |
---|
75 | oscodename='xenial' |
---|
76 | osrelease='4.8.0-39-generic' |
---|
77 | osarch='amd64' |
---|
78 | oshttp='http://es.archive.ubuntu.com/ubuntu/' |
---|
79 | elif 'xenial-4.13' == type_client: # ogLive 1.1.0-rc6 basado en Ubuntu 16.04 y Kernel 4.13. |
---|
80 | osdistrib='ubuntu' |
---|
81 | oscodename='xenial' |
---|
82 | osrelease='4.13.0-17-generic' |
---|
83 | osarch='amd64' |
---|
84 | oshttp='http://es.archive.ubuntu.com/ubuntu/' |
---|
85 | elif 'bionic' == type_client or 'bionic-4.15' == type_client: # ogLive 1.1.1-rc1 basado en Ubuntu 18.04 y Kernel 4.15. |
---|
86 | osdistrib='ubuntu' |
---|
87 | oscodename='bionic' |
---|
88 | osrelease='4.15.0-32-generic' |
---|
89 | osarch='amd64' |
---|
90 | oshttp='http://es.archive.ubuntu.com/ubuntu/' |
---|
91 | elif 'bionic-4.18' == type_client: # ogLive 1.1.1-rc3 basado en Ubuntu 18.04 y Kernel 4.18. |
---|
92 | osdistrib='ubuntu' |
---|
93 | oscodename='bionic' |
---|
94 | osrelease='4.18.0-20-generic' |
---|
95 | osarch='amd64' |
---|
96 | oshttp='http://es.archive.ubuntu.com/ubuntu/' |
---|
97 | elif 'bionic-5.0' == type_client: # ogLive 1.1.1-rc5 basado en Ubuntu 18.04 y Kernel 5.0. |
---|
98 | osdistrib='ubuntu' |
---|
99 | oscodename='bionic' |
---|
100 | osrelease='5.0.0-27-generic' |
---|
101 | osarch='amd64' |
---|
102 | oshttp='http://es.archive.ubuntu.com/ubuntu/' |
---|
103 | elif 'focal' == type_client: # ogLive 1.2.0-rc1 basado en Ubuntu 20.04 y Kernel 5.4. |
---|
104 | osdistrib='ubuntu' |
---|
105 | oscodename='focal' |
---|
106 | osrelease='5.4.0-42-generic' |
---|
107 | osarch='amd64' |
---|
108 | oshttp='http://es.archive.ubuntu.com/ubuntu/' |
---|
109 | elif 'noble' == type_client: # ogLive 3.1.1 basado en Ubuntu 24.04 y Kernel 6.8. |
---|
110 | osdistrib='ubuntu' |
---|
111 | oscodename='noble' |
---|
112 | osrelease='6.8.0-31-generic' |
---|
113 | osarch='amd64' |
---|
114 | oshttp='http://es.archive.ubuntu.com/ubuntu/' |
---|
115 | elif 'host' == type_client: # ogLive basado en la distribución del servidor. |
---|
116 | osdistrib=platform.freedesktop_os_release()['NAME'] |
---|
117 | oscodename=platform.freedesktop_os_release()['VERSION_CODENAME'] |
---|
118 | osrelease=platform.uname()[2] |
---|
119 | osarch, _=utils.run (['dpkg', '--print-architecture']) |
---|
120 | oshttp='http://es.archive.ubuntu.com/ubuntu/' |
---|
121 | else: # Parámetro desconocido |
---|
122 | logger.error ('Parámetro no válido.') |
---|
123 | osdistrib=None |
---|
124 | oscodename=None |
---|
125 | osrelease=None |
---|
126 | osarch=None |
---|
127 | oshttp=None |
---|
128 | return osdistrib, oscodename, osrelease, osarch, oshttp |
---|
129 | |
---|
130 | def mkrootfs (btrootfsimg, btrootfsimglabel, btrootfsmnt, btvirtualdisksize, bttargetdir, osarch): |
---|
131 | logger.info (f'Creación y formateo del disco virtual "{btrootfsimg}" "{btvirtualdisksize}" MB') |
---|
132 | |
---|
133 | try: utils.umount (btrootfsmnt) |
---|
134 | except: pass |
---|
135 | |
---|
136 | if (utils.is_mounted (btrootfsmnt)): |
---|
137 | raise Exception (f'failed to umount "{btrootfsmnt}"') |
---|
138 | |
---|
139 | try: os.makedirs (btrootfsmnt, exist_ok=True) |
---|
140 | except: |
---|
141 | raise Exception (f'Creando directorio "{btrootfsmnt}" : ERROR') |
---|
142 | |
---|
143 | try: utils.run (['chown', '-R', 'root:opengnsys', bttargetdir]) |
---|
144 | except Exception as e: |
---|
145 | raise Exception (f'Failed to chown root:opengnsys "{btrootfsmnt}": {str(e)}') |
---|
146 | |
---|
147 | logger.info (f'Creating disk image "{btrootfsimg}"') |
---|
148 | if 'i386' == osarch: |
---|
149 | try: utils.run (['dd', 'if=/dev/zero', f'of={btrootfsimg}', 'bs=1048576', f'count={btvirtualdisksize}']) |
---|
150 | except Exception as e: |
---|
151 | raise Exception (f'Creando el disco virtual "{btrootfsimg}" con tamaño maxima "{btvirtualdisksize}" MB : ERROR: {str(e)}') |
---|
152 | else: |
---|
153 | try: utils.run (['qemu-img', 'create', btrootfsimg, btvirtualdisksize]) |
---|
154 | except Exception as e: |
---|
155 | raise Exception (f'Creando el disco virtual "{btrootfsimg}" con tamaño maxima "{btvirtualdisksize}" MB : ERROR: {str(e)}') |
---|
156 | |
---|
157 | logger.debug ('losetup --find') |
---|
158 | diskloop, _ = utils.run (['losetup', '--find']) |
---|
159 | if not diskloop: |
---|
160 | raise Exception ('no diskloop') |
---|
161 | |
---|
162 | logger.debug ('losetup attach') |
---|
163 | try: utils.run (['losetup', '--partscan', diskloop, btrootfsimg]) |
---|
164 | except: raise Exception ('losetup failed') |
---|
165 | |
---|
166 | logger.info ('Partitioning disk image') |
---|
167 | stdout, _ = utils.run (['bash', '-c', f"echo $'n\np\n1\n\n\nt\n83\nw' |fdisk {diskloop}"]) |
---|
168 | |
---|
169 | time.sleep (3) |
---|
170 | logger.debug ('losetup --detach') |
---|
171 | try: utils.run (['losetup', '--detach', diskloop]) |
---|
172 | except: |
---|
173 | raise Exception ('Liberando disco virtual despues del particionado: ERROR') |
---|
174 | |
---|
175 | logger.debug ('losetup --find') |
---|
176 | partloop, _ = utils.run (['losetup', '--find']) |
---|
177 | if not partloop: |
---|
178 | raise Exception ('no partloop') |
---|
179 | |
---|
180 | logger.debug ('losetup --offset attach') |
---|
181 | utils.run (['losetup', '--offset', '32256', partloop, btrootfsimg]) |
---|
182 | |
---|
183 | logger.info ('Creating ext4 filesystem') |
---|
184 | try: utils.run (['mkfs.ext4', '-b', '4096', '-L', btrootfsimglabel, partloop]) |
---|
185 | except: |
---|
186 | raise Exception ('Formateando la particion principal del disco virtual: ERROR') |
---|
187 | |
---|
188 | time.sleep (3) |
---|
189 | logger.debug ('losetup --detach') |
---|
190 | try: utils.run (['losetup', '--detach', partloop]) |
---|
191 | except: |
---|
192 | raise Exception ('Liberando la particion virtual despues del formateo: ERROR') |
---|
193 | |
---|
194 | logger.info (f'"{btrootfsimg}" "{btvirtualdisksize}" MB : OK') |
---|
195 | |
---|
196 | # works on an already mounted rootfs |
---|
197 | def debootstrap (btrootfsimg, btrootfsmnt, osarch, oscodename, oshttp): |
---|
198 | logger.info ('Iniciando la generación del sistema de archivos') |
---|
199 | |
---|
200 | logger.info ('debootstrapping system') |
---|
201 | logger.debug (f'debootstrap --arch="{osarch}" --components=main,universe "{oscodename}" "{btrootfsmnt}" "{oshttp}"') |
---|
202 | try: utils.run (['debootstrap', f'--arch={osarch}', '--components=main,universe', oscodename, btrootfsmnt, oshttp]) |
---|
203 | except: raise Exception (f'debootstrap --arch="{osarch}" --components=main,universe "{oscodename}" "{btrootfsmnt}" "{oshttp}" : ha fallado!') |
---|
204 | |
---|
205 | logger.info (f'debootstrap --arch="{osarch}" --components=main,universe "{oscodename}" "{btrootfsmnt}" "{oshttp}" : ok') |
---|
206 | return 0 |
---|
207 | |
---|
208 | def copy_og_files (builder, og_shared, ogclientmount, osdistrib, oscodename): |
---|
209 | logger.info ('Iniciando la personalización con datos del repositorio') |
---|
210 | |
---|
211 | sources_list_in = f'{builder}/includes/etc/apt/sources.list.{osdistrib.lower()}' |
---|
212 | sources_list_out = f'{builder}/includes/etc/apt/sources.list' |
---|
213 | fdin = open (sources_list_in, 'r') |
---|
214 | fdout = open (sources_list_out, 'w') |
---|
215 | while True: |
---|
216 | l = fdin.readline() |
---|
217 | if not l: break |
---|
218 | fdout.write (l.replace ('OSCODENAME', oscodename)) |
---|
219 | fdin.close() |
---|
220 | fdout.close() |
---|
221 | |
---|
222 | subprocess.run (f'chmod -R 775 {builder}/includes/usr/bin/*', shell=True) |
---|
223 | |
---|
224 | os.makedirs (f'{ogclientmount}/opt/opengnsys/lib/engine/bin/', exist_ok=True) |
---|
225 | os.makedirs (f'{ogclientmount}/usr/local/etc', exist_ok=True) |
---|
226 | os.makedirs (f'{ogclientmount}/usr/local/lib', exist_ok=True) |
---|
227 | os.makedirs (f'{ogclientmount}/usr/local/plugins', exist_ok=True) |
---|
228 | |
---|
229 | subprocess.run (f'rsync -aH {builder}/includes/* {ogclientmount}/' , shell=True) |
---|
230 | subprocess.run (f'rsync -aH {og_shared}/* {ogclientmount}/opt/opengnsys/', shell=True) |
---|
231 | |
---|
232 | if not os.path.exists (f'{ogclientmount}/etc/pci.ids'): |
---|
233 | shutil.copy (f'{og_shared}/lib/pci.ids', f'{ogclientmount}/etc/') |
---|
234 | |
---|
235 | # Dependencias Qt para el Browser. |
---|
236 | subprocess.run (f'rsync -aH {og_shared}/etc/*.qmap {ogclientmount}/usr/local/etc', shell=True) |
---|
237 | subprocess.run (f'rsync -aH {og_shared}/lib/qtlib/* {ogclientmount}/usr/local/lib', shell=True) |
---|
238 | subprocess.run (f'rsync -aH {og_shared}/lib/fonts {ogclientmount}/usr/local/lib', shell=True) |
---|
239 | subprocess.run (f'rsync -aH {og_shared}/lib/qtplugins/* {ogclientmount}/usr/local/plugins', shell=True) |
---|
240 | |
---|
241 | # Browser |
---|
242 | if os.path.exists (f'{og_shared}/bin/browser'): shutil.copy (f'{og_shared}/bin/browser', f'{ogclientmount}/bin/') |
---|
243 | |
---|
244 | def sysctl (btrootfsmnt): |
---|
245 | logger.debug ('copiando sysctl.conf') |
---|
246 | with open (f'{btrootfsmnt}/etc/sysctl.conf', 'w') as fd: |
---|
247 | fd.write ('net.ipv6.conf.all.disable_ipv6 = 1\n') |
---|
248 | fd.write ('net.ipv6.conf.default.disable_ipv6 = 1\n') |
---|
249 | fd.write ('net.ipv6.conf.lo.disable_ipv6 = 1\n') |
---|
250 | |
---|
251 | def ssh_server (btrootfsmnt): |
---|
252 | if not os.path.exists ('/root/.ssh/id_rsa'): ## creates a key pair in the VM (or docker container), not in the chroot |
---|
253 | utils.run (['ssh-keygen', '-q', '-f', '/root/.ssh/id_rsa', '-N', '']) |
---|
254 | |
---|
255 | logger.debug ('comprobando directorio .ssh del root') |
---|
256 | if not os.path.exists (f'{btrootfsmnt}/root/.ssh'): ## creates directory within the chroot |
---|
257 | logger.debug ('creando directorio .ssh 600') |
---|
258 | os.mkdir (f'{btrootfsmnt}/root/.ssh') |
---|
259 | os.chmod (f'{btrootfsmnt}/root/.ssh', 0o700) |
---|
260 | |
---|
261 | logger.debug ('creando el fichero authorized_keys') ## creates file within the chroot |
---|
262 | if not os.path.exists (f'{btrootfsmnt}/root/.ssh/authorized_keys'): |
---|
263 | open (f'{btrootfsmnt}/root/.ssh/authorized_keys', 'w').close() |
---|
264 | os.chmod (f'{btrootfsmnt}/root/.ssh/authorized_keys', 0o600) |
---|
265 | |
---|
266 | logger.debug ('importando la clave publica del servidor OG') |
---|
267 | if os.path.exists ('/root/.ssh/id_rsa.pub'): ## takes the pubkey from the VM (or docker container) and puts it in the authorized_keys within the chroot |
---|
268 | fdin = open ('/root/.ssh/id_rsa.pub', 'r') |
---|
269 | fdout = open (f'{btrootfsmnt}/root/.ssh/authorized_keys', 'a') |
---|
270 | while True: |
---|
271 | l = fdin.readline() |
---|
272 | if not l: break |
---|
273 | fdout.write (l) |
---|
274 | fdin.close() |
---|
275 | fdout.close() |
---|
276 | |
---|
277 | else: |
---|
278 | logger.error ('no key publica og') |
---|
279 | |
---|
280 | def ssh_client (btrootfsmnt): |
---|
281 | if not os.path.exists (f'{btrootfsmnt}/root/.ssh/id_rsa'): |
---|
282 | utils.run (['ssh-keygen', '-q', '-f', f'{btrootfsmnt}/root/.ssh/id_rsa', '-N', '']) ## creates a key pair in the chroot |
---|
283 | |
---|
284 | #cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys ## takes the pubkey and authorises it to itself |
---|
285 | fdin = open (f'{btrootfsmnt}//root/.ssh/id_rsa.pub', 'r') |
---|
286 | fdout = open (f'{btrootfsmnt}/root/.ssh/authorized_keys', 'a') |
---|
287 | while True: |
---|
288 | l = fdin.readline() |
---|
289 | if not l: break |
---|
290 | fdout.write (l) |
---|
291 | fdin.close() |
---|
292 | fdout.close() |
---|
293 | |
---|
294 | ## TODO: exportamos la publica a los repos |
---|
295 | #cp /root/.ssh/id_rsa.pub /tmp/rsa.ogclient.pub |
---|
296 | |
---|
297 | def move_initrd (bttargetdir, osrelease): |
---|
298 | ## backup de oginitrd.img, oginitrd.img.sum, ogvmlinuz y ogvmlinuz.sum |
---|
299 | now = datetime.datetime.now(datetime.timezone.utc).strftime ('%Y%m%d-%H%M%S%z') |
---|
300 | if os.path.exists (f'{bttargetdir}/oginitrd.img'): |
---|
301 | os.rename (f'{bttargetdir}/oginitrd.img' , f'{bttargetdir}/oginitrd.img.{now}') |
---|
302 | os.rename (f'{bttargetdir}/oginitrd.img.sum', f'{bttargetdir}/oginitrd.img.sum.{now}') |
---|
303 | if os.path.exists (f'{bttargetdir}/ogvmlinuz'): |
---|
304 | os.rename (f'{bttargetdir}/ogvmlinuz' , f'{bttargetdir}/ogvmlinuz.{now}') |
---|
305 | os.rename (f'{bttargetdir}/ogvmlinuz.sum', f'{bttargetdir}/ogvmlinuz.sum.{now}') |
---|
306 | |
---|
307 | shutil.copy (f'/tmp/initrd.img-{osrelease}', f'{bttargetdir}/oginitrd.img') |
---|
308 | shutil.copy (f'/tmp/vmlinuz-{osrelease}', f'{bttargetdir}/ogvmlinuz') |
---|
309 | |
---|
310 | utils.write_md5 (f'{bttargetdir}/oginitrd.img') |
---|
311 | utils.write_md5 (f'{bttargetdir}/ogvmlinuz') |
---|
312 | |
---|
313 | #chmod -R 755 $BTTARGETDIR |
---|
314 | for f in glob.glob (f'{bttargetdir}/oginitrd*') + glob.glob (f'{bttargetdir}/vmlinuz*'): |
---|
315 | os.chmod (f, 0o755) |
---|
316 | |
---|
317 | def mksquashfs (bttargetdir, btrootfsmnt): |
---|
318 | logger.info ('Iniciando la creación del sistema de archivos en sqfs') |
---|
319 | |
---|
320 | if os.path.exists (f'{bttargetdir}/ogclient.sqfs'): |
---|
321 | now = datetime.datetime.now(datetime.timezone.utc).strftime ('%Y%m%d-%H%M%S%z') |
---|
322 | os.rename (f'{bttargetdir}/ogclient.sqfs', f'{bttargetdir}/ogclient.sqfs.{now}') |
---|
323 | |
---|
324 | ## uses all CPU cores available, even within docker |
---|
325 | utils.run (['mksquashfs', btrootfsmnt, f'{bttargetdir}/ogclient.sqfs', '-e', 'var/lib/apt/lists', '-e', 'usr/share/doc']) |
---|
326 | os.chmod (f'{bttargetdir}/ogclient.sqfs', 0o744) |
---|
327 | |
---|
328 | utils.write_md5 (f'{bttargetdir}/ogclient.sqfs') |
---|
329 | |
---|
330 | def mkisofs (pxepkg, isolinux_tpl, bttargetdir, nameisoclient): |
---|
331 | #Preparamos los gestores de arranque |
---|
332 | try: os.makedirs ('/tmp/iso/isolinux', exist_ok=True) |
---|
333 | except: raise |
---|
334 | |
---|
335 | subprocess.run (['cp -a /usr/lib/syslinux/* /tmp/iso/isolinux/'], shell=True) |
---|
336 | |
---|
337 | if 'gpxe' == pxepkg: |
---|
338 | subprocess.run (['cp -a /usr/share/gpxe/* /tmp/iso/isolinux'], shell=True) |
---|
339 | elif 'ipxe' == pxepkg: |
---|
340 | subprocess.run (['cp -a /usr/lib/ipxe/* /tmp/iso/isolinux'], shell=True) |
---|
341 | else: |
---|
342 | raise Exception (f'unknown pxepkg value "{pxepkg}"') |
---|
343 | |
---|
344 | # Si existe el fichero ISO, montarlo para extraer isolinux.bin. |
---|
345 | if os.path.exists (f'/tmp/iso/isolinux/{pxepkg}.iso'): |
---|
346 | os.mkdir ('/tmp/iso/isolinux/mount') |
---|
347 | utils.run (['mount', '-o', 'loop', f'/tmp/iso/isolinux/{pxepkg}.iso', '/tmp/iso/isolinux/mount']) |
---|
348 | subprocess.run (['cp -a /tmp/iso/isolinux/mount/* /tmp/iso/isolinux'], shell=True) |
---|
349 | utils.umount ('/tmp/iso/isolinux/mount') |
---|
350 | os.rmdir ('/tmp/iso/isolinux/mount') |
---|
351 | os.unlink (f'/tmp/iso/isolinux/{pxepkg}.iso') |
---|
352 | |
---|
353 | with open ('/tmp/iso/isolinux/isolinux.cfg', 'w') as fd: |
---|
354 | fd.write (isolinux_tpl.strip().replace('__NAMEISOCLIENT__', nameisoclient).replace('__PXEPKG__', pxepkg)) |
---|
355 | |
---|
356 | # preparamos el directorio boot-tools. |
---|
357 | if not os.path.exists ('/tmp/iso/ogclient'): |
---|
358 | os.mkdir ('/tmp/iso/ogclient') |
---|
359 | shutil.copy (f'{bttargetdir}/ogclient.sqfs', '/tmp/iso/ogclient/') |
---|
360 | shutil.copy (f'{bttargetdir}/ogclient.sqfs.sum', '/tmp/iso/ogclient/') |
---|
361 | shutil.copy (f'{bttargetdir}/ogvmlinuz', '/tmp/iso/ogclient/') |
---|
362 | shutil.copy (f'{bttargetdir}/ogvmlinuz.sum', '/tmp/iso/ogclient/') |
---|
363 | shutil.copy (f'{bttargetdir}/ogvmlinuz', '/tmp/iso/ogclient/linuxISO') |
---|
364 | shutil.copy (f'{bttargetdir}/ogvmlinuz.sum', '/tmp/iso/ogclient/linuxISO.sum') |
---|
365 | shutil.copy (f'{bttargetdir}/oginitrd.img', '/tmp/iso/ogclient/') |
---|
366 | shutil.copy (f'{bttargetdir}/oginitrd.img.sum', '/tmp/iso/ogclient/') |
---|
367 | #el ogclienteToISO debe tener una copia del ogvmlinuz como linuxISO |
---|
368 | #cp -prv /var/lib/tftpboot/ogclientToIso/* /tmp/iso/ogclient |
---|
369 | |
---|
370 | oldpwd = os.getcwd() |
---|
371 | os.chdir ('/tmp') |
---|
372 | logger.debug (f'mkisofs -quiet -V ogClient -o {nameisoclient}.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -J -no-emul-boot -boot-load-size 4 -boot-info-table /tmp/iso') |
---|
373 | utils.run (['mkisofs', '-quiet', '-V', 'ogClient', '-o', f'{nameisoclient}.iso', '-b', 'isolinux/isolinux.bin', '-c', 'isolinux/boot.cat', '-J', '-no-emul-boot', '-boot-load-size', '4', '-boot-info-table', '/tmp/iso']) |
---|
374 | |
---|
375 | utils.write_md5 (f'{nameisoclient}.iso') |
---|
376 | os.chdir (oldpwd) |
---|
377 | |
---|
378 | shutil.move (f'/tmp/{nameisoclient}.iso' , f'/var/lib/tftpboot/ogclient/{nameisoclient}.iso') |
---|
379 | shutil.move (f'/tmp/{nameisoclient}.iso.sum', f'/var/lib/tftpboot/ogclient/{nameisoclient}.iso.sum') |
---|
380 | |
---|
381 | #def __unused_boottoolsBootGraphics(): |
---|
382 | # find /tmp/opengnsys_installer/ -name .svn -type d -exec rm -fr {} \; 2>/dev/null; |
---|
383 | # apt-get -y install plymouth plymouth-theme-script |
---|
384 | # update-alternatives --install /lib/plymouth/themes/default.plymouth default.plymouth /lib/plymouth/themes/opengnsys/opengnsys.plymouth 100 |
---|
385 | # update-alternatives --set default.plymouth /lib/plymouth/themes/opengnsys/opengnsys.plymouth |
---|
386 | # mkdir -p /etc/initramfs-tools/conf.d |
---|
387 | # echo "FRAMEBUFFER=y" > /etc/initramfs-tools/conf.d/splash |
---|
388 | |
---|
389 | |
---|
390 | ############### No usados en el instalador, solo en actualizaciones. |
---|
391 | |
---|
392 | # ogClientMount [str_program] |
---|
393 | #@brief Acceso al 2nd FS del cliente desde el Servidor Opengnsys |
---|
394 | #@param 1 Opciona: scripts o programa a ejecutar para automatizaciones |
---|
395 | #@return Si no hay parametros: login de acceso. |
---|
396 | #@return con un parametro: La salida del programa ejecutado |
---|
397 | #def ogClientMount(): |
---|
398 | # TODO comprobar que OGFILE y OGFILEMOUNT existe. |
---|
399 | # mount | grep $OGCLIENTFILE > /dev/null || mount $OGCLIENTFILE $OGCLIENTMOUNT -o loop,offset=32256 |
---|
400 | # mount | grep $OGCLIENTMOUNT/proc > /dev/null || mount --bind /proc $OGCLIENTMOUNT/proc |
---|
401 | # mount | grep $OGCLIENTMOUNT/sys > /dev/null || mount --bind /sys $OGCLIENTMOUNT/sys |
---|
402 | # mount | grep $OGCLIENTMOUNT/tmp > /dev/null || mount --bind /tmp $OGCLIENTMOUNT/tmp |
---|
403 | # mount | grep $OGCLIENTMOUNT/dev > /dev/null || mount --bind /dev $OGCLIENTMOUNT/dev |
---|
404 | # mount | grep $OGCLIENTMOUNT/dev/pts > /dev/null || mount --bind /dev/pts $OGCLIENTMOUNT/dev/pts |
---|
405 | # [ $# = 0 ] && $(chroot $OGCLIENTMOUNT /sbin/getty 38400 `tty`) |
---|
406 | # [ $# = 1 ] && chroot $OGCLIENTMOUNT $1 |
---|
407 | |
---|
408 | #@brief Desmonta el 2nd FS del cliente desde el Servidor Opengnsys |
---|
409 | #def ogClientUnmount(): |
---|
410 | # cd /tmp |
---|
411 | # echo "desmontando cliente espere" |
---|
412 | # sleep 5 |
---|
413 | # mount | grep $OGCLIENTMOUNT/dev > /dev/null && umount $OGCLIENTMOUNT/dev || ogClientUnmount |
---|
414 | # mount | grep $OGCLIENTMOUNT/dev/pts > /dev/null && umount $OGCLIENTMOUNT/dev/pts || ogClientUnmount |
---|
415 | # mount | grep $OGCLIENTMOUNT/proc > /dev/null && umount $OGCLIENTMOUNT/proc || ogClientUnmount |
---|
416 | # mount | grep $OGCLIENTMOUNT/sys > /dev/null && umount $OGCLIENTMOUNT/sys || ogClientUnmount |
---|
417 | # mount | grep $OGCLIENTMOUNT/tmp > /dev/null && umount $OGCLIENTMOUNT/tmp || ogClientUnmount |
---|
418 | # mount | grep $OGCLIENTMOUNT > /dev/null && umount $OGCLIENTMOUNT || ogClientUnmount |
---|