summarylogtreecommitdiffstats
path: root/uboot-legacy-initrd-remove
blob: b6ac98a0fc1d33f16e580bcbe12febc0fb9fe53b (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
42
43
44
45
46
47
48
#!/bin/bash -e

uimgs=()
all=0

uimgs_append() {
  uimgs+=($(
    . "$preset"
    for PRESET in "${PRESETS[@]}"; do
      IMAGE_VAR="${PRESET}_image"
      IMAGE_NAME="${!IMAGE_VAR}"
      echo "${IMAGE_NAME%.img}.uimg"
    done
  ))
}

while read -r line; do
  if [[ "$line" != */vmlinuz ]]; then
    # triggers when it's a change to the hooks package itself
    all=1
    continue
  fi

  if ! read -r pkgbase > /dev/null 2>&1 < "${line%/vmlinuz}/pkgbase"; then
    # if the kernel has no pkgbase, we skip it
    continue
  fi

  preset="/etc/mkinitcpio.d/${pkgbase}.preset"

  if [[ ! -e "$preset" ]]; then
    # if the kernel did not install its preset, we skip it
    continue
  fi

  uimgs_append
  
done

if (( all )) && compgen -G /boot/initramfs-linux*.uimg > /dev/null && compgen -G /etc/mkinitcpio.d/*.preset; then
  for preset in /etc/mkinitcpio.d/*.preset; do
    uimgs_append
  done
fi

if (( ${#uimgs[@]} )); then
  rm -f "${uimgs[@]}"
fi