source: client/boot/initrd-generator @ add0bfb

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 add0bfb was 6848297, checked in by ramon <ramongomez@…>, 14 years ago

Errata en mensaje de script de generación de cliente Initrd.

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

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