#!/bin/sh
#
#  chattr-lilo  -  prerm script for sure kernel upgrade/remove
#
#  Copyright (C) 2012-2014 Joachim Wiedorn
#  All rights reserved.
#
#  Licensed under the terms contained in the file 'COPYING'
#  in the source directory.
#

set -e

CHATTR=`which chattr` || exit 0
XFSINFO=`which xfs_info` || exit 0

if test -x $XFSINFO; then
  # check whether root partition is of xfs type
  [ `LANG=C $XFSINFO / | grep -c "attr="` -eq 1 ] || exit 0
fi

# second argument gives the path and filename
# first argument gives only the kernel version
if [ -n "${2}" ]; then
  IMAGE="${2}"
elif [ -n "${1}" ]; then
  IMAGE="/boot/vmlinuz-${1}"
else
  echo "[prerm.d] do not execute chattr"
  exit 0
fi

if [ -f "$IMAGE" ]; then
  echo "[prerm.d] chattr -i ${IMAGE}"   >&2
  $CHATTR -i "${IMAGE}"
fi

# end of file
