source: client/boot/initrd-generator @ 562547a

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since 562547a was 562547a, checked in by ramon <ramongomez@…>, 14 years ago

Modificaciones en script initrd-generator:

  • Corrección error al detectar distribución de Ubuntu.
  • El cliente va a montar NFS sobre TCP en vez de sobre UDP.
  • Mostrar versión de OpenGnSys en arranque de cliente.
  • No mostrar mensajes de DHCP.
  • Limpieza de código.

Close #275.

git-svn-id: https://opengnsys.es/svn/trunk@1372 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100755
File size: 8.8 KB
RevLine 
[3434c53]1#!/bin/bash
[ab3a5dc]2# Generador de ficheros "kernel" e "initrd.gz" para arranque de cliente OpenGnSys
[3434c53]3
[562547a]4test "$(lsb_release -is 2>/dev/null)" == "Ubuntu" && DIST="$(lsb_release -cs)"
[28c96b3]5DIST=${DIST:-"lucid"}           # Si no se detecta, distribución Ubuntu por defecto.
6ARCH=$(arch)                    # Arquitectura del sistema: i386 (32 bits), amd64 (64 bits).
[23e86d8]7ARCH=${ARCH:-"$(uname -m)"}     # Corrección para Ubuntu Jaunty.
8ARCH=${ARCH/i[4-6]86/i386}
[ab3a5dc]9ARCH=${ARCH/x86_64/amd64}
10URL=http://archive.ubuntu.com/ubuntu/dists/$DIST/main/installer-$ARCH/current/images/netboot/ubuntu-installer/$ARCH
[3434c53]11if [ "$TMP" = "" ] ; then TMP=/tmp ; fi
12TMPINITRD=$TMP/initrd
13NEWROOT=$TMPINITRD/newroot
[fee895e]14ANTERIORPWD=$PWD
[3434c53]15DEST=$PWD
16LINUX=1
[bb6400a]17CHROOTINITSCRIPT=/oginit
18INITSCRIPT=$NEWROOT$CHROOTINITSCRIPT
[3434c53]19
20# Comprueba los argumentos pasados para modificar los valores por defecto
21function parsearParametros
22{
[383fe4b]23    while [ $# -ne 0 ];do
24        case $1 in
25            ("-d")
26            shift
[ab3a5dc]27                #URL=http://people.debian.org/~joeyh/d-i/images/daily/netboot/debian-installer/i386/
28                URL=http://ftp.nl.debian.org/debian/dists/testing/main/installer-$ARCH/current/images/netboot/debian-installer/$ARCH/
[383fe4b]29            ;;
30            ("-v")
31            shift
32            if [ $# -eq 0 ];then
33                echo "Error en los argumentos"
34                return -1
35            else
36                DIST=$1
[ab3a5dc]37                URL=http://archive.ubuntu.com/ubuntu/dists/$DIST/main/installer-$ARCH/current/images/netboot/ubuntu-installer/$ARCH
[40488da]38                shift
[383fe4b]39            fi
40            ;;
41            ("-l")
42            shift
43            ;;
[fee895e]44            ("-t")
45            shift
46            if [ $# -eq 0 ];then
47                echo "Error en los argumentos"
48                return -1
49            else
50                DEST=$1
51                shift
52            fi
53            ;;
[383fe4b]54        esac
55    done
[3434c53]56}
57
58function descargar
59{
[40488da]60    # Borramos si existe el directorio temporal
61    if [ -d $TMPINITRD ]; then
62        rm -r $TMPINITRD
63    fi
[3434c53]64    # Creamos directorio temporal y nos vamos alli
65    mkdir -p $TMPINITRD
66    cd $TMPINITRD
67
68    # Borramos el initrd anterior si existe
69    if [ -f initrd.gz ]; then rm initrd.gz; fi
70
71    # Nos lo descargamos
72    wget $URL/initrd.gz
73    if [ $? = 1 ] ; then
74        echo Error no se ha podido descarga el initrd.gz
75        exit -1
76    fi
77
78    # Si la opcion de descargar el nucleo tambien esta habilitado nos lo descargamos
[40488da]79    if [ $LINUX ] ; then
[3434c53]80        if [ -f linux ] ; then
81            rm linux
82        fi
83        wget $URL/linux
84        if [ $? = 1 ] ; then
85            echo Error no se ha podido descargar el nucleo linux
86            exit -1
87        fi
88    fi
89}
90
91# Descomprimimos el initrd
92function descomprimir
93{
94    if [ ! -f  $TMPINITRD/initrd.gz ]; then
95        echo No se encuentra el initrd.gz
96        exit -1
97    fi
98
99    if [ -f $NEWROOT ];then
[bb6400a]100        rm -rf $NEWROOT
[3434c53]101    fi
102
103    mkdir -p $NEWROOT
104    cd $NEWROOT
105
106    gzip -dc $TMPINITRD/initrd.gz | cpio -id
107}
108
109# Borrar todos los scripts del directorio actual
110function borrarScripts
111{
112    # Primero los hacemos con los enlaces para que no se produzcan errores si borramos a lo que apunta primero
113    for i in `ls -F -1 | grep @ | awk -F @ '{print $1}'`; do
114        if [ $(file $i -L | grep "shell script" | wc -l) -gt 0 ]; then
115            rm $i
116        fi
117    done
118
119    # Ahora lo hacemos con todos los ejecutables
120    for i in `ls`; do
121        if [ $(file $i | grep "shell script" | wc -l) -gt 0 ]; then
122            rm $i
123        fi
124    done
125}
126
127# Borra todos los ejecutables que enlacen con la libreria debian-installer
128function borrarEjecutablesDebinstall
129{
130    # Primero lo hacemos con los enlaces para que no se produzcan errores si borramos a lo que apunta primero
131    for i in `ls -F -1 | grep @ | awk -F @ '{print $1}'`; do
132        if [ $(ldd $i | grep -e libdebian-installer -e libdebconf | wc -l) -gt 0 ]; then
133            rm $i
134        fi
135    done
136
137    # Ahora lo hacemos con todos los ejecutables
138    for i in `ls`; do
139        if [ $(ldd $i | grep -e libdebian-installer -e libdebconf | wc -l) -gt 0 ]; then
140            rm $i
141        fi
142    done
143}
144
145# Elimina todos los fichero innecesarios del initrd
146function purgarFicherosDebian
147{
148    mkdir -p $NEWROOT
149    cd $NEWROOT
150
151    rm init
152
153    # Pasamos por todos los directorios y vamos borrando lo innecesario
154    cd bin/
155    borrarScripts
156    borrarEjecutablesDebinstall
157
158    cd ../etc/
159    rm -rf cdebconf.conf default-release lsb-release preseed_aliases udebs-source
160
161    cd ../lib/
162    rm -rf chroot-setup.sh debian-installer* kickseed main-menu.d preseed libdebian-installer*
163
164    cd ../sbin/
165    borrarScripts
166    borrarEjecutablesDebinstall
167
168    cd ../usr/bin/
169    borrarScripts
170    borrarEjecutablesDebinstall
171
172    cd ../lib/
173    rm -rf base-installer.d debian-installer finish-install.d libdebconfclient* cdebconf fetch-url net-retriever post-base-installer.d
174
175    # Solo queda un enlace simbolico que ya no apunta a nada
176    cd ../sbin/
177    rm -rf *
178
179    cd ../share/
180    rm -rf debconf keyrings save-logs
181
182    cd ../../var/
183    rm -rf cache/anna/ spool/kickseed/
184
185    cd lib/
186    rm -rf apt-install cdebconf dpkg
187
188    cd ../..
189}
190
191# Le agrega los archivos necesarios para que arranque de otra manera
192function agregarNuevoArranque
193{
194    cd $NEWROOT
195
196    cd etc/
[29b9d13]197    # Script de arranque de OpenGnSys Client.
[bb6400a]198    perl -i -p -e "s/\/sbin\/debian-installer\$/${CHROOTINITSCRIPT//\//\/}/" inittab
[29b9d13]199    # Impedir usar shell en terminales 2 y 3
200    #    (NOTA: comentar la siguiente línea para sistemas en pruebas).
201    #perl -n -i -e "print unless /^tty[23]/" inittab
[3434c53]202
203    # Script inicial que ejecuta el resto de scripts de /etc/rcS.d/
204    #echo "#! /bin/sh" >> rc
205    #echo "for script in /etc/rcS.d/S[0-9][0-9]*; do if [ -x $script ]; then $script fi done" >> rc
206    #chmod +x rc
207
208    # Agregamos para que ejecute el script anterior lo primero
209    #echo "::sysinit:/etc/init.d/rc" > inittab
210    # Que ejecute el fichero /init cuando se reinicio el proceso init
211    #echo "::restart:/sbin/init" >> inittab
212    # Que funciona el control alt supr
213    #echo "::ctrlaltdel:/sbin/reboot" >> inittab
214
215    # Cosas que hacer si se apaga
216    #echo "::shutdown:/bin/umount -a -r" >> inittab
217    #echo "::shutdown:/sbin/swapoff -a" >> inittab
218
219    # Primero ejecutamos el dhcp
[562547a]220    VERSION=$(cat /opt/opengnsys/doc/VERSION.txt 2>/dev/null)
221    VERSION=${VERSION:-"OpenGnSys"}
[d345fa6]222    cat << FIN > $INITSCRIPT
223#! /bin/sh
[562547a]224echo
225echo "Arranque cliente $VERSION"
226echo
[d345fa6]227set -e
[562547a]228# Exportando variables
229for i in \$(cat /proc/cmdline);
[fc7848a]230do
[562547a]231        echo \$i | grep -q "=" && export \$i
[fc7848a]232done
[562547a]233# Configurar la red
234if [ "\$ip" == "dhcp" ]; then
235    echo "Configurando red por DHCP"
[d345fa6]236    mkdir -p /var/state/dhcp
[562547a]237    /sbin/dhclient 2>/dev/null
[d345fa6]238fi
[562547a]239# Modo de trabajo del cliente: on-line/off-line
[fc7848a]240status="\${status:-online}"
[29b9d13]241echo "Comprobando modo de trabajo \$status"
[fc7848a]242case "\$status" in
[29b9d13]243    online)
[562547a]244        if [ -z "\$repo" ]
[fc7848a]245        then
246                SERVERIP=\$(grep -h dhcp-server-identifier /var/lib/dhcp3/dhclient.* | sed 's/[^0-9]*\(.*\);/\1/' | head -1)
247        else
[562547a]248                SERVERIP="\$repo"
[fc7848a]249        fi
[29b9d13]250        echo "Preparando conexión con el Repositorio  \$SERVERIP"
[fc7848a]251        # determinar el paramtro de boot para los permisos de los montajes de imagenes.
252        BOOTMODE=\${boot:-"user"}
253        case "\$BOOTMODE" in
[29b9d13]254            admin) MOUNTOPTS="rw" ;;
255            user)  MOUNTOPTS="ro" ;;
[562547a]256            *)     echo "Aviso: Modo de arranque desconocido."
257                   BOOTMODE="user"
[29b9d13]258                   MOUNTOPTS="ro" ;;
[fc7848a]259        esac
260        # Montamos el resto de cosas necesarias
[29b9d13]261        echo "Montar repo en modo \$BOOTMODE"
262        mkdir -p /opt/opengnsys
[562547a]263        DEFAULTOPTS="nolock,proto=tcp"
[29b9d13]264        if \$(mount | grep -q " /opt/opengnsys "); then
265            DEFAULTOPTS="remount,\$DEFAULTOPTS"
266        fi
267        mount -t nfs -o "\$DEFAULTOPTS,ro" \$SERVERIP:/opt/opengnsys/client /opt/opengnsys
268        mount -t nfs -o "\$DEFAULTOPTS,rw" \$SERVERIP:/opt/opengnsys/log/clients /opt/opengnsys/log
269        mount -t nfs -o "\$DEFAULTOPTS,\$MOUNTOPTS" \$SERVERIP:/opt/opengnsys/images /opt/opengnsys/images
[fc7848a]270        ;;
271    offline)
[29b9d13]272        echo "Off-line mode."
[fc7848a]273        ;;
274esac
[d345fa6]275/opt/opengnsys/etc/preinit/default.sh
276FIN
[bb6400a]277    chmod +x $INITSCRIPT
[3434c53]278}
279
[23e86d8]280# Función para corregir problemas detectados con módulos del kernel.
281function configurarModulos
282{
283    cd $NEWROOT/lib/modules/*
284
285    case "$DIST" in
286        lucid)  # Corregir problema de frame-buffer en Lucid.
287                perl -p -i -e 's/vga16fb/vesafb/g' modules.alias ;;
288        *)      ;;
289    esac
290}
291
[3434c53]292function comprimir
293{
294    cd $NEWROOT
295
296    if [ $? = 1 ] ; then
297        exit -1
298    fi
299
300    find ./ | cpio -H newc -o > $TMPINITRD/new-initrd
301    cd $TMPINITRD
302    gzip -9 new-initrd
303}
304
305function finalizar
306{
[fee895e]307    cd $ANTERIORPWD
[3434c53]308    mv $TMPINITRD/new-initrd.gz $DEST/initrd.gz
[40488da]309    if [ $LINUX ] ; then
310        mv $TMPINITRD/linux $DEST/linux
311    fi
[3434c53]312}
313
[fee895e]314parsearParametros $@
[3434c53]315descargar
316descomprimir
317#purgarFicherosDebian
318agregarNuevoArranque
[23e86d8]319configurarModulos
[3434c53]320comprimir
321finalizar
Note: See TracBrowser for help on using the repository browser.