summaryrefslogtreecommitdiff
path: root/mail/qmail/files/pkg-install.in
blob: c6dd258e00d27a042b16626c75885d894757cf85 (plain) (blame)
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
#!/bin/sh
#
# $FreeBSD$
#

export PATH=/bin:/sbin:/usr/bin:/usr/sbin

PREFIX=${PKG_PREFIX:-%%PREFIX%%}
UID=`id -u`

addGroup() {
	NGROUP=$1
	NGID=$2

	if ! pw groupshow ${NGROUP} >/dev/null 2>&1; then
		if ! pw groupadd ${NGROUP} -g ${NGID} >/dev/null 2>&1; then
			echo "Failed to add group '${NGROUP}' as gid '${NGID}'"
			exit 1
		fi
	fi

	CHECKGID=`pw groupshow ${NGROUP} 2>/dev/null | cut -d: -f3`
	if [ "${CHECKGID}" != "${NGID}" ]; then
		echo "Group '$NGROUP' should have gid '$NGID'"
		exit 1
	fi
}

addUser() {
	NUSER=$1
	NUID=$2
	NGROUP=$3
	NHOME=${4:-${PREFIX}}

	if ! pw usershow ${NUSER} >/dev/null 2>&1; then
		if ! pw useradd ${NUSER} -g ${NGROUP} -d ${NHOME} -s /nonexistent -u ${NUID} >/dev/null 2>&1; then
			echo "Failed to add user '${NUSER}' as uid '${NUID}'"
			exit 1
		fi
	fi

	CHECKUID=`pw usershow ${NUSER} 2>/dev/null | cut -d: -f3`
	if [ "${CHECKUID}" != "${NUID}" ]; then
		echo "User '$NUSER' should have uid '$NUID'"
		exit 1
	fi
}

if [ "$UID" != "0" ]; then
	echo "It is necessary to add missing qmail users/groups at"
	echo "this stage.  Please either add them manually or retry"
	echo "as root."
	exit 1
fi

if [ "$2" = "PRE-INSTALL" ]; then
	addGroup qmail    82
	addGroup qnofiles 81

	addUser alias  81 qnofiles ${PREFIX}/alias
	addUser qmaild 82 qnofiles
	addUser qmaill 83 qnofiles
	addUser qmailp 84 qnofiles
	addUser qmailq 85 qmail
	addUser qmailr 86 qmail
	addUser qmails 87 qmail

elif [ "$2" = "POST-INSTALL" ]; then
	${PREFIX}/configure/install x

	[ -e ${PREFIX}/control/me ] || (cd ${PREFIX}/configure && ./config)

	%%RCDLINK%%ln -s ${PREFIX}/rc %%LOCALBASE%%/etc/rc.d/qmail.sh

	%%RCDLINK%%echo ""
	%%RCDLINK%%echo "A %%LOCALBASE%%/etc/rc.d/qmail.sh symlink was created.  To enable qmail at boot"
	%%RCDLINK%%echo "time you need to copy a script to %%PREFIX%%/rc.  There are some examples at"
	%%RCDLINK%%echo "%%PREFIX/boot"
	%%RCDLINK%%echo ""

	if ! touch ${PREFIX}/alias/.qmail-postmaster \
		   ${PREFIX}/alias/.qmail-root \
		   ${PREFIX}/alias/.qmail-mailer-daemon; then
		echo "Failed to create files :"
		echo "  ${PREFIX}/alias/.qmail-postmaster"
		echo "  ${PREFIX}/alias/.qmail-root"
		echo "  ${PREFIX}/alias/.qmail-mailer-daemon"
		exit 1
	fi
fi

exit 0