File: postinst

package info (click to toggle)
linpopup 1.2.0-7
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 600 kB
  • ctags: 251
  • sloc: ansic: 2,885; sh: 250; makefile: 223
file content (113 lines) | stat: -rw-r--r-- 3,583 bytes parent folder | download
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
#!/bin/sh
# linpopup postinst

set -e

SMBCONF=/etc/smb.conf
if [ -e /etc/samba/smb.conf ]; then
	SMBCONF=/etc/samba/smb.conf
fi

addtosmbconf() {
    # uncomment an existing message command definition is one exists;
    # add a line for linpopup.
    if grep 'message command = .*linpopup' $SMBCONF >/dev/null 2>&1
    then	# there's already a linpopup line in there, commented out?
    	perl -i -pe '
	    print ";removed-by-linpopup-install " if /^\s*message command/;
	    s,^;(\s*message command = /bin/sh -c ./usr/bin/linpopup .*),$1,;
            ' $SMBCONF
    else
	# \047 is '
    	perl -i -pe '
	    print ";removed-by-linpopup-install " if /^\s*message command/;
            if (/^\s*\[global\]/) {
               print; print "   message command = /bin/sh -c \047/usr/bin/linpopup \"%f\" \"%m\" %s; rm %s\047 &\n";
            $_="";
            }' $SMBCONF
    fi
}

removefromsmbconf() {
    # undo what addtosmbconf did.
    perl -i -pe 's/^(\s*message command)/;linpopup-removed $1/;
                 s/^;removed-by-linpopup-install //' $SMBCONF
}

case "$1" in
    configure)
        . /usr/share/debconf/confmodule
        if [ -x /usr/bin/update-menus ] ; then update-menus ; fi
#        # fix symlink for /usr/doc
#        if [ "$1" = "configure" ]; then
#            if [ -d /usr/doc -a ! -e /usr/doc/linpopup -a -d /usr/share/doc/linpopup ]; then
#                ln -sf ../share/doc/linpopup /usr/doc/linpopup
#            fi
#        fi

        # as it's a conffile, it gets replaced by an upgrade... replace it back!
        if [ -f /var/lib/linpopup/messages.dat -a ! -s /var/lib/linpopup/messages.dat ]
        then	# exists, is zero size
            if [ -s /var/lib/linpopup/messages.dat.dpkg-old ]
            then
                mv -f /var/lib/linpopup/messages.dat.dpkg-old /var/lib/linpopup/messages.dat
            fi
        fi
        # setting the mode correctly in debian/tmp/ doesn't help...
        chmod 666 /var/lib/linpopup/messages.dat

        # already there?
        if grep -s "^[^;]*message command.*/usr/bin/linpopup" $SMBCONF > /dev/null
        then
            echo "LinPopUp apparently already configured in your $SMBCONF."
            exit 0
        fi

        # already there, but commented out?
        gsearch='^;linpopup-removed .*message command.*/usr/bin/linpopup '
        psearch='^;linpopup-removed (.*message command.*/usr/bin/linpopup )'
        if grep -s "$gsearch" $SMBCONF > /dev/null
        then
            echo -n "
Enabling linpopup line in $SMBCONF..."
            perl -i -pe "s,$psearch,\$1," $SMBCONF
            echo ' done'
            exit 0
        fi

        # not there. Add it?
	db_get linpopup/addtosmbconf # || true
	addtosmbconf=$RET
        db_stop
        if [ "$addtosmbconf" = true ]; then
            addtosmbconf
            echo "LinPopUp added to $SMBCONF.

Note that to actually SEE the messages, you need to start linpopup explicitly.
"
            exit 0
        fi

        # not there, and I wasn't allowed to add it...
        msg=`tempfile --prefix popup`
        echo > $msg "You will need to edit $SMBCONF
to enable receiving popup messages.
See /usr/share/doc/linpopup/examples/smb.conf for an example.
"
        /usr/bin/linpopup "LinPopUp installation" `uname -n` $msg
        rm $msg
        exit 0
        # all done
        ;;
    abort-upgrade)
        ;;
    abort-remove)
        removefromsmbconf
        ;;
    abort-deconfigure)
        removefromsmbconf
        ;;
    *)
        echo "postinst called with unexpected argument '$1', ignored."
        ;;
esac