Genericize package
[grml-rescueboot.git] / debian / grub-loopback-iso.postinst
1 #!/bin/sh
2 # postinst script for grub-loopback-iso
3
4 set -e
5
6 update_grub_wrapper() {
7   # default unless configured otherwise:
8   ISO_LOCATION="/boot/isos"
9
10   # grml-rescueboot backwards compatibility
11   if [ -d /boot/grml ]; then
12     ISO_LOCATION="${ISO_LOCATION} /boot/grml"
13   fi
14
15   if [ -r /etc/default/grub-loopback-isos ] ; then
16     . /etc/default/grub-loopback-isos
17   fi
18
19   # grml-rescueboot backwards compatibility
20   if [ -r /etc/default/grml-rescueboot ] ; then
21     . /etc/default/grml-rescueboot
22   fi
23
24   iso_list=""
25   for dir in $ISO_LOCATION; do
26     for file in "$dir"/*.iso ; do
27       [ -e "$file" ] || continue
28       iso_list="$iso_list $file"
29     done
30   done
31
32   if [ -z "$iso_list" ]; then
33     echo "INFO: No *.iso files found inside ${ISO_LOCATION}."
34     echo "INFO: Please create ${ISO_LOCATION} and place rescue ISO(s) there."
35     echo "INFO: Finally invoke update-grub and enjoy your rescue system."
36     return 0
37   fi
38
39   if ! which update-grub >/dev/null 2>&1; then
40     echo "WARN: ISOs found inside ${ISO_LOCATION} but update-grub not present (huh?)"
41     return 0
42   fi
43
44   if ! [ -e /boot/grub/grub.cfg ] ; then
45     echo "WARN: ISOs found inside ${ISO_LOCATION} but /boot/grub/grub.cfg does not exist."
46     echo "WARN: Ignoring request to run update-grub to avoid possible boot loader problems."
47     return 0
48   fi
49
50   echo "INFO: ISOs found inside ${ISO_LOCATION}, invoking update-grub:"
51   update-grub
52 }
53
54 case "$1" in
55     configure)
56       update_grub_wrapper
57     ;;
58
59     abort-upgrade|abort-remove|abort-deconfigure)
60     ;;
61
62     *)
63         echo "postinst called with unknown argument \`$1'" >&2
64         exit 1
65     ;;
66 esac
67
68 #DEBHELPER#
69
70 exit 0