blob: ad6d5ae3357e115748165c4a465df4fb99da6db9 (
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
#!/bin/sh
#
# $FreeBSD$
#
# ex:ts=4
ask() {
local question default answer
question=$1
default=$2
if [ -z "${PACKAGE_BUILDING}" -a -z "${BATCH}" ]; then
read -p "${question} [${default}]? " answer
fi
echo ${answer:-${default}}
}
yesno() {
local question default answer
question=$1
default=$2
while :; do
answer=$(ask "${question}" "${default}")
case "${answer}" in
[Yy]*) return 0;;
[Nn]*) return 1;;
esac
echo "Please answer yes or no."
done
}
create_account() {
local port user uid group gid gcos home shell
port=$1
user=${2%:*}
uid=${2#*:}
group=${3%:*}
gid=${3#*:}
gcos=$4
home=$5
shell=$6
pw_user_uid=$(pw usershow -n "${user}" 2>/dev/null | cut -d: -f3)
pw_uid_user=$(pw usershow -u "${uid}" 2>/dev/null | cut -d: -f1)
pw_group_gid=$(pw groupshow -n "${group}" 2>/dev/null | cut -d: -f3)
pw_gid_group=$(pw groupshow -g "${gid}" 2>/dev/null | cut -d: -f1)
if [ -z "${pw_group_gid}" -a -z "${pw_gid_group}" ]; then
echo "You need a ${group} group; creating it..."
pw groupadd "${group}" -g "${gid}" || exit
echo "Done."
elif [ "${gid}" = "${pw_group_gid}" -a "${group}" = "${pw_gid_group}" ]; then
echo "Using existing ${group} group."
else
echo "${port} has reserved the groupname '${group}' and gid '${gid}':"
[ -n "${pw_group_gid}" -a "${gid}" != "${pw_group_gid}" ] \
&& echo "ERROR: groupname '${group}' already in use by gid '${pw_group_gid}'"
[ -n "${pw_gid_group}" -a "${group}" != "${pw_gid_group}" ] \
&& echo "ERROR: gid '${gid}' already in use by group '${pw_gid_group}'"
echo "Please resolve these issues and try again:"
echo "Either remove the conflicting group or if you wish to continue using a legacy group override DOVECOT_GID."
exit 1
fi
if [ -z "${pw_user_uid}" -a -z "${pw_uid_user}" ]; then
echo "You need a ${user} user; creating it..."
pw useradd "${user}" -u "${uid}" -g "${group}" -c "${gcos}" -d "${home}" -s "${shell}"
echo "Done."
elif [ "${uid}" = "${pw_user_uid}" -a "${user}" = "${pw_uid_user}" ]; then
echo "Using existing ${user} user."
else
echo "${port} has reserved the username '${user}' and uid '${uid}':"
[ -n "${pw_user_uid}" -a "${uid}" != "${pw_user_uid}" ] \
&& echo "ERROR: username '${user}' already in use by uid '${pw_user_uid}'"
[ -n "${pw_uid_user}" -a "${user}" != "${pw_uid_user}" ] \
&& echo "ERROR: uid '${uid}' already in use by user '${pw_uid_user}'"
echo "Please resolve these issues and try again:"
echo "Either remove the conflicting user or if you wish to continue using a legacy user override DOVECOT_UID."
exit 1
fi
}
case $2 in
PRE-INSTALL)
create_account Dovecot dovecot:${DOVECOT_UID:-143} dovecot:${DOVECOT_GID:-143} "Dovecot User" /var/empty /usr/sbin/nologin
;;
POST-INSTALL)
base=/var/run/dovecot
DIRLIST="${base} ${base}/login"
echo "Fixing ownerships and modes in \"${base}\"."
for directory in ${DIRLIST}; do
if [ ! -d "${directory}" ]; then
mkdir -p ${directory}
echo "Created directory: ${directory}"
fi
done
chown -R root:wheel ${base}
chmod -R 0755 ${base}
chown -R root:dovecot ${base}/login
chmod -R 0750 ${base}/login
;;
esac
|