[3434c53] | 1 | #!/bin/bash |
---|
[ab3a5dc] | 2 | # Generador de ficheros "kernel" e "initrd.gz" para arranque de cliente OpenGnSys |
---|
[3434c53] | 3 | |
---|
[ab3a5dc] | 4 | DIST="jaunty" # Distribución Ubuntu por defecto |
---|
| 5 | ARCH=$(arch) # Arquitectura del sistema: i386 (32 bits), amd64 (64 bits) |
---|
[23e86d8] | 6 | ARCH=${ARCH:-"$(uname -m)"} # Corrección para Ubuntu Jaunty. |
---|
| 7 | ARCH=${ARCH/i[4-6]86/i386} |
---|
[ab3a5dc] | 8 | ARCH=${ARCH/x86_64/amd64} |
---|
| 9 | URL=http://archive.ubuntu.com/ubuntu/dists/$DIST/main/installer-$ARCH/current/images/netboot/ubuntu-installer/$ARCH |
---|
[3434c53] | 10 | if [ "$TMP" = "" ] ; then TMP=/tmp ; fi |
---|
| 11 | TMPINITRD=$TMP/initrd |
---|
| 12 | NEWROOT=$TMPINITRD/newroot |
---|
[fee895e] | 13 | ANTERIORPWD=$PWD |
---|
[3434c53] | 14 | DEST=$PWD |
---|
| 15 | LINUX=1 |
---|
[bb6400a] | 16 | CHROOTINITSCRIPT=/oginit |
---|
| 17 | INITSCRIPT=$NEWROOT$CHROOTINITSCRIPT |
---|
[3434c53] | 18 | |
---|
| 19 | # Comprueba los argumentos pasados para modificar los valores por defecto |
---|
| 20 | function parsearParametros |
---|
| 21 | { |
---|
[383fe4b] | 22 | while [ $# -ne 0 ];do |
---|
| 23 | case $1 in |
---|
| 24 | ("-d") |
---|
| 25 | shift |
---|
[ab3a5dc] | 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/ |
---|
[383fe4b] | 28 | ;; |
---|
| 29 | ("-v") |
---|
| 30 | shift |
---|
| 31 | if [ $# -eq 0 ];then |
---|
| 32 | echo "Error en los argumentos" |
---|
| 33 | return -1 |
---|
| 34 | else |
---|
| 35 | DIST=$1 |
---|
[ab3a5dc] | 36 | URL=http://archive.ubuntu.com/ubuntu/dists/$DIST/main/installer-$ARCH/current/images/netboot/ubuntu-installer/$ARCH |
---|
[40488da] | 37 | shift |
---|
[383fe4b] | 38 | fi |
---|
| 39 | ;; |
---|
| 40 | ("-l") |
---|
| 41 | shift |
---|
| 42 | ;; |
---|
[fee895e] | 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 | ;; |
---|
[383fe4b] | 53 | esac |
---|
| 54 | done |
---|
[3434c53] | 55 | } |
---|
| 56 | |
---|
| 57 | function descargar |
---|
| 58 | { |
---|
[40488da] | 59 | # Borramos si existe el directorio temporal |
---|
| 60 | if [ -d $TMPINITRD ]; then |
---|
| 61 | rm -r $TMPINITRD |
---|
| 62 | fi |
---|
[3434c53] | 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 |
---|
[40488da] | 78 | if [ $LINUX ] ; then |
---|
[3434c53] | 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 |
---|
| 91 | function 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 |
---|
[bb6400a] | 99 | rm -rf $NEWROOT |
---|
[3434c53] | 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 |
---|
| 109 | function 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 |
---|
| 127 | function 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 |
---|
| 145 | function 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 |
---|
| 191 | function agregarNuevoArranque |
---|
| 192 | { |
---|
| 193 | cd $NEWROOT |
---|
| 194 | |
---|
| 195 | cd etc/ |
---|
[29b9d13] | 196 | # Script de arranque de OpenGnSys Client. |
---|
[bb6400a] | 197 | perl -i -p -e "s/\/sbin\/debian-installer\$/${CHROOTINITSCRIPT//\//\/}/" inittab |
---|
[29b9d13] | 198 | # Impedir usar shell en terminales 2 y 3 |
---|
| 199 | # (NOTA: comentar la siguiente línea para sistemas en pruebas). |
---|
| 200 | #perl -n -i -e "print unless /^tty[23]/" inittab |
---|
[3434c53] | 201 | |
---|
| 202 | # Script inicial que ejecuta el resto de scripts de /etc/rcS.d/ |
---|
| 203 | #echo "#! /bin/sh" >> rc |
---|
| 204 | #echo "for script in /etc/rcS.d/S[0-9][0-9]*; do if [ -x $script ]; then $script fi done" >> rc |
---|
| 205 | #chmod +x rc |
---|
| 206 | |
---|
| 207 | # Agregamos para que ejecute el script anterior lo primero |
---|
| 208 | #echo "::sysinit:/etc/init.d/rc" > inittab |
---|
| 209 | # Que ejecute el fichero /init cuando se reinicio el proceso init |
---|
| 210 | #echo "::restart:/sbin/init" >> inittab |
---|
| 211 | # Que funciona el control alt supr |
---|
| 212 | #echo "::ctrlaltdel:/sbin/reboot" >> inittab |
---|
| 213 | |
---|
| 214 | # Cosas que hacer si se apaga |
---|
| 215 | #echo "::shutdown:/bin/umount -a -r" >> inittab |
---|
| 216 | #echo "::shutdown:/sbin/swapoff -a" >> inittab |
---|
| 217 | |
---|
| 218 | # Primero ejecutamos el dhcp |
---|
[d345fa6] | 219 | cat << FIN > $INITSCRIPT |
---|
| 220 | #! /bin/sh |
---|
| 221 | set -e |
---|
[fc7848a] | 222 | #exportando variables |
---|
| 223 | GLOBAL="cat /proc/cmdline" |
---|
| 224 | for i in \`\${GLOBAL}\` |
---|
| 225 | do |
---|
| 226 | #export \$i |
---|
| 227 | echo \$i | grep "=" > /dev/null && export \$i |
---|
| 228 | done |
---|
| 229 | #configurar la red |
---|
[d345fa6] | 230 | if grep -q "ip=dhcp" /proc/cmdline; then |
---|
| 231 | mkdir -p /var/state/dhcp |
---|
| 232 | /sbin/dhclient |
---|
| 233 | fi |
---|
[fc7848a] | 234 | echo Configurada la red \$ip |
---|
| 235 | #Modo de Trabajo del cliente, on line <> off lne |
---|
| 236 | status="\${status:-online}" |
---|
[29b9d13] | 237 | echo "Comprobando modo de trabajo \$status" |
---|
[fc7848a] | 238 | case "\$status" in |
---|
[29b9d13] | 239 | online) |
---|
[fc7848a] | 240 | if [ -z \$repo ] |
---|
| 241 | then |
---|
| 242 | SERVERIP=\$(grep -h dhcp-server-identifier /var/lib/dhcp3/dhclient.* | sed 's/[^0-9]*\(.*\);/\1/' | head -1) |
---|
| 243 | else |
---|
| 244 | SERVERIP=\$repo |
---|
| 245 | fi |
---|
[29b9d13] | 246 | echo "Preparando conexión con el Repositorio \$SERVERIP" |
---|
[fc7848a] | 247 | # determinar el paramtro de boot para los permisos de los montajes de imagenes. |
---|
| 248 | BOOTMODE=\${boot:-"user"} |
---|
| 249 | case "\$BOOTMODE" in |
---|
[29b9d13] | 250 | admin) MOUNTOPTS="rw" ;; |
---|
| 251 | user) MOUNTOPTS="ro" ;; |
---|
[fc7848a] | 252 | *) # FIXME: Modo de arranque desconocido |
---|
[29b9d13] | 253 | echo "\$MSG_ERRBOOTMODE" |
---|
| 254 | MOUNTOPTS="ro" ;; |
---|
[fc7848a] | 255 | esac |
---|
| 256 | # Montamos el resto de cosas necesarias |
---|
[29b9d13] | 257 | echo "Montar repo en modo \$BOOTMODE" |
---|
| 258 | mkdir -p /opt/opengnsys |
---|
| 259 | DEFAULTOPTS="nolock" |
---|
| 260 | if \$(mount | grep -q " /opt/opengnsys "); then |
---|
| 261 | DEFAULTOPTS="remount,\$DEFAULTOPTS" |
---|
| 262 | fi |
---|
| 263 | mount -t nfs -o "\$DEFAULTOPTS,ro" \$SERVERIP:/opt/opengnsys/client /opt/opengnsys |
---|
| 264 | mount -t nfs -o "\$DEFAULTOPTS,rw" \$SERVERIP:/opt/opengnsys/log/clients /opt/opengnsys/log |
---|
| 265 | mount -t nfs -o "\$DEFAULTOPTS,\$MOUNTOPTS" \$SERVERIP:/opt/opengnsys/images /opt/opengnsys/images |
---|
[fc7848a] | 266 | ;; |
---|
| 267 | offline) |
---|
[29b9d13] | 268 | echo "Off-line mode." |
---|
[fc7848a] | 269 | ;; |
---|
| 270 | esac |
---|
[d345fa6] | 271 | /opt/opengnsys/etc/preinit/default.sh |
---|
| 272 | FIN |
---|
[bb6400a] | 273 | chmod +x $INITSCRIPT |
---|
[3434c53] | 274 | } |
---|
| 275 | |
---|
[23e86d8] | 276 | # Función para corregir problemas detectados con módulos del kernel. |
---|
| 277 | function configurarModulos |
---|
| 278 | { |
---|
| 279 | cd $NEWROOT/lib/modules/* |
---|
| 280 | |
---|
| 281 | case "$DIST" in |
---|
| 282 | lucid) # Corregir problema de frame-buffer en Lucid. |
---|
| 283 | perl -p -i -e 's/vga16fb/vesafb/g' modules.alias ;; |
---|
| 284 | *) ;; |
---|
| 285 | esac |
---|
| 286 | } |
---|
| 287 | |
---|
[3434c53] | 288 | function comprimir |
---|
| 289 | { |
---|
| 290 | cd $NEWROOT |
---|
| 291 | |
---|
| 292 | if [ $? = 1 ] ; then |
---|
| 293 | exit -1 |
---|
| 294 | fi |
---|
| 295 | |
---|
| 296 | find ./ | cpio -H newc -o > $TMPINITRD/new-initrd |
---|
| 297 | cd $TMPINITRD |
---|
| 298 | gzip -9 new-initrd |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | function finalizar |
---|
| 302 | { |
---|
[fee895e] | 303 | cd $ANTERIORPWD |
---|
[3434c53] | 304 | mv $TMPINITRD/new-initrd.gz $DEST/initrd.gz |
---|
[40488da] | 305 | if [ $LINUX ] ; then |
---|
| 306 | mv $TMPINITRD/linux $DEST/linux |
---|
| 307 | fi |
---|
[3434c53] | 308 | } |
---|
| 309 | |
---|
[fee895e] | 310 | parsearParametros $@ |
---|
[3434c53] | 311 | descargar |
---|
| 312 | descomprimir |
---|
| 313 | #purgarFicherosDebian |
---|
| 314 | agregarNuevoArranque |
---|
[23e86d8] | 315 | configurarModulos |
---|
[3434c53] | 316 | comprimir |
---|
| 317 | finalizar |
---|