# vim:set ts=2 sw=2 ft=sh et:

# arg 1:  the new package version
post_install () {
  if type -P kernel-install >/dev/null; then
    version=${1%-*}
    version=${version/_/-}-stable
    echo "==> Calling kernel-install add $version ..."
    kernel-install add "$version" "/usr/lib/kernel/vmlinuz-$version"
  fi
}

# arg 1:  the new package version
# arg 2:  the old package version
pre_upgrade() {
  pre_remove "$2"
}

# arg 1:  the new package version
# arg 2:  the old package version
post_upgrade() {
  post_install "$1"
}

# arg 1:  the old package version
pre_remove() {
  if type -P kernel-install >/dev/null; then
    version=${1%-*}
    version=${version/_/-}-stable
    echo "==> kernel-install remove $version"
    kernel-install remove "$version"
  fi
}

# arg 1:  the old package version
post_remove() {
  version=${1%-*}
  version=${version/_/-}-stable
  echo "==> Cleaning remaining kernel $version modules"
  [[ -n $version ]] && rm -rvf /usr/lib/modules/"$version"
}
