1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
|
ogClientVar()
{
export SVNCLIENTDIR=/tmp/opengnsys_installer/opengnsys/client/boot-tools
export SVNCLIENTSTRUCTURE=/tmp/opengnsys_installer/opengnsys/client/shared
export SVNCLIENTENGINE=/tmp/opengnsys_installer/opengnsys/client/engine
export OGCLIENTBASEDIR=/var/lib/tftpboot/ogclient/
export OGCLIENTFILE=${OGCLIENTBASEDIR}ogclient.img
export OGCLIENTMOUNT=${OGCLIENTBASEDIR}ogclientmount
# tamaño maximo limitado por schroot 2GB
export OGCLIENTSIZEMB=1900
#export OGCLIENTSIZEMB=1000
# export OGCLIENTSIZEKB=500
export OGCLIENTLABEL=ogClient
#export OGLIB=/opt/opengnsys/client/lib
}
function ogClientOsInfo ()
{
#TODO según host, un OSHHTP u otro OSARCH
#1 OSCODENAME jaunty|karmic|lucid
#devuelve OSDISTRIB(ubuntu,debian),OSCODENAME(lucid,karmic,squeeze):OGRELEASE:httpAPT
case $1 in
host | HOST)
export OSDISTRIB=$(lsb_release -i | awk -F: '{sub(/\t/,""); print $2}') 2>/dev/null
#OSCODENAME=$(lsb_release -c | awk -F: '{sub(/\t/,""); print $2}') 2>/dev/null
export OSCODENAME=$(cat /etc/lsb-release | grep CODENAME | awk -F= '{print $NF}')
export OSRELEASE=$(uname -a | awk '{print $3}')
uname -a | grep x86_64 > /dev/null && export OSARCH=amd64 || export OSARCH=i386
export OSHTTP="http://es.archive.ubuntu.com/ubuntu/"
;;
jaunty|JAUNTY)
export OSDISTRIB=ubuntu
export OSCODENAME=jaunty
export OSRELEASE="2.6.28-11-generic"
export OSARCH=i386
export OSHTTP="http://es.archive.ubuntu.com/ubuntu/"
;;
lenny|LENNY)
export OSDISTRIB=debian
export OSCODENAME=lenny
export OSRELEASE="2.6.28-11-generic"
export OSARCH=i386
export OSHTTP="http://es.archive.ubuntu.com/ubuntu/ "
;;
squeeze|SQUEEZE)
export OSDISTRIB=debian
export OSCODENAME=squeeze
export OSRELEASE="2.6.28-11-generic"
export OSARCH=i386
export OSHTTP="http://es.archive.ubuntu.com/ubuntu/ "
;;
karmic|KARMIC)
export OSDISTRIB=ubuntu
export OSCODENAME=karmic
export OSRELEASE="2.6.31-14-generic"
export OSARCH=i386
export OSHTTP="http://es.archive.ubuntu.com/ubuntu/ "
;;
lucid|LUCID)
export OSDISTRIB=ubuntu
export OSCODENAME=lucid
export OSRELEASE="2.6.32-21-generic-pae"
export OSARCH=i386
export OSHTTP="http://es.archive.ubuntu.com/ubuntu/ "
;;
*)
return 1
;;
esac
echo $OSDISTRIB:$OSCODENAME:$OSRELEASE:$OSARCH:$OSHTTP
}
#creación y formateo del disco virtual.
ogClient2ndFile ()
{
local RERROR DISKLOOP PARTLOOP #return code error
echoAndLog "$FUNCNAME(): Creación y formateo del disco virtual $OGCLIENTSIZEMB MB "
#Desmontamos por si acaso el dispositivo virtual
mount | grep $OGCLIENTMOUNT && umount $OGCLIENTMOUNT
mount | grep $OGCLIENTMOUNT && umount $OGCLIENTMOUNT
echo "$FUNCNAME(): Creando el directorio donde se montará el disco virtual $OGCLIENTMOUNT"
mkdir -p $OGCLIENTMOUNT
if [ $? -ne 0 ]
then
errorAndLog "$FUNCNAME(): Creando directorio $OGCLIENTMOUNT : ERROR"
return 1
fi
echo "$FUNCNAME(): Creando el disco virtual que almacenará el FS del cliente $OGCLIENTSIZEMB MB de datos físicos"
dd if=/dev/zero of=$OGCLIENTFILE bs=1048576 count=$OGCLIENTSIZEMB
#qemu-img create $OGCLIENTFILE 3G
#dd if=/dev/zero of=$OGCLIENTFILE bs=1k count=$OGCLIENTSIZEKB # necesita 500MB
if [ $? -ne 0 ]
then
errorAndLog "$FUNCNAME(): Creando el disco virtual: ERROR"
return 1
fi
DISKLOOP=$(losetup -f)
losetup $DISKLOOP $OGCLIENTFILE
echo "$FUNCNAME(): particiondo el disco virtual - $DISKLOOP - con una particion primaria"
echo -e "n\np\n1\n\n\nt\n83\nw" | fdisk $DISKLOOP
#echo $?
# da error, porque no puede actualizar el kernel.
#if [ $? -ne 0 ]
#then
# errorAndLog "$FUNCNAME(): Particionando el disco virutal: ERROR"
# return 1
#fi
echoAndLog "$FUNCNAME(): Desmontando $DISKLOOP despues del particionado "
losetup -d $DISKLOOP
if [ $? -ne 0 ]
then
errorAndLog "$FUNCNAME(): Liberando disco virtual despues del particionado: ERROR"
return 1
fi
#mkfs.ext3 -L $OGCLIENTLABEL /dev/loop1
#mkfs.ext3 -L $OGCLIENTLABEL /dev/loop1
PARTLOOP=$(losetup -f)
echo "$FUNCNAME(): Formateando la particion principal $PARTLOOP"
losetup -o 32256 $PARTLOOP $OGCLIENTFILE && mkfs.ext3 -b 4096 -L $OGCLIENTLABEL $PARTLOOP
if [ $? -ne 0 ]
then
errorAndLog "$FUNCNAME(): Formateando la particion principal del disco virtual: ERROR"
return 1
fi
echoAndLog "$FUNCNAME(): Desmontando $PARTLOOP despues del formateo "
losetup -d $PARTLOOP
if [ $? -ne 0 ]
then
errorAndLog "$FUNCNAME(): Liberando la particion virtual despues del formateo: ERROR"
return 1
else
echoAndLog "$FUNCNAME(): $OGCLIENTFILE $OGCLIENTSIZEMB MB : OK"
fi
}
ogClient2ndFs ()
{
ogClientOsInfo $1
echoAndLog "$FUNCNAME: Iniciando la generación del sistema de archivos "
#Montamos el dispositivo virtual en su punto de montaje.
mount | grep $OGCLIENTMOUNT || mount $OGCLIENTFILE $OGCLIENTMOUNT -o loop,offset=32256
mount | grep $OGCLIENTMOUNT && echoAndLog "$FUNCNAME: mount $OGCLIENTFILE $OGCLIENTMOUNT -o loop,offset=32256 OK " || errorAndLog "$FUNCNAME: mount $OGCLIENTFILE $OGCLIENTMOUNT -o loop,offset=32256 : FAILURE "
#debootstrap --include=linux-image-${OSRELEASE},linux-headers-${OSRELEASE} --arch=$OSARCH --components=main,universe ${OSCODENAME} ${OGCLIENTMOUNT} ${OSHTTP}
debootstrap --arch=$OSARCH --components=main,universe ${OSCODENAME} ${OGCLIENTMOUNT} ${OSHTTP}
if [ $? -ne 0 ]; then
errorAndLog "$FUNCNAME: debootstrap --include=linux-image-${OSRELEASE},linux-headers-${OSRELEASE} --arch=$OSARCH --components=main,universe $OSCODENAME $OGCLIENTMOUNT $OSHTTP
: ha fallado!"
mount | grep $OGCLIENTMOUNT && umount $OGCLIENTMOUNT
return 1
else
echoAndLog "$FUNCNAME: debootstrap --include=linux-image-${OSRELEASE},linux-headers-${OSRELEASE} --arch=$OSARCH --components=main,universe $OSCODENAME $OGCLIENTMOUNT $OSHTTP
: ok"
mount | grep $OGCLIENTMOUNT && umount $OGCLIENTMOUNT
return 0
fi
sleep 5
##preubas revisar OSRELEASE
#debootstrap --include=linux-image-${OSRELEASE} --arch=i386 --variant=minbase $OSVERSION $OGCLIENTMOUNT http://es.archive.ubuntu.com/ubuntu/
#debootstrap --variant=minbase --include=linux-image-${OGRELEASE} --arch=i386 $OGVERSION $OGCLIENTMOUNT http://es.archive.ubuntu.com/ubuntu/
#echo debootstrap --include=linux-image-${OGRELEASE},dbus --arch=i386 --components=main,universe $OGVERSION $OGCLIENTMOUNT http://es.archive.ubuntu.com/ubuntu/
}
########## configura el segundo sistema de archivos
########### parametro: "host"
function ogClient2ndSVN()
{
ogClientOsInfo $1
#1 la salida de ogClientOsInfo
local LERROR
LERROR=TRUE
echoAndLog "$FUNCNAME: Iniciando la personalización con datos del SVN "
# comprobar que está montado $OGCLIENTMOUNT
mount | grep $OGCLIENTMOUNT || mount $OGCLIENTFILE $OGCLIENTMOUNT -o loop,offset=32256
# parseamos del apt.source
sed -e "s/OSCODENAME/$OSCODENAME/g" ${SVNCLIENTDIR}/clientstructure/etc/apt/sources.list.ubuntu > ${SVNCLIENTDIR}/clientstructure/etc/apt/sources.list
if [ $? -ne 0 ]
then
errorAndLog "$FUNCNAME(): Parsing apt.sources : ERROR"
return 1
fi
#parseamos el script de generación del initrd.
sed -e "s/OSRELEASE/$OSRELEASE/g" ${SVNCLIENTDIR}/clientstructure/root/GenerateInitrd.generic.sh > ${SVNCLIENTDIR}/clientstructure/root/GenerateInitrd.sh
if [ $? -ne 0 ]
then
errorAndLog "$FUNCNAME(): Parsing GenerateInitrd.sh : ERROR"
return 1
fi
#damos permiso al directorio de scripts
chmod 775 ${SVNCLIENTDIR}/clientstructure/root/*
# los copiamos
cp -prv ${SVNCLIENTDIR}/clientstructure/* $OGCLIENTMOUNT
mkdir -p ${OGCLIENTMOUNT}/opt/opengnsys/
cp -prv ${SVNCLIENTSTRUCTURE}/* ${OGCLIENTMOUNT}/opt/opengnsys/
cp -prv ${SVNCLIENTENGINE}/* ${OGCLIENTMOUNT}/opt/opengnsys/lib/engine/bin/
if [ $? -ne 0 ]
then
errorAndLog "$FUNCNAME(): Copying client data : ERROR"
return 1
fi
# copiamos algunas cosas del nfsexport
#### Tipos de letra para el Browser.
cp -pr ${SVNCLIENTSTRUCTURE}/lib/fonts $OGCLIENTMOUNT/usr/local/lib/fonts
#### Crear enlaces para compatibilidad con las distintas versiones del Browser.
mkdir -p $OGCLIENTMOUNT/usr/local/Trolltech/QtEmbedded-4.5.1/lib/
mkdir -p $OGCLIENTMOUNT/usr/local/QtEmbedded-4.6.2/lib/
mkdir -p $OGCLIENTMOUNT/usr/local/QtEmbedded-4.6.3/lib/
#ln -fs $OGCLIENTMOUNT/usr/local/lib/fonts /usr/local/Trolltech/QtEmbedded-4.5.1/lib/fonts
#ln -fs $OGCLIENTMOUNT/usr/local/lib/fonts /usr/local/QtEmbedded-4.6.2/lib/fonts
#ln -fs $OGCLIENTMOUNT/usr/local/lib/fonts /usr/local/QtEmbedded-4.6.3/lib/fonts
cp -pr ${SVNCLIENTSTRUCTURE}/lib/fonts $OGCLIENTMOUNT/usr/local/Trolltech/QtEmbedded-4.5.1/lib/fonts
cp -pr ${SVNCLIENTSTRUCTURE}/lib/fonts $OGCLIENTMOUNT/usr/local/QtEmbedded-4.6.2/lib/fonts
cp -pr ${SVNCLIENTSTRUCTURE}/lib/fonts $OGCLIENTMOUNT/usr/local/QtEmbedded-4.6.3/lib/fonts
if [ $? -ne 0 ]
then
errorAndLog "$FUNCNAME(): Linking Browser fonts : ERROR"
return 1
fi
# B ########################################################
cp -pr ${SVNCLIENTSTRUCTURE}/lib/pci.ids $OGCLIENTMOUNT/etc
if [ $? -ne 0 ]
then
errorAndLog "$FUNCNAME(): Copying pci.ids : ERROR"
return 1
fi
cp ${SVNCLIENTSTRUCTURE}/bin/browser $OGCLIENTMOUNT/bin
if [ $? -ne 0 ]
then
errorAndLog "$FUNCNAME(): Copying Browser : ERROR"
return 1
fi
cp ${SVNCLIENTSTRUCTURE}/bin/ogAdmClient $OGCLIENTMOUNT/bin
if [ $? -ne 0 ]
then
errorAndLog "$FUNCNAME(): Copying ogAdmClient : ERROR"
return 1
else
mount | grep $OGCLIENTMOUNT && umount $OGCLIENTMOUNT
mount | grep $OGCLIENTMOUNT && umount $OGCLIENTMOUNT
mount | grep $OGCLIENTMOUNT && umount $OGCLIENTMOUNT
mount | grep $OGCLIENTMOUNT && umount $OGCLIENTMOUNT
echoAndLog "$FUNCNAME: Finalizado: OK "
return 0
fi
}
ogClientSchrootConf()
{
echoAndLog "$FUNCNAME: Iniciando la configuración del schroot "
cp /etc/schroot/schroot.conf /etc/schroot/schroot.conf.`getDateTime`
cat << EOF > /etc/schroot/schroot.conf
[IMGogclient]
type=loopback
file=/var/lib/tftpboot/ogclient/ogclient.img
description=ogclient ubuntu luc IMGi
priority=1
users=root
groups=root
root-groups=root
mount-options=-o offset=32256
root-users=root
[DIRogclient]
type=directory
directory=/var/lib/tftpboot/ogclient/ogclientmount
description=ogclient ubuntu lucid DIR
priority=2
users=root
groups=root
root-groups=root
root-users=root
EOF
cp /etc/schroot/mount-defaults /etc/schroot/mount-defaults.`getDateTime`
cat << EOF > /etc/schroot/mount-defaults
# mount.defaults: static file system information for chroots.
# Note that the mount point will be prefixed by the chroot path
# (CHROOT_PATH)
#
# <file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
#procbususb /proc/bus/usb usbfs defaults 0 0
#/dev /dev none rw,bind 0 0
/dev/pts /dev/pts none rw,bind 0 0
/dev/shm /dev/shm none rw,bind 0 0
#/home /home none rw,bind 0 0
/tmp /tmp none rw,bind 0 0
EOF
echoAndLog "$FUNCNAME: Finalizado: OK "
return 0
}
########### param1 "host"
ogClientInitrd()
{
ogClientVar
cd /
ogClientOsInfo $1
schroot -c IMGogclient -- /root/GenerateInitrd.generic.sh
echo "cp /tmp/*-${OSRELEASE} $OGCLIENTBASEDIR"
cp /tmp/*-${OSRELEASE} $OGCLIENTBASEDIR
cp /tmp/initrd.img-${OSRELEASE} ${OGCLIENTBASEDIR}/oginitrd.img
cp /tmp/vmlinuz-${OSRELEASE} ${OGCLIENTBASEDIR}/ogvmlinuz
cd -
}
ogClient2ndSqfs()
{
ogClientVar
echoAndLog "$FUNCNAME: Iniciando la creación del sistema de archivos en sqfs "
# si ya existe un sqfs lo renombramos
[ -f $OGCLIENTBASEDIR/ogclient.sqfs ] && mv $OGCLIENTBASEDIR/ogclient.sqfs $OGCLIENTBASEDIR/ogclient.sqfs.`date +%Y%m%d-%H%M%S`
mount | grep $OGCLIENTMOUNT || mount $OGCLIENTFILE $OGCLIENTMOUNT -o loop,offset=32256
mksquashfs $OGCLIENTMOUNT $OGCLIENTBASEDIR/ogclient.sqfs
chmod 744 $OGCLIENTBASEDIR/ogclient.sqfs
mount | grep $OGCLIENTMOUNT && umount $OGCLIENTMOUNT
}
ogClientSshkeys()
{
echo comprobamos clave rsa en el host REPO OG.
if [ ! -f /root/.ssh/id_rsa.pub ]
then
echo "creando claves rsa"
ssh-keygen -q -f /root/.ssh/id_dsa -t dsa -N "opengnsys"
else
echo "la claves ya estan creadas"
fi
echo "copiamos la clave publica a /tmp"
cp /root/.ssh/id_dsa.pub /tmp
cat /tmp/id_dsa.pub
echo "schroot con instrucciones."
schroot -c IMGogclient -- /root/importSshKeys.sh
echo "limpiando"
rm /tmp/id_dsa.pub
## copiamos ssh rsa del host al guest como authorized-key2
##rm ${OGCLIENTMOUNT}/root/.ssh/authorized-key2
##cat /root/.ssh/id_rsa.pub >> ${OGCLIENTMOUNT}/root/.ssh/authorized-key2
#cat ${OGCLIENTMOUNT}/root/.ssh/id_rsa.pub >> ${OGCLIENTMOUNT}/root/.ssh/authorized-key2
##mount | grep $OGCLIENTMOUNT || umount $OGCLIENTMOUNT
}
ogClientConfpxe()
{
################## DEJAMOS FICHERO DE EJEMPLOS PARA:
#default
cat << FIN >> /var/lib/tftpboot/pxelinux.cfg/defaultNEWClient
LABEL pxe-${OGRELEASE}
KERNEL ogclient/vmlinuz-$OGRELEASE
APPEND initrd=ogclient/initrd.img-$OGRELEASE ip=dhcp ro boot=og vga=788 irqpoll acpi=on reposerver=
LABEL pxe-2.6.32-21-generic-pae
KERNEL ogclient/vmlinuz-2.6.32-21-generic-pae
APPEND initrd=ogclient/initrd.img-2.6.32-21-generic-pae ip=dhcp ro boot=oginit vga=788 irqpoll acpi=on ogrepo=172.17.36.11 ogprotocol=nfs og2nd=sqfs
LABEL cache
KERNEL grub.exe
APPEND --config-file="find --set-root /vmlinuz; kernel /vmlinuz ip=dhcp ro boot=og vga=788 irqpoll acpi=on engine=testing reposerver=172.17.32.242; initrd /initrd.img"
LABEL net
KERNEL grub.exe
APPEND keeppxe --config-file="pxe detect; kernel (pd)/ogclient/vmlinuz-2.6.32-21-generic-pae ip=dhcp ro boot=og vga=788 irqpoll acpi=on engine=testing reposerver=172.17.32.242; initrd (pd)/ogclient/initrd.img-2.6.32-21-generic-pae"
LABEL IfNOTcacheGOnet
KERNEL grub.exe
APPEND keeppxe --config-file="pxe detect; default 0; timeout 0; hiddenmenu; title cache; fallback 1; find --set-root /vmlinuz; kernel /vmlinuz ip=dhcp ro boot=og vga=788 irqpoll acpi=on engine=testing reposerver=172.17.32.242; initrd /initrd.img; boot; title net; kernel (pd)/ogclient/vmlinuz-2.6.32-21-generic-pae ip=dhcp ro boot=og vga=788 irqpoll acpi=on engine=testing reposerver=172.17.32.242; initrd (pd)/ogclient/initrd.img-2.6.32-21-generic-pae; boot"
#LABEL pxe-2.6.32-21-generic-pae
#KERNEL ogclient/vmlinuz-2.6.32-21-generic-pae
#APPEND initrd=ogclient/initrd.img-2.6.32-21-generic-pae ip=dhcp ro boot=og vga=788 irqpoll acpi=on reposerver=172.17.32.242
#LABEL grub
#KERNEL grub.exe
#APPEND keeppxe
FIN
#/etc/hosts
echo "/var/lib/tftpboot *(ro,no_subtree_check,no_root_squash,sync)" > /etc/exportsNEWClient
/etc/init.d/nfs-kernel-server restart
#####################################################################
}
############### No usados en el instalador, solo en actualizaciones.
#/**
# ogClientMount [str_program]
#@brief Acceso al 2nd FS del cliente desde el Servidor Opengnsys
#@param 1 Opciona: scripts o programa a ejecutar para automatizaciones
#@return Si no hay parametros: login de acceso.
#@return con un parametro: La salida del programa ejecutado
#@exception
#@note
#@todo
#@version 0.9 - Primera versión para OpenGnSys
#@author Antonio J. Doblas Viso, Universidad de Málaga
#@date 2010/02/15
#*/ ##
function ogClientMount ()
{
#TODO comprobar que OGFILE y OGFILEMOUNT existe.
mount | grep $OGCLIENTFILE > /dev/null || mount $OGCLIENTFILE $OGCLIENTMOUNT -o loop,offset=32256
mount | grep $OGCLIENTMOUNT/proc > /dev/null || mount --bind /proc $OGCLIENTMOUNT/proc
mount | grep $OGCLIENTMOUNT/sys > /dev/null || mount --bind /sys $OGCLIENTMOUNT/sys
mount | grep $OGCLIENTMOUNT/tmp > /dev/null || mount --bind /tmp $OGCLIENTMOUNT/tmp
mount | grep $OGCLIENTMOUNT/dev > /dev/null || mount --bind /dev $OGCLIENTMOUNT/dev
mount | grep $OGCLIENTMOUNT/dev/pts > /dev/null || mount --bind /dev/pts $OGCLIENTMOUNT/dev/pts
[ $# = 0 ] && $(chroot $OGCLIENTMOUNT /sbin/getty 38400 `tty`)
[ $# = 1 ] && chroot $OGCLIENTMOUNT $1
}
#/**
# ogClientUnmount
#@brief Desmonta el 2nd FS del cliente desde el Servidor Opengnsys
#@param
#@return
#@exception
#@note
#@todo
#@version 0.9 - Primera versión para OpenGnSys
#@author Antonio J. Doblas Viso, Universidad de Málaga
#@date 2010/02/15
#*/ ##
function ogClientUnmount ()
{
cd /tmp
echo "desmontando cliente espere"
sleep 5
mount | grep $OGCLIENTMOUNT/dev > /dev/null && umount $OGCLIENTMOUNT/dev || ogClientUnmount
mount | grep $OGCLIENTMOUNT/dev/pts > /dev/null && umount $OGCLIENTMOUNT/dev/pts || ogClientUnmount
mount | grep $OGCLIENTMOUNT/proc > /dev/null && umount $OGCLIENTMOUNT/proc || ogClientUnmount
mount | grep $OGCLIENTMOUNT/sys > /dev/null && umount $OGCLIENTMOUNT/sys || ogClientUnmount
mount | grep $OGCLIENTMOUNT/tmp > /dev/null && umount $OGCLIENTMOUNT/tmp || ogClientUnmount
mount | grep $OGCLIENTMOUNT > /dev/null && umount $OGCLIENTMOUNT || ogClientUnmount
#-d -f -l
}
############################ hasta el final del archivo antiguos
############################# ANTIGUOS
function ogClientGetRelease ()
{
#1 OSCODENAME jaunty|karmic|lucid
case $1 in
jaunty|JAUNTY)
OSCODENAME=jaunty
OGRELEASE="2.6.28-11-generic"
echo $OGRELEASE
;;
lenny|LENNY)
OSCODENAME=lenny
OGRELEASE="2.6.28-11-generic"
echo $OGRELEASE
;;
squeeze|SQUEEZE)
OSCODENAME=squeeze
OGRELEASE="2.6.28-11-generic"
echo $OGRELEASE
;;
karmic|KARMIC)
OSCODENAME=karmic
OGRELEASE="2.6.31-14-generic"
echo $OGRELEASE
;;
lucid|LUCID)
OSCODENAME=lucid
OGRELEASE="2.6.32-21-generic-pae"
echo $OGRELEASE
;;
*)
return 1
;;
esac
}
#/**
# ogClientGenerator str_versionUbuntu str_release
#@brief Crea el 2nd FS del cliente desde el Servidor Opengnsys
#@param 1 Versión de ubuntu a generar, jaunty karmic
#@return
#@exception
#@note
#@todo
#@version 0.9 - Primera versión para OpenGnSys
#@author Antonio J. Doblas Viso, Universidad de Málaga
#@date 2010/02/15
#*/ ##
function ogClientGeneratorDebootstrap ()
{
if [ $# != 2 ]
then
echo Debes introducir como argumento1: jaunty karmic lucid
echo Debes introducir como argumento2: la release
echo utiliza como entrada ogClientCheckVersion
return
fi
OSCODENAME=$1
OGRELEASE=$2
# instalamos el ultimo debotstrap para permitir instalar versiones superiores a nuestro sistema
#apt-get install gdebi-core
#wget $LASTDEBOOTSTRAP
#gdebi -n debootstrap_1.0.20_all.deb
#Desmontamos por si acaso el dispositivo virtual
mount | grep $OGCLIENTMOUNT && umount $OGCLIENTMOUNT
#Creamos el directorio donde montaremos el disco virtual
mkdir -p $OGCLIENTMOUNT
#Creamos el disco virtual con el filesystem del cliente.
dd if=/dev/zero of=$OGCLIENTFILE bs=1048576 count=$OGCLIENTSIZEMB
#qemu-img create $OGCLIENTFILE 3G
#dd if=/dev/zero of=$OGCLIENTFILE bs=1k count=$OGCLIENTSIZEKB # necesita 500MB
#particionamos el disco virtual
losetup /dev/loop0 $OGCLIENTFILE
echo -e "n\np\n1\n\n\nt\n83\nw" | fdisk /dev/loop0
losetup -d /dev/loop0
#formateamos la particion principal.
losetup -o 32256 /dev/loop1 $OGCLIENTFILE
mkfs.ext3 -b 4096 -L $OGCLIENTLABEL /dev/loop1
#mkfs.ext3 -L $OGCLIENTLABEL /dev/loop1
#mkfs.ext3 -L $OGCLIENTLABEL /dev/loop1
losetup -d /dev/loop1
#Montamos el dispositivo virtual en su punto de montaje.
mount | grep $OGCLIENTMOUNT || mount $OGCLIENTFILE $OGCLIENTMOUNT -o loop,offset=32256
#TODO Comprobar arquitectura
#Iniciamos la creación del sistema en el directorio de clientes.
#echo debootstrap --include=linux-image-${OGRELEASE},dbus --arch=i386 --components=main,universe $OGVERSION $OGCLIENTMOUNT http://es.archive.ubuntu.com/ubuntu/
debootstrap --include=linux-image-${OGRELEASE},linux-headers-${OGRELEASE} --arch=i386 --components=main,universe $OSCODENAME $OGCLIENTMOUNT http://es.archive.ubuntu.com/ubuntu/
##preubas
#debootstrap --include=linux-image-${OGRELEASE} --arch=i386 --variant=minbase $OGVERSION $OGCLIENTMOUNT http://es.archive.ubuntu.com/ubuntu/
#debootstrap --variant=minbase --include=linux-image-${OGRELEASE} --arch=i386 $OGVERSION $OGCLIENTMOUNT http://es.archive.ubuntu.com/ubuntu/
if [ $? -ne 0 ]; then
errorAndLog "ogClientGeneratorDebootstrap(): ha fallado!"
return 1
else
echoAndLog "ogClientGeneratorDebootstrap(): ok"
return 0
fi
sleep 5
mount | grep $OGCLIENTMOUNT && umount $OGCLIENTFILE
cat << EOF > /etc/schroot/schroot.conf
[DIRogclient]
type=directory
directory=/var/lib/tftpboot/ogclient/ogclientmount
description=ogclient ubuntu lucid DIR
priority=2
users=root
groups=root
root-groups=root
root-users=root
EOF
}
|