File: postinst

package info (click to toggle)
xmail 1.22-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,840 kB
  • ctags: 3,857
  • sloc: cpp: 33,585; sh: 625; makefile: 102; perl: 56; sql: 31
file content (206 lines) | stat: -rw-r--r-- 7,312 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#! /bin/sh -e
# postinst script for xmail

# Use debconf.
. /usr/share/debconf/confmodule

      
case "$1" in
    configure)

    #this is used to see if the user is running dpkg-reconfigure
    CUR_VER=`cat /var/lib/xmail/curr_ver`

    #these configuration changes don't require xmail to run.

    if [ -z "$2" ]; then
	#we are installing for the first time
        cp /usr/share/doc/xmail/sample/*.tab /etc/xmail
        cp /usr/share/doc/xmail/sample/dnsroots /etc/xmail
        #make links to xmail config files
        ln -s /etc/xmail/*.tab /var/lib/xmail/
        ln -s /etc/xmail/dnsroots /var/lib/xmail
        chmod 711 /var/lib/xmail
        chmod 711 /var/spool/xmail
        chmod 711 /var/spool/xmail/spool
        chmod 770       /var/spool/xmail/spool/local
        chown root:mail /var/spool/xmail/spool/local
        chmod 770       /var/spool/xmail/spool/temp
        chown root:mail /var/spool/xmail/spool/temp
        chmod 700 /var/cache/xmail

    else if dpkg --compare-versions "$2" lt "1.21" ; then
	echo "I: From 1.21 the configuration file handling has changed. Making neccesary changes."
	#adding new configuration files.
	cp --reply=no /usr/share/doc/xmail/sample/*.tab /etc/xmail
	#copying user configuration files
	cp -f /var/lib/xmail/aliasdomain.tab /etc/xmail
        cp -f /var/lib/xmail/aliases.tab /etc/xmail
        cp -f /var/lib/xmail/domains.tab /etc/xmail
        cp -f /var/lib/xmail/filters.in.tab /etc/xmail
        cp -f /var/lib/xmail/filters.out.tab /etc/xmail
        cp -f /var/lib/xmail/mailusers.tab /etc/xmail
        cp -f /var/lib/xmail/spammers.tab /etc/xmail
        cp -f /usr/share/doc/xmail/sample/dnsroots /etc/xmail
	rm -f /var/lib/xmail/*.tab 
	rm -f /var/lib/xmail/dnsroots
        #make links to xmail config files
        ln -s /etc/xmail/*.tab /var/lib/xmail/
	ln -s /etc/xmail/dnsroots /var/lib/xmail
	fi
    fi

     chmod +t /var/spool/xmail/spool/temp
     chmod +t /var/spool/xmail/spool/local
   
    dpkg-statoverride --force --update --add root mail 2555 /var/lib/xmail/sendmail/xsendmail
    ;;

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

    ;;

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

#DEBHELPER#

if [ "$1" = "configure" ]; then 
	
	if [ ! -f /var/run/XMail.pid ]; then
		echo "E: XMail not started. Skipping configuration...."
		exit 0
	fi
	
	if [ -z "$2" ] || [ "$2" = "$CUR_VER" ]; then
            #Make sure xmail starts
	    while [ ! -d /var/lib/xmail/spool/22/22/ ] ; do 
		sleep 1; 
	    done
	    
	    #there is not much i can do here, xmail's startup sucks
	    sleep 2

	    db_get xmail/domainname && domainname="$RET"
            db_get xmail/daemonuser && daemonuser="$RET"
            db_get xmail/daemonpasswd && daemonpasswd="$RET"
            db_get xmail/redirect && redirect="$RET"

	    if [ "$domainname" = "/etc/mailname" ] && [ -f "/etc/mailname" ]; then
		    domainname=`cat /etc/mailname`
	    fi 
	    
            #add control account data
            echo -e "\"debian\"\t\"0100070c040b\"" >> /etc/xmail/ctrlaccounts.tab
	
	    #maybe we are reconfiguring
            if [ -f "/etc/xmail/default_domain" ]; then
    		    old_domain=`cat /etc/xmail/default_domain`
            else
                   old_domain="xmailserver.test"
            fi
		
            echo "I: Adding new domain."	
	    #Let's see if the domain exists or is an alias to another domain
	    EXISTS_D=$(CtrlClnt -s localhost -u debian -p debian domainlist "$domainname")
	    ALIAS_D=$(CtrlClnt -s localhost -u debian -p debian aliasdomainlist "*" "$domainname")

	    if [ -z "$EXISTS_D" ] && [ -z "$ALIAS_D" ]; then
                CtrlClnt -s localhost -u debian -p debian domainadd $domainname
	    fi
	
	    #an alias domain with the same name exists
	    if [ "$ALIAS_D" ]; then
                CtrlClnt -s localhost -u debian -p debian aliasdomaindel $domainname
                CtrlClnt -s localhost -u debian -p debian domainadd $domainname
	    fi
	    
	    echo "I: Adding user."
	    #Let's see if the special user exists
	    EXISTS=$(CtrlClnt -s localhost -u debian -p debian userlist "$domainname" "$daemonuser")
	    ALIAS=$(CtrlClnt -s localhost -u debian -p debian aliaslist "$domainname" "$daemonuser")

	    if [ -z "$ALIAS" ]; then
		    if [ "$EXISTS" ]; then
			CtrlClnt -s localhost -u debian -p debian userpasswd $domainname $daemonuser $daemonpasswd
		    else
        	        CtrlClnt -s localhost -u debian -p debian useradd $domainname $daemonuser $daemonpasswd U
	            fi	
	    fi

	    if [ "$ALIAS" ]; then
       			CtrlClnt -s localhost -u debian -p debian aliasdel $domainname $daemonuser
                        CtrlClnt -s localhost -u debian -p debian useradd $domainname $daemonuser $daemonpasswd U
            fi

	
	    # add aliases
	    for daemon in root postmaster abuse; do
		if [ "$daemonuser" != "$daemon" ]; then
		
                    #delete old aliases if needed
                    EXISTS_U=$(CtrlClnt -s localhost -u debian -p debian userlist "$domainname" "$daemon")
                    ALIAS_U=$(CtrlClnt -s localhost -u debian -p debian aliaslist "$domainname" "$daemon")

		    if [ "$ALIAS_U" ]; then
			    CtrlClnt -s localhost -u debian -p debian aliasdel $domainname $daemon; 
		    fi
		
		    #if there is already an daemon account then don't touch it
		    if [ -z "$EXISTS_U" ]; then
			    CtrlClnt -s localhost -u debian -p debian aliasadd $domainname $daemon $daemonuser;
		    fi	
		fi
	    done
	 
	    # domain alias to `hostname`   
	    EXISTS_H=$(CtrlClnt -s localhost -u debian -p debian domainlist "`hostname`")
            ALIAS_H=$(CtrlClnt -s localhost -u debian -p debian aliasdomainlist "*" "`hostname`")
			
	    if [ -z "$EXISTS_H" ]; then 
		    #make sure we delete the old alias if we have to
		    if [ "$ALIAS_H" ]; then
			CtrlClnt -s localhost -u debian -p debian aliasdomaindel `hostname`
		    fi
		    
		    CtrlClnt -s localhost -u debian -p debian aliasdomainadd $domainname `hostname`
	    else if [ "$domainname" != "`hostname`" ]; then
		    echo "E: A domain called `hostname` already exists. Please remove it and run dpkg-reconfigure."
	         fi
	    fi
	    
	    #clear out debian install ctrl account
	    sed -i '/"debian"\t"0100070c040b"/d' /etc/xmail/ctrlaccounts.tab

	    #add default domain to cmdline
	    echo $domainname > /etc/xmail/default_domain
	
	    #change settings in server.tab and xsendmail
	    sed -i "s/${old_domain}/${domainname}/g" /etc/xmail/server.tab
	    sed -i "s/${old_domain}\|xmailserver.test/${domainname}/g" /var/lib/xmail/sendmail/xsendmail
				
	    #Add redirect settings in case it's not set
	    if [ "$redirect" ]; then
        	mailproc="/var/lib/xmail/domains/${domainname}/${daemonuser}/mailproc.tab"
		if [ -f "$mailproc" ];  then
                	is_redirect=$(cat $mailproc | grep "redirect");
	                if [ -z "$is_redirect" ]; then ADD=1; fi
       		else	ADD=1
	        fi

            	if [ "$ADD" ]; then
                	echo "I: Adding redirect."
                	echo -e "\"redirect\"\t\"${redirect}\"" > /var/lib/xmail/domains/${domainname}/${daemonuser}/mailproc.tab
            	fi
	      fi	

        #restart xmail
        invoke-rc.d xmail restart

	fi
fi
								
exit 0