1 | #!/bin/bash |
---|
2 | #/** |
---|
3 | #@file boottoolsfunctions.lib |
---|
4 | #@brief Librería o clase Boot-Tools |
---|
5 | #@class Boot-Tools |
---|
6 | #@brief Funciones para generar un sistema operativo cliente para opengnsys |
---|
7 | #@version 0.9 |
---|
8 | #@warning License: GNU GPLv3+ |
---|
9 | #*/ |
---|
10 | |
---|
11 | |
---|
12 | |
---|
13 | |
---|
14 | # btGetVariables: define las constantes a utilizar |
---|
15 | # Autor: Antonio J. Doblas Viso. Universidad de Málaga. |
---|
16 | btogGetVar() |
---|
17 | { |
---|
18 | export BTSVNBOOTTOOLS=/tmp/opengnsys_installer/opengnsys/client/boot-tools |
---|
19 | export BTSVNSHARE=/tmp/opengnsys_installer/opengnsys/client/shared |
---|
20 | export BTSVNENGINE=/tmp/opengnsys_installer/opengnsys/client/engine |
---|
21 | |
---|
22 | export BTSVNOG2=/tmp/opengnsys_installer/opengnsys2 |
---|
23 | |
---|
24 | export BTTARGETDIR=/var/lib/tftpboot/ogclient/ |
---|
25 | export BTROOTFSIMG=${BTTARGETDIR}ogclient.img |
---|
26 | export BTROOTFSMNT=${BTTARGETDIR}ogclientmount |
---|
27 | # tamaño maximo limitado por schroot 2GB |
---|
28 | export BTVIRTUALDISKSIZE=1000 |
---|
29 | export BTROOTFSIMGLABEL=ogClient |
---|
30 | |
---|
31 | export LOG_FILE=/tmp/boot-tools_installation.log |
---|
32 | } |
---|
33 | |
---|
34 | |
---|
35 | # btGetOsInfo: detecta la version del host, para tenerla de referencia en el boot-tools a generar. |
---|
36 | #@version 0.9 - Prototipo de sistema operativo multiarranque de opengnsys. |
---|
37 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
38 | #@date 2010/05/24 |
---|
39 | #@version 1.0 - Compatibilidad OpengGnsys X. |
---|
40 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
41 | #@date 2011/08/03 |
---|
42 | function btogGetOsInfo () |
---|
43 | { |
---|
44 | case $1 in |
---|
45 | lenny|LENNY) |
---|
46 | export OSDISTRIB=debian |
---|
47 | export OSCODENAME=lenny |
---|
48 | export OSRELEASE="2.6.28-11-generic" |
---|
49 | export OSARCH=i386 |
---|
50 | export OSHTTP="http://es.archive.ubuntu.com/ubuntu/ " |
---|
51 | ;; |
---|
52 | lucid|LUCID) |
---|
53 | export OSDISTRIB=ubuntu |
---|
54 | export OSCODENAME=lucid |
---|
55 | export OSRELEASE="2.6.32-21-generic-pae" |
---|
56 | export OSARCH=i386 |
---|
57 | export OSHTTP="http://es.archive.ubuntu.com/ubuntu/ " |
---|
58 | ;; |
---|
59 | host | HOST | *) |
---|
60 | export OSDISTRIB=$(lsb_release -i | awk -F: '{sub(/\t/,""); print $2}') 2>/dev/null |
---|
61 | export OSCODENAME=$(cat /etc/lsb-release | grep CODENAME | awk -F= '{print $NF}') |
---|
62 | export OSRELEASE=$(uname -a | awk '{print $3}') |
---|
63 | uname -a | grep x86_64 > /dev/null && export OSARCH=amd64 || export OSARCH=i386 |
---|
64 | export OSHTTP="http://es.archive.ubuntu.com/ubuntu/" |
---|
65 | ;; |
---|
66 | esac |
---|
67 | echo $OSDISTRIB:$OSCODENAME:$OSRELEASE:$OSARCH:$OSHTTP |
---|
68 | } |
---|
69 | |
---|
70 | # btogSetFsVirtual: Crea y formatea el fichero - disco duro virtual |
---|
71 | #@version 0.9 - Prototipo de sistema operativo multiarranque de opengnsys. |
---|
72 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
73 | #@date 2010/05/24 |
---|
74 | #@version 1.0 - Compatibilidad OpengGnsys X. |
---|
75 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
76 | #@date 2011/08/03 |
---|
77 | # error code return 2 |
---|
78 | btogSetFsVirtual () |
---|
79 | { |
---|
80 | |
---|
81 | local RERROR DISKLOOP PARTLOOP #return code error |
---|
82 | |
---|
83 | #Dependencias. |
---|
84 | [ -z "$BTROOTFSIMG" ] && btogGetVar |
---|
85 | |
---|
86 | echoAndLog "$FUNCNAME(): Creación y formateo del disco virtual $BTVIRTUALDISKSIZE MB " |
---|
87 | |
---|
88 | #Desmontamos el dispositivo virtual |
---|
89 | mount | grep $BTROOTFSMNT && umount $BTROOTFSMNT |
---|
90 | mount | grep $BTROOTFSMNTT && umount $BTROOTFSMNT |
---|
91 | |
---|
92 | #echo "$FUNCNAME(): Creando el directorio donde se montará el disco virtual $BTROOTFSMNT" |
---|
93 | mkdir -p $BTROOTFSMNT |
---|
94 | |
---|
95 | if [ $? -ne 0 ] |
---|
96 | then |
---|
97 | errorAndLog "$FUNCNAME(): Creando directorio $BTROOTFSMNT : ERROR" |
---|
98 | return 1 |
---|
99 | fi |
---|
100 | |
---|
101 | # Permisos para el usuario opengnsys. |
---|
102 | chown -R root:opengnsys $BTTARGETDIR |
---|
103 | |
---|
104 | #echo "$FUNCNAME(): Creando el disco virtual con tamaño máximo de $BTVIRTUALDISKSIZE MB" |
---|
105 | dd if=/dev/zero of=$BTROOTFSIMG bs=1048576 count=$BTVIRTUALDISKSIZE |
---|
106 | #qemu-img create $BTROOTFSIMG 3G |
---|
107 | #dd if=/dev/zero of=$BTROOTFSIMG bs=1k count=$OGCLIENTSIZEKB # necesita 500MB |
---|
108 | |
---|
109 | if [ $? -ne 0 ] |
---|
110 | then |
---|
111 | errorAndLog "$FUNCNAME(): Creando el disco virtual con tamaño maxima $BTVIRTUALDISKSIZE MB : ERROR" |
---|
112 | return 2 |
---|
113 | fi |
---|
114 | |
---|
115 | # Particionamos el disco virtual con una sola particion primaria. |
---|
116 | DISKLOOP=$(losetup -f) |
---|
117 | #TODO: si no DISKLOOP error |
---|
118 | losetup $DISKLOOP $BTROOTFSIMG |
---|
119 | #echo "$FUNCNAME(): particiondo el disco virtual - $DISKLOOP - con una particion primaria" |
---|
120 | echo -e "n\np\n1\n\n\nt\n83\nw" | fdisk $DISKLOOP |
---|
121 | |
---|
122 | |
---|
123 | #echoAndLog "$FUNCNAME(): Liberamos Desmontando $DISKLOOP despues del particionado " |
---|
124 | losetup -d $DISKLOOP |
---|
125 | if [ $? -ne 0 ] |
---|
126 | then |
---|
127 | errorAndLog "$FUNCNAME(): Liberando disco virtual despues del particionado: ERROR" |
---|
128 | return 2 |
---|
129 | fi |
---|
130 | |
---|
131 | |
---|
132 | PARTLOOP=$(losetup -f) |
---|
133 | #echo "$FUNCNAME(): Formateando la particion principal $PARTLOOP" |
---|
134 | losetup -o 32256 $PARTLOOP $BTROOTFSIMG && mkfs.ext3 -b 4096 -L $BTROOTFSIMGLABEL $PARTLOOP |
---|
135 | if [ $? -ne 0 ] |
---|
136 | then |
---|
137 | errorAndLog "$FUNCNAME(): Formateando la particion principal del disco virtual: ERROR" |
---|
138 | return 2 |
---|
139 | fi |
---|
140 | #echoAndLog "$FUNCNAME(): Desmontando $PARTLOOP despues del formateo " |
---|
141 | losetup -d $PARTLOOP |
---|
142 | if [ $? -ne 0 ] |
---|
143 | then |
---|
144 | errorAndLog "$FUNCNAME(): Liberando la particion virtual despues del formateo: ERROR" |
---|
145 | return 2 |
---|
146 | else |
---|
147 | echoAndLog "$FUNCNAME(): $BTROOTFSIMG $BTVIRTUALDISKSIZE MB : OK" |
---|
148 | fi |
---|
149 | } |
---|
150 | |
---|
151 | |
---|
152 | # btogSetfsBase: Genera el sistema root base con debootstrap |
---|
153 | #@version 0.9 - Prototipo de sistema operativo multiarranque de opengnsys. |
---|
154 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
155 | #@date 2010/05/24 |
---|
156 | #@version 1.0 - Compatibilidad OpengGnsys X. |
---|
157 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
158 | #@date 2011/08/03 |
---|
159 | # error code return 3 |
---|
160 | btogSetFsBase () |
---|
161 | { |
---|
162 | |
---|
163 | # Dependencias |
---|
164 | [ -z "$OSCODENAME" ] && btogGetOsInfo |
---|
165 | |
---|
166 | echoAndLog "$FUNCNAME: Iniciando la generación del sistema de archivos " |
---|
167 | |
---|
168 | #Montamos el dispositivo virtual en su punto de montaje. |
---|
169 | mount | grep $BTROOTFSMNT || mount $BTROOTFSIMG $BTROOTFSMNT -o loop,offset=32256 |
---|
170 | mount | grep $BTROOTFSMNT && echoAndLog "$FUNCNAME: mount $BTROOTFSIMG $BTROOTFSMNT -o loop,offset=32256 OK " || errorAndLog "$FUNCNAME: mount $BTROOTFSIMG $BTROOTFSMNT -o loop,offset=32256 : FAILURE " |
---|
171 | |
---|
172 | debootstrap --arch=$OSARCH --components=main,universe ${OSCODENAME} ${BTROOTFSMNT} ${OSHTTP} |
---|
173 | |
---|
174 | |
---|
175 | if [ $? -ne 0 ]; then |
---|
176 | errorAndLog "$FUNCNAME: debootstrap --include=linux-image-${OSRELEASE},linux-headers-${OSRELEASE} --arch=$OSARCH --components=main,universe $OSCODENAME $BTROOTFSMNT $OSHTTP : ha fallado!" |
---|
177 | mount | grep $BTROOTFSMNT && umount $BTROOTFSMNT |
---|
178 | return 3 |
---|
179 | else |
---|
180 | echoAndLog "$FUNCNAME: debootstrap --include=linux-image-${OSRELEASE},linux-headers-${OSRELEASE} --arch=$OSARCH --components=main,universe $OSCODENAME $BTROOTFSMNT $OSHTTP : ok" |
---|
181 | mount | grep $BTROOTFSMNT && umount $BTROOTFSMNT |
---|
182 | return 0 |
---|
183 | fi |
---|
184 | sleep 5 |
---|
185 | |
---|
186 | ##preubas revisar OSRELEASE |
---|
187 | #debootstrap --include=linux-image-${OSRELEASE},linux-headers-${OSRELEASE} --arch=$OSARCH --components=main,universe ${OSCODENAME} ${OGCLIENTMOUNT} ${OSHTTP} |
---|
188 | #debootstrap --include=linux-image-${OSRELEASE} --arch=i386 --variant=minbase $OSVERSION $OGCLIENTMOUNT http://es.archive.ubuntu.com/ubuntu/ |
---|
189 | #debootstrap --variant=minbase --include=linux-image-${OGRELEASE} --arch=i386 $OGVERSION $OGCLIENTMOUNT http://es.archive.ubuntu.com/ubuntu/ |
---|
190 | #echo debootstrap --include=linux-image-${OGRELEASE},dbus --arch=i386 --components=main,universe $OGVERSION $OGCLIENTMOUNT http://es.archive.ubuntu.com/ubuntu/ |
---|
191 | } |
---|
192 | |
---|
193 | #btogSetFsAcces: habilita el acceso al sistema root del cliente con schroot |
---|
194 | #@version 0.9 - Prototipo de sistema operativo multiarranque de opengnsys. |
---|
195 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
196 | #@date 2010/05/24 |
---|
197 | #@version 1.0 - Compatibilidad OpengGnsys X. |
---|
198 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
199 | #@date 2011/08/03 |
---|
200 | btogSetFsAccess() |
---|
201 | { |
---|
202 | echoAndLog "$FUNCNAME: Iniciando la configuración del schroot " |
---|
203 | cp /etc/schroot/schroot.conf /etc/schroot/schroot.conf.`getDateTime` |
---|
204 | cat << EOF > /etc/schroot/schroot.conf |
---|
205 | [IMGogclient] |
---|
206 | type=loopback |
---|
207 | file=/var/lib/tftpboot/ogclient/ogclient.img |
---|
208 | description=ogclient ubuntu luc IMGi |
---|
209 | #priority=1 |
---|
210 | users=root |
---|
211 | groups=root |
---|
212 | root-groups=root |
---|
213 | mount-options=-o offset=32256 |
---|
214 | root-users=root |
---|
215 | EOF |
---|
216 | |
---|
217 | cp /etc/schroot/mount-defaults /etc/schroot/mount-defaults.`getDateTime` |
---|
218 | cat << EOF > /etc/schroot/mount-defaults |
---|
219 | # mount.defaults: static file system information for chroots. |
---|
220 | # Note that the mount point will be prefixed by the chroot path |
---|
221 | # (CHROOT_PATH) |
---|
222 | # |
---|
223 | # <file system> <mount point> <type> <options> <dump> <pass> |
---|
224 | proc /proc proc defaults 0 0 |
---|
225 | #procbususb /proc/bus/usb usbfs defaults 0 0 |
---|
226 | #/dev /dev none rw,bind 0 0 |
---|
227 | /dev/pts /dev/pts none rw,bind 0 0 |
---|
228 | /dev/shm /dev/shm none rw,bind 0 0 |
---|
229 | #/home /home none rw,bind 0 0 |
---|
230 | /tmp /tmp none rw,bind 0 0 |
---|
231 | EOF |
---|
232 | |
---|
233 | echoAndLog "$FUNCNAME: Finalizado: OK " |
---|
234 | return 0 |
---|
235 | } |
---|
236 | |
---|
237 | |
---|
238 | |
---|
239 | #btogFsInitr genera un initrd. |
---|
240 | #@version 0.9 - Prototipo de sistema operativo multiarranque de opengnsys. |
---|
241 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
242 | #@date 2010/05/24 |
---|
243 | #@version 1.0 - Compatibilidad OpengGnsys X. |
---|
244 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
245 | #@date 2011/08/03 |
---|
246 | btogFsInitrd () |
---|
247 | { |
---|
248 | #DEPENDENCIAS |
---|
249 | ogClientVar |
---|
250 | ogClientOsInfo |
---|
251 | # $1 |
---|
252 | #TODO generara md5 del kernel y del initrd. |
---|
253 | |
---|
254 | cd / |
---|
255 | schroot -c IMGogclient -- /root/GenerateInitrd.generic.sh |
---|
256 | echo "cp /tmp/*-${OSRELEASE} $OGCLIENTBASEDIR" |
---|
257 | cp /tmp/*-${OSRELEASE} $OGCLIENTBASEDIR |
---|
258 | cp /tmp/initrd.img-${OSRELEASE} ${OGCLIENTBASEDIR}/oginitrd.img |
---|
259 | cp /tmp/vmlinuz-${OSRELEASE} ${OGCLIENTBASEDIR}/ogvmlinuz |
---|
260 | cd - |
---|
261 | chmod -R 755 $OGCLIENTBASEDIR |
---|
262 | } |
---|
263 | |
---|
264 | #btogFsToSqfs convierte el sistema root en sqfs |
---|
265 | #@version 0.9 - Prototipo de sistema operativo multiarranque de opengnsys. |
---|
266 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
267 | #@date 2010/05/24 |
---|
268 | #@version 1.0 - Compatibilidad OpengGnsys X. |
---|
269 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
270 | #@date 2011/08/03 |
---|
271 | btogFsSqfs () |
---|
272 | { |
---|
273 | #Dependencias. |
---|
274 | ogClientVar |
---|
275 | |
---|
276 | echoAndLog "$FUNCNAME: Iniciando la creación del sistema de archivos en sqfs " |
---|
277 | # si ya existe un sqfs lo renombramos |
---|
278 | [ -f $OGCLIENTBASEDIR/ogclient.sqfs ] && mv $OGCLIENTBASEDIR/ogclient.sqfs $OGCLIENTBASEDIR/ogclient.sqfs.`date +%Y%m%d-%H%M%S` |
---|
279 | mount | grep $OGCLIENTMOUNT || mount $OGCLIENTFILE $OGCLIENTMOUNT -o loop,offset=32256 |
---|
280 | |
---|
281 | mksquashfs $OGCLIENTMOUNT $OGCLIENTBASEDIR/ogclient.sqfs |
---|
282 | chmod 744 $OGCLIENTBASEDIR/ogclient.sqfs |
---|
283 | |
---|
284 | mount | grep $OGCLIENTMOUNT && umount $OGCLIENTMOUNT |
---|
285 | } |
---|
286 | |
---|
287 | |
---|
288 | |
---|
289 | |
---|
290 | |
---|
291 | # btogIsoGenerator genera la iso del cliente |
---|
292 | #@version 0.9 - Prototipo de sistema operativo multiarranque de opengnsys. |
---|
293 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
294 | #@date 2010/05/24 |
---|
295 | #@version 1.0 - Compatibilidad OpengGnsys X. |
---|
296 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
297 | #@date 2011/08/03 |
---|
298 | function btogIsoGenerator { |
---|
299 | apt-get install syslinux genisoimage |
---|
300 | #TODO: deb http://free.nchc.org.tw/drbl-core drbl stable |
---|
301 | #apt-get install gpxe |
---|
302 | mkdir -p /tmp/iso/isolinux |
---|
303 | #cd tmp/iso/ |
---|
304 | cp -prv /usr/lib/syslinux/* /tmp/iso/isolinux/ |
---|
305 | cp -prv /usr/share/gpxe/* /tmp/iso/isolinux/ |
---|
306 | mkdir -p /tmp/iso/ogclient |
---|
307 | #el ogclienteToISO debe tener una copia del ogvmlinuz como linuxISO |
---|
308 | cp -prv /var/lib/tftpboot/ogclientToIso/* /tmp/iso/ogclient |
---|
309 | |
---|
310 | |
---|
311 | cat << FIN > /tmp/iso/isolinux/isolinux.cfg |
---|
312 | DEFAULT menu.c32 |
---|
313 | PROMPT 0 |
---|
314 | ALLOWOPTIONS 1 |
---|
315 | |
---|
316 | MENU TITLE OpenGnsys 1.0.1 v00 |
---|
317 | |
---|
318 | LABEL gpxe |
---|
319 | MENU LABEL gpxe |
---|
320 | KERNEL /clonezilla/live/vmlinuz1 |
---|
321 | APPEND initrd=/clonezilla/live/initrd1.img boot=live union=aufs noswap vga=788 ip=frommedia |
---|
322 | |
---|
323 | |
---|
324 | #default 0 |
---|
325 | #prompt 1 |
---|
326 | #timeout 100 |
---|
327 | |
---|
328 | #display mensaje.txt |
---|
329 | |
---|
330 | |
---|
331 | |
---|
332 | |
---|
333 | LABEL 0 |
---|
334 | MENU LABEL ogClient vga irqpool acpi ogdebug ip:none |
---|
335 | KERNEL /ogclient/linuxISO |
---|
336 | APPEND initrd=/ogclient/oginitrd.img ro vga=788 irqpoll acpi=on boot=oginit og2nd=sqfs ogprotocol=local ogactiveadmin=true ogdebug=true ip=none |
---|
337 | |
---|
338 | LABEL 1 |
---|
339 | MENU LABEL ogClient irqpoll acpi ip:none |
---|
340 | KERNEL /ogclient/linuxISO |
---|
341 | APPEND initrd=/ogclient/oginitrd.img ro irqpoll acpi=on boot=oginit og2nd=sqfs ogprotocol=local ogactiveadmin=true ogdebug=false ip=none |
---|
342 | |
---|
343 | LABEL 2 |
---|
344 | MENU LABEL ogClient acpi debug ip=dhcp |
---|
345 | KERNEL /ogclient/linuxISO |
---|
346 | APPEND initrd=/ogclient/oginitrd.img ro acpi=on boot=oginit og2nd=sqfs ogprotocol=local ogactiveadmin=true ogdebug=true ip=dhcp |
---|
347 | |
---|
348 | LABEL 3 |
---|
349 | MENU LABEL ogClient ip=dhcp |
---|
350 | KERNEL /ogclient/linuxISO |
---|
351 | APPEND initrd=/ogclient/oginitrd.img ro acpi=off boot=oginit og2nd=sqfs ogprotocol=local ogactiveadmin=true ogdebug=false ip=dhcp |
---|
352 | |
---|
353 | |
---|
354 | #LABEL ogclient |
---|
355 | #KERNEL /ogclient/linuxISO |
---|
356 | #APPEND initrd=/ogclient/initrdISO.img |
---|
357 | |
---|
358 | #KERNEL linuxISO |
---|
359 | #APPEND initrd=initrdISO.img |
---|
360 | |
---|
361 | LABEL 4 |
---|
362 | MENU LABEL local |
---|
363 | localboot 0x80 |
---|
364 | append - |
---|
365 | |
---|
366 | |
---|
367 | label 5 |
---|
368 | MENU LABEL Network boot via gPXE lkrn |
---|
369 | KERNEL gpxe.lkrn |
---|
370 | |
---|
371 | label 5 |
---|
372 | MENU LABEL Network boot via gPXE usb |
---|
373 | KERNEL gpxe.usb |
---|
374 | |
---|
375 | label 5 |
---|
376 | MENU LABEL Network boot via gPXE pxe |
---|
377 | KERNEL gpxe.pxe |
---|
378 | |
---|
379 | label 5 |
---|
380 | MENU LABEL Network boot via gPXE iso |
---|
381 | KERNEL gpxe.iso |
---|
382 | FIN |
---|
383 | #### /tmp/iso# |
---|
384 | mkisofs -V ogClient -o ogClient.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -J -no-emul-boot -boot-load-size 4 -boot-info-table tmp/iso |
---|
385 | |
---|
386 | ### vi /etc/grub.d/40_custom |
---|
387 | ## |
---|
388 | #menuentry "og cache " { |
---|
389 | #set root=(hd0,4) |
---|
390 | #linux /ogvmlinuz ro vga=788 irqpoll acpi=on boot=oginit og2nd=sqfs ogprotocol=local ogactiveadmin=true ogdebug=true ip=none |
---|
391 | #initrd /oginitrd.img |
---|
392 | #} |
---|
393 | |
---|
394 | |
---|
395 | } |
---|
396 | |
---|
397 | |
---|
398 | #@version 0.9 - Prototipo de sistema operativo multiarranque de opengnsys. |
---|
399 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
400 | #@date 2010/05/24 |
---|
401 | #@version 1.0 - Compatibilidad OpengGnsys X. |
---|
402 | #@author Antonio J. Doblas Viso. Universidad de Malaga. |
---|
403 | #@date 2011/08/03 |
---|
404 | function btogIsoTest { |
---|
405 | #/tmp/iso |
---|
406 | qemu -m 256 -boot d -cdrom ogClient.iso |
---|
407 | } |
---|
408 | |
---|
409 | |
---|
410 | |
---|
411 | |
---|
412 | function getDateTime() |
---|
413 | { |
---|
414 | echo `date +%Y%m%d-%H%M%S` |
---|
415 | } |
---|
416 | |
---|
417 | # Escribe a fichero y muestra por pantalla |
---|
418 | function echoAndLog() |
---|
419 | { |
---|
420 | echo $1 |
---|
421 | FECHAHORA=`getDateTime` |
---|
422 | echo "$FECHAHORA;$SSH_CLIENT;$1" >> $LOG_FILE |
---|
423 | } |
---|
424 | |
---|
425 | function errorAndLog() |
---|
426 | { |
---|
427 | echo "ERROR: $1" |
---|
428 | FECHAHORA=`getDateTime` |
---|
429 | echo "$FECHAHORA;$SSH_CLIENT;ERROR: $1" >> $LOG_FILE |
---|
430 | } |
---|
431 | |
---|
432 | |
---|
433 | |
---|
434 | |
---|
435 | |
---|
436 | |
---|
437 | |
---|
438 | |
---|
439 | |
---|
440 | |
---|
441 | ############### No usados en el instalador, solo en actualizaciones. |
---|
442 | #/** |
---|
443 | # ogClientMount [str_program] |
---|
444 | #@brief Acceso al 2nd FS del cliente desde el Servidor Opengnsys |
---|
445 | #@param 1 Opciona: scripts o programa a ejecutar para automatizaciones |
---|
446 | #@return Si no hay parametros: login de acceso. |
---|
447 | #@return con un parametro: La salida del programa ejecutado |
---|
448 | #@exception |
---|
449 | #@note |
---|
450 | #@todo |
---|
451 | #@version 0.9 - Primera versión para OpenGnSys |
---|
452 | #@author Antonio J. Doblas Viso, Universidad de Málaga |
---|
453 | #@date 2010/02/15 |
---|
454 | #*/ ## |
---|
455 | function ogClientMount () |
---|
456 | { |
---|
457 | #TODO comprobar que OGFILE y OGFILEMOUNT existe. |
---|
458 | mount | grep $OGCLIENTFILE > /dev/null || mount $OGCLIENTFILE $OGCLIENTMOUNT -o loop,offset=32256 |
---|
459 | mount | grep $OGCLIENTMOUNT/proc > /dev/null || mount --bind /proc $OGCLIENTMOUNT/proc |
---|
460 | mount | grep $OGCLIENTMOUNT/sys > /dev/null || mount --bind /sys $OGCLIENTMOUNT/sys |
---|
461 | mount | grep $OGCLIENTMOUNT/tmp > /dev/null || mount --bind /tmp $OGCLIENTMOUNT/tmp |
---|
462 | mount | grep $OGCLIENTMOUNT/dev > /dev/null || mount --bind /dev $OGCLIENTMOUNT/dev |
---|
463 | mount | grep $OGCLIENTMOUNT/dev/pts > /dev/null || mount --bind /dev/pts $OGCLIENTMOUNT/dev/pts |
---|
464 | |
---|
465 | |
---|
466 | [ $# = 0 ] && $(chroot $OGCLIENTMOUNT /sbin/getty 38400 `tty`) |
---|
467 | [ $# = 1 ] && chroot $OGCLIENTMOUNT $1 |
---|
468 | |
---|
469 | } |
---|
470 | |
---|
471 | #/** |
---|
472 | # ogClientUnmount |
---|
473 | #@brief Desmonta el 2nd FS del cliente desde el Servidor Opengnsys |
---|
474 | #@param |
---|
475 | #@return |
---|
476 | #@exception |
---|
477 | #@note |
---|
478 | #@todo |
---|
479 | #@version 0.9 - Primera versión para OpenGnSys |
---|
480 | #@author Antonio J. Doblas Viso, Universidad de Málaga |
---|
481 | #@date 2010/02/15 |
---|
482 | #*/ ## |
---|
483 | |
---|
484 | function ogClientUnmount () |
---|
485 | { |
---|
486 | cd /tmp |
---|
487 | echo "desmontando cliente espere" |
---|
488 | sleep 5 |
---|
489 | mount | grep $OGCLIENTMOUNT/dev > /dev/null && umount $OGCLIENTMOUNT/dev || ogClientUnmount |
---|
490 | mount | grep $OGCLIENTMOUNT/dev/pts > /dev/null && umount $OGCLIENTMOUNT/dev/pts || ogClientUnmount |
---|
491 | mount | grep $OGCLIENTMOUNT/proc > /dev/null && umount $OGCLIENTMOUNT/proc || ogClientUnmount |
---|
492 | mount | grep $OGCLIENTMOUNT/sys > /dev/null && umount $OGCLIENTMOUNT/sys || ogClientUnmount |
---|
493 | mount | grep $OGCLIENTMOUNT/tmp > /dev/null && umount $OGCLIENTMOUNT/tmp || ogClientUnmount |
---|
494 | mount | grep $OGCLIENTMOUNT > /dev/null && umount $OGCLIENTMOUNT || ogClientUnmount |
---|
495 | #-d -f -l |
---|
496 | |
---|
497 | } |
---|