File: cfs.postinst

package info (click to toggle)
cfs 1.4.1-17
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 600 kB
  • ctags: 648
  • sloc: ansic: 7,684; sh: 362; makefile: 185
file content (128 lines) | stat: -rw-r--r-- 4,290 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#! /bin/sh
set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see /usr/share/doc/packaging-manual/
#
# quoting from the policy:
#     Any necessary prompting should almost always be confined to the
#     post-installation script, and should be protected with a conditional
#     so that unnecessary prompting doesn't happen if a package's
#     installation fails and the `postinst' is called with `abort-upgrade',
#     `abort-remove' or `abort-deconfigure'.

clear_exports () {
  cat <<EOT

I am about to remove the following lines from /etc/exports:

`sed -ne '/^# Automatically added for use by cfs\$/p;/^.*localhost(rw).*#.*Cryptographic.*\$/p;' /etc/exports`

These entries were created by a previous version of cfs and are
obsolete now when using cfs with the nfs-kernel-server package.
You will still need such an entry when using cfs with the
nfs-user-server package.

EOT
  echo -n 'Remove cfs entries from /etc/exports? (Y/n) '
  read input
  if test "$input" = 'n'; then
    echo '/etc/exports untouched.'
  else
    sed -e '/^# Automatically added for use by cfs\$/d;/^.*localhost(rw).*#.*Cryptographic.*\$/d;' \
      /etc/exports >/etc/exports'{new}' && \
    mv -f /etc/exports'{new}' /etc/exports
    chmod 644 /etc/exports
  fi
}
nfs_restart () {
  test ! -x /etc/init.d/nfs-common || invoke-rc.d nfs-common restart
  test ! -x /etc/init.d/nfs-user-server || invoke-rc.d nfs-user-server restart
  test ! -x /etc/init.d/nfs-kernel-server || invoke-rc.d nfs-kernel-server restart
  sleep 2s
}

case "$1" in
  configure)
    . /etc/cfs.conf
    # upgrading?
    if test -n "$2"; then
      # most-recently-configured-version <= 1.4.1-3?
      if dpkg --compare-versions "$2" le '1.4.1-3'; then
	if grep '^# Automatically added for use by cfs' \
         /etc/exports >/dev/null; then
          clear_exports
	fi
	nfs_restart
      # most-recently-configured-version <= 1.4.1-4?
      elif dpkg --compare-versions "$2" le '1.4.1-4'; then
	# remove obsolete entry in /etc/exports if present
	if grep '^#-- cfs begin' /etc/exports >/dev/null; then
          cat <<EOT

I am about to remove the following lines from /etc/exports:

`sed -ne '/^#-- cfs begin/,/^#-- cfs end/p' /etc/exports`

These entries were created by a previous version of cfs and are
obsolete now when using cfs with the nfs-kernel-server package.
You will still need such an entry when using cfs with the
nfs-user-server package.

EOT
          echo -n 'Remove cfs entries from /etc/exports? (Y/n) '
          read input
          if test "$input" = 'n'; then
            echo '/etc/exports untouched.'
          else
            sed -e '/^#-- cfs begin/,/^#-- cfs end/d' \
	      /etc/exports >/etc/exports'{new}' && \
	    mv -f /etc/exports'{new}' /etc/exports
	    chmod 644 /etc/exports
	    nfs_restart
	  fi
	fi
      # most-recently-configured-version <= 1.4.1-5.1?
      elif dpkg --compare-versions "$2" le '1.4.1-5.1'; then
	# work around bug #136703
	nfs_restart
      fi
    fi
    if test ! -d "$NULL_EXPORT"; then
      echo "Creating directory $NULL_EXPORT"
      mkdir -p -m0 "$NULL_EXPORT"
    fi
    if test ! -d "$CRYPT_ROOT"; then
      echo "Creating directory $CRYPT_ROOT"
      mkdir -p -m755 "$CRYPT_ROOT"
    fi
    if test -z "$NO_CRYPT_SYMLINK"; then
      test ! -h /crypt || rm -f /crypt
      if test ! -e /crypt; then ln -sf "$CRYPT_ROOT" /crypt
      else echo '/crypt exists, leaving it untouched.'; fi
    else
      test ! -h /crypt || rm -f /crypt
    fi
    if test "`ls -A "$CRYPT_ROOT" 2>/dev/null | wc -l`" -ne 0; then
      echo "$CRYPT_ROOT/ is not empty, not restarting cfsd."
    elif test -x /etc/init.d/cfsd; then
      invoke-rc.d cfsd start
    fi
    update-rc.d cfsd defaults 30 20 >/dev/null
    ;;
  abort-upgrade|abort-remove|abort-deconfigure)
    ;;
  *)
    echo "postinst called with unknown argument \`$1'" >&2
    exit 1
    ;;
esac

exit 0