source: client/boot/initrd-generator @ 9f27c6e

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 9f27c6e was 23e86d8, checked in by ramon <ramongomez@…>, 15 years ago

Solución ticket:176 - Sustituir en el cliente el driver vga16fb por vesafb.

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

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