File: cfengine2.postinst

package info (click to toggle)
cfengine2 2.1.14-1sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,688 kB
  • ctags: 12
  • sloc: sh: 290; makefile: 113; perl: 29
file content (102 lines) | stat: -rw-r--r-- 2,787 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
#! /bin/sh

# 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/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'.

set -e

INPUTS=/var/lib/cfengine2/inputs

. /usr/share/debconf/confmodule
db_version 2.0

make_key () {
    if [ ! -f /var/lib/cfengine2/ppkeys/localhost.priv ]; then
	cfkey
    fi
}

sed_script_config_daemons () {
    # Spits out sed commands to re-configure /etc/default/cfengine2
    ALL_DAEMONS="CFSERVD CFEXECD CFENVD"
    for DAEMON in $ALL_DAEMONS; do
	LC_DAEMON=$(echo $DAEMON | tr 'A-Z' 'a-z')
	db_get "cfengine2/run_${LC_DAEMON}"
	case "$RET" in
	    true|1) DO_IT=1;;
	    false|0) DO_IT=0;;
	    *) echo "Wacky RET: '$RET'" >&2 ; return 1;;
	esac
	echo -n "s/^RUN_$DAEMON=[01]/RUN_$DAEMON=${DO_IT}/;"
    done
}

config_daemons() {
    CUR=/etc/default/cfengine2
    test ! -f "$CUR" && cp -p /usr/share/cfengine2/default "$CUR"

    NEW=$(mktemp "${CUR}.XXXXXXXXX")
    cp -a -f "$CUR" "$NEW"
    sed `sed_script_config_daemons` < "$CUR" > "$NEW"
    mv -f "$NEW" "$CUR"
}


no_files_in_common() {
    # returns 0 if no files in $1 exist in $2;
    # 1 if they intersect; 2 if symlink
    for d in "$@"; do
	test -L "$d" && return 2
	test -d "$d" || return 0
    done

    (cd "$1" && find . -mindepth 1 -print0 2>/dev/null) |\
	(cd "$2" && perl -ne \
	'BEGIN {$/="\0"}; chomp; if (-e) {exit 1;}')
    return $?
}

move_inputs_to_etc() {
    test -d "$INPUTS" && return
    if no_files_in_common "$INPUTS" /etc/cfengine; then
	(cd "$INPUTS" && tar cf - .) | (cd /etc/cfengine && tar xpf -) && \
	    { rm -rf "$INPUTS" && ln -s /etc/cfengine "$INPUTS"; }
    else
	cat <<-EOF
	WARNING: Could not move files from $INPUTS to /etc/cfengine
	Please do this manually and then run:
	\$ ln -s /etc/cfengine $INPUTS
EOF
    fi
}

case "$1" in
    configure|reconfigure)
	make_key
	config_daemons
	rm -f /var/lib/cfengine2/av.db
	test -L "$INPUTS" || move_inputs_to_etc
	;;
    abort-upgrade|abort-remove|abort-deconfigure)
	;;
    *)
	echo "postinst called with unknown argument \`$1'" >&2
        exit 0
	;;
esac

#DEBHELPER#