#!/bin/sh
# (C) 2006 by Marcos Guglielmetti
# Released under GNU GPL v2 or any later version

# This script makes an initrd for kernels that 
# were not packaged with --initrd option

# Las versiones exactas de los kernels instalados 
# podemos obtenerlas mirando en 
# /lib/modules

ENGLISH="no"
CREADO="no"

if grep -w -q "lang=en" /proc/cmdline ; then
ENGLISH="yes"
fi



# ANSI COLORS
CRE="
[K"
NORMAL="[0;39m"
# RED: Failure or error message
RED="[1;31m"
# GREEN: Success message
GREEN="[1;32m"
# YELLOW: Descriptions
YELLOW="[1;33m"
# BLUE: System messages
BLUE="[1;34m"
# MAGENTA: Found devices or drivers
MAGENTA="[1;35m"
# CYAN: Questions
CYAN="[1;36m"
# BOLD WHITE: Hint
WHITE="[1;37m"


# if we are not installed: exit
[ -e /KNOPPIX/bin/ash ] && echo "Musix NOT Installed on HD..."
[ -e /KNOPPIX/bin/ash ] && exit

for k in $(ls /lib/modules); do

test -f /boot/initrd.img-$k
if [ "$?" = "0" ]
then
echo "
/boot/initrd.img-$k$GREEN
[OK]$NORMAL"

else

echo "$RED
There is no initrd.img for $k
$NORMAL
We will make:

/boot/initrd.img-$k

"
#ls /boot/initrd.img-$k

# no se encuentra el initrd para ese kernel, lo instalamos

# obtenemos el root para ese kernel (sólo por si lo implementamos por chroot)

# esto solo funciona si: 1) en menu.lst el formato es el siguiente:
#kernel          /boot/vmlinuz-2.6.15.4-rt root=/dev/hdb7 ro dma ramdisk_size=100000 init=/etc/init lang=es apm=power-off nomce quiet alsa dma bootfrom=/dev/hdb8/knx/knoppix.iso vga=normal
# 2) funciona si los nombres de los kernels son distintos

ROOT=`cat /boot/grub/menu.lst | grep $k | grep root | cut -f2 -d"=" | cut -f1 -d" "`

# realizamos el initrd
echo "Making initrd image for $k"
mkinitrd -o /boot/initrd.img-$k $k
[ -e /boot/initrd.img-$k ] && echo "
/boot/initrd.img-$k .......................... $YELLOW [created]$NORMAL"
CREADO="yes"
KCREADO="$k"

fi

done

if [ "$CREADO" = "yes" ]
then


if [ "$ENGLISH" = "yes" ]
then

echo "
....................................................................

We created an initrd image for $KCREADO kernel.

This usually happens only one time after Musix was installed on HD.

We advice you to reboot the machine if you want to use the new kernel

$YELLOW
¿Reboot?
[y/n]
$NORMAL
"


else
echo "
....................................................................

Hemos creado una imagen initrd -disco-RAM inicializado por el gestor
 de arranque- para el kernel $KCREADO

Esto generalmente ocurre una sola vez luego de la instalación de 
Musix en su PC.

Aconsejamos reiniciar la PC: de este modo podrá utilizar el nuevo 
kernel si lo desea.
$YELLOW
¿Reiniciar?
[y/n]
$NORMAL
"



fi


read YN

	if [ "$YN" = "y" ]
	then
	echo "Reiniciando en 10 segundos..."
	sleep 10s
	init 6

	else

	echo "No reiniciamos"
	exit
	fi

fi

