summaryrefslogtreecommitdiff
path: root/initrd.sh
blob: 1eca9bb1835dbd5b99f6b6291438a9e715d1e0bf (plain)
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
#!/bin/sh

initrd=isolinux/live/initrd.img
vmlinuz=isolinux/live/vmlinuz

version=$(uname -r)
conf_dir=initramfs-tools

apt_dependencies=initrd-dependencies.txt

find_source_dirs() {
    set -- find "$conf_dir" ./old-school "$@"
    "$@"
}

force_rebuild()
{
    touch "$conf_dir"
    return 1
}

rebuild()
{
    [ ! -f "$apt_dependencies" ] || sudo apt-get install -q=10 --no-upgrade -y $(cat "$apt_dependencies")

    set -ex
    cp -f /boot/vmlinuz-${version} "$vmlinuz"
    /usr/sbin/mkinitramfs -d "$conf_dir" -o "$initrd" ${version} || force_rebuild
}

if [ ! -e "$initrd" -o ! -e "$vmlinuz" ]; then
    rebuild
elif [ "$(find_source_dirs -newer "$initrd" -print -quit)" ]; then
    rebuild
fi