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
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}
[8908baa]10URL=http://archive.ubuntu.com/ubuntu/dists/$DIST-updates/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
[8908baa]37                URL=http://archive.ubuntu.com/ubuntu/dists/$DIST-updates/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
[8908baa]68    # Ficheros a descargar: Initrd y Kernel (si está habilitado).
69    FILES="initrd.gz"
70    [ $LINUX ] && FILES="$FILES linux"
[3434c53]71
[8908baa]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
[6848297]77        if [ $? != 0 ]; then
78            echo "Error no se ha podido descargar el fichero $f"
[8908baa]79            exit 1
[3434c53]80        fi
[8908baa]81    done
[3434c53]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
[bb6400a]93        rm -rf $NEWROOT
[3434c53]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/
[29b9d13]190    # Script de arranque de OpenGnSys Client.
[bb6400a]191    perl -i -p -e "s/\/sbin\/debian-installer\$/${CHROOTINITSCRIPT//\//\/}/" inittab
[29b9d13]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
[3434c53]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
[562547a]213    VERSION=$(cat /opt/opengnsys/doc/VERSION.txt 2>/dev/null)
214    VERSION=${VERSION:-"OpenGnSys"}
[d345fa6]215    cat << FIN > $INITSCRIPT
216#! /bin/sh
[562547a]217echo
218echo "Arranque cliente $VERSION"
219echo
[d345fa6]220set -e
[562547a]221# Exportando variables
222for i in \$(cat /proc/cmdline);
[fc7848a]223do
[562547a]224        echo \$i | grep -q "=" && export \$i
[fc7848a]225done
[562547a]226# Configurar la red
227if [ "\$ip" == "dhcp" ]; then
228    echo "Configurando red por DHCP"
[d345fa6]229    mkdir -p /var/state/dhcp
[562547a]230    /sbin/dhclient 2>/dev/null
[d345fa6]231fi
[562547a]232# Modo de trabajo del cliente: on-line/off-line
[fc7848a]233status="\${status:-online}"
[29b9d13]234echo "Comprobando modo de trabajo \$status"
[fc7848a]235case "\$status" in
[29b9d13]236    online)
[562547a]237        if [ -z "\$repo" ]
[fc7848a]238        then
239                SERVERIP=\$(grep -h dhcp-server-identifier /var/lib/dhcp3/dhclient.* | sed 's/[^0-9]*\(.*\);/\1/' | head -1)
240        else
[562547a]241                SERVERIP="\$repo"
[fc7848a]242        fi
[29b9d13]243        echo "Preparando conexión con el Repositorio  \$SERVERIP"
[fc7848a]244        # determinar el paramtro de boot para los permisos de los montajes de imagenes.
245        BOOTMODE=\${boot:-"user"}
246        case "\$BOOTMODE" in
[29b9d13]247            admin) MOUNTOPTS="rw" ;;
248            user)  MOUNTOPTS="ro" ;;
[562547a]249            *)     echo "Aviso: Modo de arranque desconocido."
250                   BOOTMODE="user"
[29b9d13]251                   MOUNTOPTS="ro" ;;
[fc7848a]252        esac
253        # Montamos el resto de cosas necesarias
[29b9d13]254        echo "Montar repo en modo \$BOOTMODE"
255        mkdir -p /opt/opengnsys
[562547a]256        DEFAULTOPTS="nolock,proto=tcp"
[29b9d13]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
[fc7848a]263        ;;
264    offline)
[29b9d13]265        echo "Off-line mode."
[fc7848a]266        ;;
267esac
[d345fa6]268/opt/opengnsys/etc/preinit/default.sh
269FIN
[bb6400a]270    chmod +x $INITSCRIPT
[3434c53]271}
272
[23e86d8]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
[3434c53]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{
[fee895e]300    cd $ANTERIORPWD
[3434c53]301    mv $TMPINITRD/new-initrd.gz $DEST/initrd.gz
[40488da]302    if [ $LINUX ] ; then
303        mv $TMPINITRD/linux $DEST/linux
304    fi
[3434c53]305}
306
[fee895e]307parsearParametros $@
[3434c53]308descargar
309descomprimir
310#purgarFicherosDebian
311agregarNuevoArranque
[23e86d8]312configurarModulos
[3434c53]313comprimir
314finalizar
Note: See TracBrowser for help on using the repository browser.