[3434c53] | 1 | #!/bin/bash |
---|
| 2 | |
---|
| 3 | DIST="jaunty" |
---|
| 4 | URL=http://archive.ubuntu.com/ubuntu/dists/$DIST/main/installer-i386/current/images/netboot/ubuntu-installer/i386 |
---|
| 5 | if [ "$TMP" = "" ] ; then TMP=/tmp ; fi |
---|
| 6 | TMPINITRD=$TMP/initrd |
---|
| 7 | NEWROOT=$TMPINITRD/newroot |
---|
[fee895e] | 8 | ANTERIORPWD=$PWD |
---|
[3434c53] | 9 | DEST=$PWD |
---|
| 10 | LINUX=1 |
---|
[bb6400a] | 11 | CHROOTINITSCRIPT=/oginit |
---|
| 12 | INITSCRIPT=$NEWROOT$CHROOTINITSCRIPT |
---|
[3434c53] | 13 | |
---|
| 14 | # Comprueba los argumentos pasados para modificar los valores por defecto |
---|
| 15 | function parsearParametros |
---|
| 16 | { |
---|
[383fe4b] | 17 | while [ $# -ne 0 ];do |
---|
| 18 | case $1 in |
---|
| 19 | ("-d") |
---|
| 20 | shift |
---|
[40488da] | 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/ |
---|
[383fe4b] | 23 | ;; |
---|
| 24 | ("-v") |
---|
| 25 | shift |
---|
| 26 | if [ $# -eq 0 ];then |
---|
| 27 | echo "Error en los argumentos" |
---|
| 28 | return -1 |
---|
| 29 | else |
---|
| 30 | DIST=$1 |
---|
[40488da] | 31 | URL=http://archive.ubuntu.com/ubuntu/dists/$DIST/main/installer-i386/current/images/netboot/ubuntu-installer/i386 |
---|
| 32 | shift |
---|
[383fe4b] | 33 | fi |
---|
| 34 | ;; |
---|
| 35 | ("-l") |
---|
| 36 | shift |
---|
| 37 | ;; |
---|
[fee895e] | 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 | ;; |
---|
[383fe4b] | 48 | esac |
---|
| 49 | done |
---|
[3434c53] | 50 | } |
---|
| 51 | |
---|
| 52 | function descargar |
---|
| 53 | { |
---|
[40488da] | 54 | # Borramos si existe el directorio temporal |
---|
| 55 | if [ -d $TMPINITRD ]; then |
---|
| 56 | rm -r $TMPINITRD |
---|
| 57 | fi |
---|
[3434c53] | 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 |
---|
[40488da] | 73 | if [ $LINUX ] ; then |
---|
[3434c53] | 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 |
---|
| 86 | function 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 |
---|
[bb6400a] | 94 | rm -rf $NEWROOT |
---|
[3434c53] | 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 |
---|
| 104 | function 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 |
---|
| 122 | function 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 |
---|
| 140 | function 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 |
---|
| 186 | function agregarNuevoArranque |
---|
| 187 | { |
---|
| 188 | cd $NEWROOT |
---|
| 189 | |
---|
| 190 | cd etc/ |
---|
[bb6400a] | 191 | perl -i -p -e "s/\/sbin\/debian-installer\$/${CHROOTINITSCRIPT//\//\/}/" inittab |
---|
[3434c53] | 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 |
---|
[d345fa6] | 210 | cat << FIN > $INITSCRIPT |
---|
| 211 | #! /bin/sh |
---|
| 212 | set -e |
---|
[fc7848a] | 213 | #exportando variables |
---|
| 214 | GLOBAL="cat /proc/cmdline" |
---|
| 215 | for i in \`\${GLOBAL}\` |
---|
| 216 | do |
---|
| 217 | #export \$i |
---|
| 218 | echo \$i | grep "=" > /dev/null && export \$i |
---|
| 219 | done |
---|
| 220 | #configurar la red |
---|
[d345fa6] | 221 | if grep -q "ip=dhcp" /proc/cmdline; then |
---|
| 222 | mkdir -p /var/state/dhcp |
---|
| 223 | /sbin/dhclient |
---|
| 224 | fi |
---|
[fc7848a] | 225 | echo Configurada la red \$ip |
---|
| 226 | #Modo de Trabajo del cliente, on line <> off lne |
---|
| 227 | status="\${status:-online}" |
---|
| 228 | echo "comprobando modo de trabajo \$status" |
---|
| 229 | case "\$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 | ;; |
---|
| 258 | esac |
---|
[d345fa6] | 259 | /opt/opengnsys/etc/preinit/default.sh |
---|
| 260 | FIN |
---|
[bb6400a] | 261 | chmod +x $INITSCRIPT |
---|
[3434c53] | 262 | } |
---|
| 263 | |
---|
| 264 | function 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 | |
---|
| 277 | function finalizar |
---|
| 278 | { |
---|
[fee895e] | 279 | cd $ANTERIORPWD |
---|
[3434c53] | 280 | mv $TMPINITRD/new-initrd.gz $DEST/initrd.gz |
---|
[40488da] | 281 | if [ $LINUX ] ; then |
---|
| 282 | mv $TMPINITRD/linux $DEST/linux |
---|
| 283 | fi |
---|
[3434c53] | 284 | } |
---|
| 285 | |
---|
[fee895e] | 286 | parsearParametros $@ |
---|
[3434c53] | 287 | descargar |
---|
| 288 | descomprimir |
---|
| 289 | #purgarFicherosDebian |
---|
| 290 | agregarNuevoArranque |
---|
| 291 | comprimir |
---|
| 292 | finalizar |
---|