#! /bin/sh

# whoops! in /etc/cron.weekly/dpkg-mountable, fixed v0.3

set -e

if [ "$1" = "abort-upgrade" \
     -o "$1" = "abort-deconfigure" \
     -o "$1" = "abort-remove" ]; then
  exit
fi

if [ -e /var/log/4.0 -a -e /var/log/-c.0 ]; then
  cat <<EOF
Warning: an older version of dpkg-mountable appears to have left some
incorrect logfiles (-c.0 and 4.0, possibly higher numbers compressed) in your
/var/log directory.
EOF
  echo -n "Shall I delete them? [Yn] "
  read a
  if [ -z "$a" -o "$a" = "y" -o "$a" = "yes" -o "$a" = "Y" ]; then
    echo -n "Deleting: "
    for i in 4.0  4.1.gz  4.2.gz  4.3.gz  4.4.gz  4.5.gz  4.6.gz  4.7.gz \
             -c.0 -c.1.gz -c.2.gz -c.3.gz -c.4.gz -c.5.gz -c.6.gz -c.7.gz; do
      if [ -e /var/log/$i ]; then
        echo -n "$i "
        rm -f /var/log/$i
      fi
    done
    echo "done."
  else
    echo "OK, leaving them there."
  fi
fi

# rewrite config file, ensuring it includes new variables
if [ "$1" = "configure" ]; then
  /usr/lib/dpkg/methods/mountable/setup /var/lib/dpkg mountable 'int:postinst'
fi

exit 0
