make-initrd.sh 1.18 KB
Newer Older
Daniel Bissani Furlin's avatar
Daniel Bissani Furlin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#!/bin/bash

_DIST=$1
PREFIX=$PWD

source ${PREFIX}/conf/$_DIST/create-iso.conf
source ${PREFIX}/common.sh

if [ ! -d ${PREFIX}/initrd ]; then
    mkdir ${PREFIX}/initrd
else
    rm -rf ${PREFIX}/initrd/*
fi
ls ${CHROOTDIR}/boot/
initname=$(ls "${CHROOTDIR}/boot/" | grep "initrd.*")
echo "initname = '${initname}'"
cd ${PREFIX}/initrd
gzip -dc ${CHROOTDIR}/boot/${initname} | cpio -id
broken_links=$(find . -type l ! -exec test -e {} \; -print)
for broken_link in ${broken_links}; do
    path_file=$(readlink -m ${broken_link})
    # Expand path_file and remove prefix presents in broken_link variable
    # ex: path_file = /usr/share/plymouth/themes/le-text/le-text.plymouth
    # $(dirname broken_link) = ./usr/share/plymouth/themes/
    # so relative_path = le-text/le-text.plymouth
    # parameter expansion used "${PARAMETER#PATTERN}" remove substring from PARAMETER that matches with PATTHERN
    link_dir=$(dirname ${broken_link})
    link_name=$(basename ${broken_link})
    cd ${link_dir}
    relative_path=${path_file#*${link_dir#.}/}
    rm ${link_name}
    ln -s ${relative_path} ${link_name}
    cd -
done
find . | cpio --quiet --dereference -o -H newc | lzma -7 > ../initrd.lz
cd ..
exit 0