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

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 9a2cda1e was f2bb433, checked in by ramon <ramongomez@…>, 16 years ago

Correcciones en scripts de instalación.

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

  • Property mode set to 100755
File size: 6.7 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    echo '#! /bin/sh' > $INITSCRIPT
211    echo 'set -e' >> $INITSCRIPT
212    echo 'mkdir -p /var/state/dhcp' >> $INITSCRIPT
213    echo '/sbin/dhclient' >> $INITSCRIPT
214
215    # Montamos NFS y ejecutamos el script con nombre nuestra ip
216    echo "DHCP_SERVER=\`grep -h dhcp-server-identifier /var/lib/dhcp3/dhclient.* | sed 's/[^0-9]*\(.*\);/\1/' | head -1\`" >> $INITSCRIPT
217    echo "IP=\`grep -h fixed-address /var/lib/dhcp3/dhclient.* | sed 's/[^0-9]*\(.*\);/\1/' | head -1\`" >> $INITSCRIPT
218    echo "mkdir -p /opt/opengnsys" >> $INITSCRIPT
219    echo "mount -t nfs -onolock \$DHCP_SERVER:/opt/opengnsys/client /opt/opengnsys" >> $INITSCRIPT
220    echo "/opt/opengnsys/etc/preinit/default.sh" >> $INITSCRIPT
221
222    chmod +x $INITSCRIPT
223}
224
225function comprimir
226{
227    cd $NEWROOT
228
229    if [ $? = 1 ] ; then
230        exit -1
231    fi
232
233    find ./ | cpio -H newc -o > $TMPINITRD/new-initrd
234    cd $TMPINITRD
235    gzip -9 new-initrd
236}
237
238function finalizar
239{
240    cd $ANTERIORPWD
241    mv $TMPINITRD/new-initrd.gz $DEST/initrd.gz
242    if [ $LINUX ] ; then
243        mv $TMPINITRD/linux $DEST/linux
244    fi
245}
246
247parsearParametros $@
248descargar
249descomprimir
250#purgarFicherosDebian
251agregarNuevoArranque
252comprimir
253finalizar
Note: See TracBrowser for help on using the repository browser.