jw-pkg/scripts/generate-boot-medium.sh

201 lines
4.2 KiB
Bash
Raw Normal View History

2006-06-29 06:36:25 +00:00
#!/bin/sh
myname=`basename $0`
cwd=`pwd`
make_initrd_from_template()
2006-06-29 06:36:25 +00:00
{
uname_r=$1
target=$2
modules_dir=$3
template=$4
shift 4
mod_names="$*"
# set up work space
2006-06-29 06:36:25 +00:00
dir=`mktemp -d "/tmp/$myname""_XXXXXX"`
mkdir $dir/source
# unpack template and copy it
cat $template | (cd $dir/source; gunzip | cpio -i)
2006-06-29 06:36:25 +00:00
cp -rp $dir/source $dir/target
rm -rf $dir/target/lib/modules/*
# copy all modules both in template and kernel
2006-06-29 06:36:25 +00:00
(
cd $dir/source
find . -name '*.ko'
) | while read tmpl_relpath; do
mod_name=`basename $tmpl_relpath`
source_mod=`cd $modules_dir; find . -name $mod_name`
if [ ! "$source_mod" ]; then
echo "warning: module $mod_name not found in $modules_dir" >&2
# exit 1
else
mod_relpath=`dirname $source_mod`
target_path=$dir/target/lib/modules/$uname_r/$mod_relpath
echo "copying $mod_name from $mod_relpath to $target_path"
mkdir -p $target_path
cp -p $modules_dir/$source_mod $target_path
2006-06-29 06:36:25 +00:00
fi
done
# copy all explicitly specified modules
for mod_name in $mod_names; do
echo "processing explicitly requested module $mod_name"
mod_source_path=`find $modules_dir -name $mod_name.ko`
if [ -z "$mod_source_path" ]; then
echo "warning: explicitly specified module $mod_name not found in $uname_r" >&2
continue
fi
mod_relpath=`echo $mod_source_path | sed "s%$modules_dir%%g; s/$mod_name.ko$//"`
target_path=$dir/target/lib/modules/$uname_r/$mod_relpath
echo "copying $mod_name from $mod_relpath to $target_path"
mkdir -p $target_path
cp -p $mod_source_path $target_path
done
2006-12-03 20:17:59 +00:00
# linuxrc
if [ "$linux_rc" ]; then
echo "copying $linux_rc to linuxrc"
cp $linux_rc $dir/target/init
fi
# depmod
/sbin/depmod -a -b $dir/target -v $uname_r > /dev/null
# pack stuff up
2006-06-29 06:36:25 +00:00
(cd $dir/target; find . | cpio -co) | gzip -9 > $target
rm -rf $dir
}
unquote()
{
cat | sed 's/^[ ]*|//'
}
2006-06-29 06:36:25 +00:00
config_section()
{
output_file=
add_boot_dir=
add_modules_basedir=
root_dev=
initrd_template=
sed -n "/\[$2\]/,/\[/ p" $1 | sed '/]/ d; s/#.*//; /./ !d; s/ *= */=/; s/=\(.*\)/="\1"/'
}
boot_sections()
{
sed '/\[boot\..*\]/ !d; s/\[boot\.//; s/\].*//' $1
}
name_filter()
{
echo $1 | \
tr [A-Z] [a-z] | \
sed 's/\.tar\.gz/.tgz/; s/-/_/g; s/\([^.]*\)\.\([^.]*\)$$/\1@\2/; s/\./_/g; s/@/./'
2006-06-29 06:36:25 +00:00
}
#make_initrd $template $modules_dir
set -- `getopt 'i:f:o:d:' $*`
2006-06-29 06:36:25 +00:00
while [ "$1" != -- ]; do
case $1 in
-f)
opt_config_file="$2"
shift
;;
-o)
opt_output_file="$2"
shift
;;
-d)
opt_build_dir="$2"
boot_dir="$2"
shift
;;
-i)
linux_rc="$2"
shift
;;
2006-06-29 06:36:25 +00:00
*)
usage
;;
2006-06-29 06:36:25 +00:00
esac
shift
done
shift
if [ ! "$opt_build_dir" ]; then
boot_dir=`mktemp -d "/tmp/$myname""_XXXXXX"`
fi
2006-06-29 06:36:25 +00:00
eval `config_section $opt_config_file global`
echo DEFAULT menu.c32 > $boot_dir/isolinux.cfg
echo PROMPT 0 >> $boot_dir/isolinux.cfg
for sec in `boot_sections $opt_config_file`; do
2006-06-29 06:36:25 +00:00
echo "+ processing section boot.$sec"
config_section $opt_config_file boot.$sec
2006-06-29 06:36:25 +00:00
eval `config_section $opt_config_file boot.$sec`
2006-06-29 06:36:25 +00:00
if [ "$add_boot_dir" ]; then
2006-06-29 06:36:25 +00:00
echo "+ adding boot directory $add_boot_dir"
for f in $add_boot_dir/*; do
b=`basename $f`
n=`name_filter $b`
echo "+ copying $f -> $n"
cp -p $f $boot_dir/$n
done
2006-06-29 06:36:25 +00:00
kernels=`file $add_boot_dir/* | grep -ie 'linux.*kernel' | sed 's/:.*//'`
for kernel in $kernels; do
2006-06-29 06:36:25 +00:00
kernel_version=`basename $kernel | sed 's/vmlinuz-//'`
kernel_version_iso=`name_filter $kernel_version | cut -b1-21`
2006-06-29 06:36:25 +00:00
echo "+ processing kernel $kernel (version $kernel_version)"
# create initrd
if [ "$initrd_template" ]; then
echo "+ creating initial ram disk from template $initrd_template"
make_initrd_from_template \
2006-12-03 20:17:59 +00:00
$kernel_version \
$boot_dir/initrd_$kernel_version_iso \
$add_modules_basedir/$kernel_version \
$initrd_template \
$included_modules
2006-06-29 06:36:25 +00:00
fi
# create isolinux.cfg
cat << EOT | unquote >> $boot_dir/isolinux.cfg
|
|LABEL $kernel_version
|KERNEL vmlinuz_$kernel_version_iso
|APPEND initrd=initrd_$kernel_version_iso root=$root_dev
EOT
2006-06-29 06:36:25 +00:00
done
fi
done
cp $* $boot_dir
mkisofs -l --iso-level 2 -o $opt_output_file \
-b isolinux.bin -c boot.cat \
-no-emul-boot -boot-load-size 4 -boot-info-table \
$boot_dir
if [ ! "$opt_build_dir" ]; then
rm -rf $boot_dir
fi