3 ## first, some generic functions
6 # find first free uid/gid in range
7 # find_id passwd 100 999
9 local db first last ids
13 ids=$(getent $db | awk -F: "\$3 >= $first && \$3 <= $last {print \$3}")
14 for i in $(seq $first $last)
16 if ! echo $ids |grep -q $i; then
25 # Update uid for user from reserved system range (0-99) to dynamic system
26 # range (100-999). Optionally update ownerships of given directories.
27 # $0 user [directory ...]
29 check_and_update_ugid() {
30 local user newgid newuid
32 if [ "$(getent passwd $user | awk -F: '$3 >= 100 {print "ok"; exit 0}')" ]; then
36 newgid=$(find_id group 100 999)
37 newuid=$(find_id passwd 100 999)
38 # other directories/files
39 chown -R $newuid:$newgid $* 2>/dev/null || true
40 groupmod -g $newgid $user
41 usermod -u $newuid -g $newgid $user
42 cp_echo "CN: Fixed $user user uid/gid."
46 # wait until process shows some I/O readiness :)
47 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
48 local name IFSOLD num sleep maxtry script user psname pidfile fdname
50 [ -z "$name" ] && return 1
53 read name script user psname pidfile num fdname <<-EOPTS
54 $(echo "$options" | sed 's/ */ /g' | grep ^$name)
60 if [ -n "$pidfile" ]; then
61 pidfile=/var/run/$pidfile
62 findpid="[ -f $pidfile ] && cat $pidfile || true"
64 findpid="pgrep -u $user -f \"$psname\" -P 1 | head -1"
67 # loop the loop the loop
71 sleep $sleep # 1st, give it a chance to run
72 pid=`eval $findpid` # 2nd: find it
73 [ -z "$pid" ] && return 1 # not running at all
74 count=`ls -1 /proc/$pid/fd 2> /dev/null| wc -l` # 3rd: count all it's worth
75 [ "$count" -ge "$num" ] && ls -l /proc/$pid/fd | grep -q $fdname \
76 && return # success -- release
78 [ "0$try" -ge "0$maxtry" ] && return 1 # no luck this time
83 if [ -n "$failed" ]; then
90 check_and_add_alias () {
91 if ! grep -q "^$1:" $ALIASES; then
92 echo "$1: $2" >> $ALIASES
93 # both postfix and sendmail use newaliases
94 newaliases > /dev/null
99 cp_backup_conffile "$1"
100 cp_echo "CN: Current configuration saved in /var/backups/`basename $1`.bak"
103 # if fqdn is name.dom3.dom2.dom1.hr, check if this host is MX for
104 # either dom3.dom2.dom1.hr, dom2.dom1.hr or dom1.hr and dump highest level
109 if ! echo $host | grep -q '\.'; then
112 if [ ! -x /usr/bin/host ]; then
113 cp_echo "CN: no host command... \$mydomain value might be unoptimal."
116 domains=$(hostname -f | awk -F'\.' '
118 for (i=2; i<NF; i++) {
119 for (j=i; j<NF; j++) {
127 mxes=$(host -t mx $d)
128 # handle output of both /usr/bin/host providers
129 mxes=$(echo "$mxes"|\
130 awk '/mail is handled by/ || /MX/ {print $NF}'|sed s/\.$//)
131 if echo "$mxes" |egrep -q "^$host$"; then
137 # XXX TODO implement per paragraph conditional munging some day
142 commented_in_paragraph() {
146 s=`echo $s|sed 's/^/[[:blank:]]*#[[:blank:]]/'`
151 uncommented_in_paragraph() {
155 s=`echo $s|sed 's/^/[[:blank:]]*/'`
161 cat "$postdiff" | sed "s,amavisd\.conf[a-z.-]*\t,$1\t,"
166 ## amavisd-cn specific functions bloated enough to be moved here
169 conf_from_template() {
171 sed -e "s/_CN_DOMAIN_/$domain/g; s/_CN_HOST_/$host/g" $ACONFTMPL >> $ACONF