make-initrd.sh 2.74 KB
Newer Older
Daniel Bissani Furlin's avatar
Daniel Bissani Furlin committed
1
#!/usr/bin/env bash
2 3 4 5 6 7
#
# Copyright (C) 2017 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of create-iso
#
8
# create-iso is free software; you can redistribute it and/or
9 10 11 12 13 14 15 16 17 18 19 20 21
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
Daniel Bissani Furlin's avatar
Daniel Bissani Furlin committed
22 23

_DIST=$1
24
_ARCH=$2
25 26
_REPO=$3
CHROOTDIR=$4
27
SCRIPT_NAME=$5
28 29 30 31 32 33 34 35 36 37 38 39 40 41
DISTRO=$6
DPLIST=$7
INSTLIST=$8
ISOLINUX=$9
MOUNTLIST=${10}
OURSOURCESLIST=${11}
RMDSKT=${12}
RMLIST=${13}
SCRIPTSDIR=${14}
SHORTNAME=${15}
SOURCESLISTDEFAULT=${16}
TMP=${17}
TMPFS=${18}
REPOPKGS=${19}
Daniel Bissani Furlin's avatar
Daniel Bissani Furlin committed
42 43
PREFIX=$PWD

44 45
type genErrHandle >/dev/null 2>&1 || source ${PREFIX}/common.sh
type pinfo >/dev/null 2>&1 || source ${PREFIX}/helper/logging.incsh
Daniel Bissani Furlin's avatar
Daniel Bissani Furlin committed
46

47 48
version=$(ls ${CHROOTDIR}/boot/ | egrep "initrd.img-[0-9,.,-]*-generic" | cut --delimiter='-' --fields=2,3 | sort --version-sort --reverse | head --lines=1)
cp "${CHROOTDIR}/boot/vmlinuz-${version}-generic" ${TMP}/image/casper/vmlinuz; $(genErrHandle "Unable to copy kernel to image")
49
if ! test -f initrd.lz; then
50
    initname="initrd.img-${version}-generic"
51 52 53
    if [ ! -d ${PREFIX}/initrd ]; then
        mkdir ${PREFIX}/initrd
    else
54
        rm --recursive --force ${PREFIX}/initrd/*
55
    fi
56
    pinfo "Using '${initname}'"
57
    initrd_type=$(file "${CHROOTDIR}/boot/${initname}")
58
    pushd ${PREFIX}/initrd
59 60 61 62 63 64 65 66
    if echo ${initrd_type} | grep --quiet --ignore-case "gzip"; then
        gzip --decompress --stdout "${CHROOTDIR}/boot/${initname}" | cpio --extract; $(genErrHandle "Unable to decompress initrd")
    elif echo ${initrd_type} | grep --quiet --ignore-case "ascii"; then
        block_size=$(binwalk --include="compressed data" "${CHROOTDIR}/boot/${initname}" | cut --delimiter=" " --fields=1 | egrep "[0-9]+")
       dd if="${CHROOTDIR}/boot/${initname}" bs="${block_size}" skip=1 | gunzip | cpio --extract --make-directories
    else
        perror "${BASH_SOURCE[0]}: Invalid initrd format"; /bin/bash
    fi
67 68
    find . | cpio --quiet --create -H newc | lzma -7 > ../initrd.lz; $(genErrHandle "Unable to compress initrd")
    popd
69
    rm --recursive --force ${PREFIX}/initrd
Daniel Bissani Furlin's avatar
Daniel Bissani Furlin committed
70
fi
71 72
mv initrd.lz ${TMP}/image/casper/initrd.lz; $(genErrHandle "Unable to copy initrd to image")

73

Daniel Bissani Furlin's avatar
Daniel Bissani Furlin committed
74
exit 0