summaryrefslogtreecommitdiff
path: root/src/initrd.sh
blob: 802e4ac714be94454413e9abe55d4b831c482a6b (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
36
37
38
39
40
41
#!/bin/sh

. samizdat-paths.sh

initrd=${samizdat_linux_dir}/initrd.img
vmlinuz=${samizdat_linux_dir}/vmlinuz
conf_dir=$samizdat_initramfs_conf_dir
apt_dependencies=$samizdat_initrd_files_dir/initrd-dependencies.txt

for kernel_package in linux-image-rt-amd64 linux-image-amd64
do
  kernel_package_version=$(apt-cache policy $kernel_package | sed -ne 's/ *Installed: //p')
  real_kernel_package=$(apt-cache show $kernel_package=$kernel_package_version | sed -n 's/^Depends: //p')
  version=${real_kernel_package#linux-image-}
  [ -e "/boot/vmlinuz-${version}" ] && break
done

find_source_dirs() {
    find "$conf_dir" "$samizdat_initrd_files_dir" "$@"
}

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