This file is indexed.

postinst is in ejabberd 2.1.11-1ubuntu2.

This file is a maintainer script. It is executed when installing (*inst) or removing (*rm) the package.

The actual contents of the file can be viewed below.

  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
#! /bin/sh
# postinst script for ejabberd
#
# see: dh_installdeb(1)

set -e

CONFIG_SOURCE=/usr/share/ejabberd/ejabberd.cfg
CONFIG_TARGET=/etc/ejabberd/ejabberd.cfg
TEMPFILE=$(mktemp)

. /usr/share/debconf/confmodule

setup_ejabberd()
{
    # Ejabberd config dir may contain sensitive data, so making it unreadable by
    # the world.
    if ! dpkg-statoverride --list /etc/ejabberd >/dev/null; then
	chown root:ejabberd /etc/ejabberd
	chmod 750 /etc/ejabberd
    fi

    # The users database dir /var/lib/ejabberd must be writable by user ejabberd.
    install -d /var/lib/ejabberd
    if ! dpkg-statoverride --list /var/lib/ejabberd >/dev/null; then
	chown -R ejabberd:ejabberd /var/lib/ejabberd
	chmod 700 /var/lib/ejabberd
    fi

    # Ejabberd logs should be readable by users in adm group (see also logrotate script).
    install -d /var/log/ejabberd
    if ! dpkg-statoverride --list /var/log/ejabberd >/dev/null; then
	chown ejabberd:adm /var/log/ejabberd
	chmod 2750 /var/log/ejabberd
	if dpkg --compare-versions "$2" lt '2.1.4'; then
	    find /var/log/ejabberd -type f -name '*.log*' \
		| while read f; do
		    chown ejabberd:adm "$f"
		    chmod 0640 "$f"
	    done
	fi
    fi

    # Making /etc/ejabberd/ejabberd.pem if it does not exist.
    ( cd /etc/ejabberd
    if [ ! -f ejabberd.pem ]
    then
	echo "Generating SSL certificate /etc/ejabberd/ejabberd.pem..."
	EHOSTNAME=$(hostname -s 2>/dev/null || echo localhost)
	EDOMAINNAME=$(hostname -d 2>/dev/null || echo localdomain)
	openssl req -new -x509 -days 365 -nodes -out ejabberd.pem \
		    -keyout ejabberd.pem > /dev/null 2>&1 <<+++
.
.
.
$EDOMAINNAME
$EHOSTNAME
ejabberd
root@$EHOSTNAME.$EDOMAINNAME
+++
    fi
    if ! dpkg-statoverride --list /etc/ejabberd/ejabberd.pem >/dev/null; then
	chown root:ejabberd /etc/ejabberd/ejabberd.pem
	chmod 640 /etc/ejabberd/ejabberd.pem
    fi
    )

    db_get ejabberd/hostname
    HOST="$RET"
    db_get ejabberd/user
    USER="$RET"
    db_get ejabberd/password
    PASSWD="$RET"
    sed -e "s/__USER__/$USER/g ; s/__HOSTNAME__/$HOST/g" $CONFIG_SOURCE >$TEMPFILE
    ucf --three-way --debconf-ok $TEMPFILE $CONFIG_TARGET
    db_stop

    # Making ejabberd config readable only by ejabberd user.
    chown ejabberd:ejabberd $CONFIG_TARGET
    chmod 600 $CONFIG_TARGET
}

register_admin()
{
    if [ -n "$USER" -a -n "$PASSWD" ]; then
	echo -n "Waiting for ejabberd to register admin user"

	if ejabberdctl status >/dev/null || test $? = 1 ; then
	    # Ejabberd is starting ($? = 1) or running ($? = 0) already.
	    cnt=0
	    flag=1
	    while ! ejabberdctl status >/dev/null ; do
		echo -n "."
		cnt=`expr $cnt + 1`
		if [ $cnt -ge 60 ] ; then
		    echo
		    echo "Can't register admin user \"$USER@$HOST\"."
		    echo -n "Ejabberd is starting too long."
		    flag=0
		    break
		fi
		sleep 1
	    done

	    echo
	    if [ $flag -eq 1 ] ; then
		if ! status=$(ejabberdctl register "$USER" "$HOST" "$PASSWD") ; then
		    if echo $status | grep -q "already registered" ; then
			echo "Admin user \"$USER@$HOST\" is already registered. Password IS NOT changed."
		    else
			echo "Can't register admin user \"$USER@$HOST\"."
		    fi
		else
		    echo "Admin user \"$USER@$HOST\" is registered successfully."
		fi
	    fi
	else
	    echo
	    echo "Can't register admin user \"$USER@$HOST\"."
	    echo "Ejabberd server is not started."
	fi
    fi
}

case "$1" in
    configure|reconfigure)
	adduser --quiet --system --shell /bin/sh --group --home /var/lib/ejabberd ejabberd
	setup_ejabberd "$@"
    ;;

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

    ;;

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

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

# Automatically added by dh_installinit
if [ -x "/etc/init.d/ejabberd" ] || [ -e "/etc/init/ejabberd.conf" ]; then
	if [ ! -e "/etc/init/ejabberd.conf" ]; then
		update-rc.d ejabberd defaults >/dev/null
	fi
	invoke-rc.d ejabberd start || exit $?
fi
# End automatically added section


case "$1" in
    configure|reconfigure)
    register_admin
    ;;
esac

exit 0