File: cfengine3.postinst

package info (click to toggle)
cfengine3 3.15.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 34,456 kB
  • sloc: ansic: 145,932; sh: 8,550; makefile: 1,558; yacc: 1,192; python: 1,056; lex: 758; perl: 211; pascal: 149; awk: 58; xml: 21; sed: 13
file content (96 lines) | stat: -rw-r--r-- 2,872 bytes parent folder | download | duplicates (7)
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
#!/bin/sh
# postinst script for cfengine
#
# see: dh_installdeb(1)

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>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

WORKDIR=/var/lib/cfengine3
INPUTS=$WORKDIR/inputs

set_permissions() {
    # If people have already their own set of files we do not touch the
    # directory permissions, assuming that everything is OK already.
    for dir in ppkeys modules inputs outputs; do
	if [ -d "$WORKDIR/$dir" ] && [ ! "$(ls -A $WORKDIR/$dir)" ]; then
	    chmod 700 $WORKDIR/$dir
	fi
    done
}

make_key() {
    if [ ! -f $WORKDIR/ppkeys/localhost.priv ]; then
        cf-key
    fi
}

move_inputs_if_needed() {
    # Migration function: if the inputdir is pointing to /etc/cfengine3, then
    # create a new input dir and copy the files.
   
    if [ ! -L "$INPUTS" ] || [ ! -d "/etc/cfengine3" ]; then
        return
    fi

    CONFIG_DEST=$(readlink $INPUTS)
    INPUTS_MOVED=0
    if [ "$CONFIG_DEST" = "/etc/cfengine3" ]; then
        rm $INPUTS
        # Permissions will be set by set_permissions() afterwards
        mkdir $INPUTS
        cp -a /etc/cfengine3/* $INPUTS
        INPUTS_MOVED=1
    fi
    
    # Also warn the user by creating a file; this news is also advertised in NEWS.Debian.
    FILE_WARNING="/etc/cfengine3/README_inputs_now_in_var_lib"
    if [ "$INPUTS_MOVED" -eq 1 ] &&  [ ! -f "$FILE_WARNING" ]; then
        echo "Since 3.6.2, the authoritative input files are now in /var/lib/cfengine3/inputs." >> $FILE_WARNING
        echo "Existing input files at the time of the upgrade were copied over to that dir." >> $FILE_WARNING
        echo "Feel free to remove the input files in /etc/cfengine3 if needed." >> $FILE_WARNING
    fi
}

copy_masterfiles() {
    # If the masterfiles directory is empty we are going to copy the shared
    # masterfiles there.
    if [ -d "$WORKDIR/masterfiles" ] && [ ! "$(ls -A $WORKDIR/masterfiles)" ]; then
        cp -a /usr/share/cfengine3/masterfiles/* $WORKDIR/masterfiles
    fi
}

case "$1" in
    configure)
    	move_inputs_if_needed
	copy_masterfiles
        set_permissions
        make_key
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0