source: client/boot/initrd-generator @ ecdc8ec

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 ecdc8ec was fc7848a, checked in by adv <adv@…>, 15 years ago

adaptación oginit para interpretar parametro repo, en su ausencia utiliza el dhcp. Se incluye en oginit la rutina de mount.sh. Por ese motivo se elimina su llamada desde el preinit/default.sh.
Lo que no he hecho es eliminar el mount.sh (aunque no se utiliza, se puede dejar para una posible reutilización)

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

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