1722daa5458530685eebe6223704f1e2f97a3622
[invirt/packages/xvm-iscsi-config.git] / debian / xvm-iscsi-config.postinst
1 #!/bin/sh
2 # postinst script for xvm-iscsi-config
3 #
4 # see: dh_installdeb(1)
5
6 set -e
7
8 # Source debconf library
9 . /usr/share/debconf/confmodule
10
11 # summary of how this script can be called:
12 #        * <postinst> `configure' <most-recently-configured-version>
13 #        * <old-postinst> `abort-upgrade' <new version>
14 #        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
15 #          <new-version>
16 #        * <postinst> `abort-remove'
17 #        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
18 #          <failed-install-package> <version> `removing'
19 #          <conflicting-package> <version>
20 # for details, see http://www.debian.org/doc/debian-policy/ or
21 # the debian-policy package
22
23 # dh_installdeb will replace this with shell code automatically
24 # generated by other debhelper scripts.
25
26 #DEBHELPER#
27
28 case "$1" in
29     configure)
30         db_get xvm-iscsi-config/address
31         ADDRESS="$RET"
32         db_get xvm-iscsi-config/username
33         USERNAME="$RET"
34         db_get xvm-iscsi-config/password
35         PASSWORD="$RET"
36         db_stop
37         
38         if [ -e /etc/invirt/conf.d/iscsi ]; then
39           # invirt.config.run_parts_list excludes backup filenames.
40           mv -f /etc/invirt/conf.d/iscsi /etc/invirt/conf.d/iscsi~
41         fi
42         cat >/etc/invirt/conf.d/iscsi <<EOF
43 iscsi:
44  address: $ADDRESS
45  username: $USERNAME
46  password: $PASSWORD
47 EOF
48         if [ -z "$2" ]; then
49             invoke-rc.d xvm-iscsi-config restart
50             invoke-rc.d open-iscsi restart
51             iscsiadm -m discovery -t st -p $(invirt-getconf iscsi.address):3260
52         elif ! diff /etc/invirt/conf.d/iscsi~ /etc/invirt/conf.d/iscsi >/dev/null; then
53               cat <<EOF
54 xvm-iscsi-config: The configuration has changed.  Restart iscsi:
55   /etc/init.d/xvm-iscsi-config restart
56   /etc/init.d/open-iscsi restart
57   iscsiadm -m discovery -t st -p $(invirt-getconf iscsi.address):3260
58   lvchange -a ln /dev/xenvg && lvchange -a y /dev/xenvg
59 This will leave VMs unable to access their disks, so migrate them first.
60
61 EOF
62         fi
63     ;;
64
65     abort-upgrade|abort-remove|abort-deconfigure)
66     ;;
67
68     *)
69         echo "postinst called with unknown argument \`$1'" >&2
70         exit 1
71     ;;
72 esac
73
74 exit 0