blob: bd0984271db5ae97f466097049b72248eecdf77c (
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
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
|
#!/bin/sh
#
#
SPAMDDIR=%%SPAMDDIR%%
SPAMDUSER=%%SPAMDUSER%%
SPAMDGROUP=%%SPAMDGROUP%%
SPAMDUID=%%SPAMDUID%%
SPAMDGID=%%SPAMDGID%%
ask() {
local question default answer
question=$1
default=$2
if [ -z "${PACKAGE_BUILDING}" ]; then
read -p "${question} [${default}]? " answer
fi
if [ "x${answer}" = "x" ]; then
answer=${default}
fi
echo ${answer}
}
yesno() {
local default question answer
question=$1
default=$2
while :; do
answer=$(ask "${question}" "${default}")
case "${answer}" in
[Yy][Ee][Ss]|[Yy])
return 0
;;
[Nn][Oo]|[Nn])
return 1
;;
esac
echo "Please answer yes or no."
done
}
check_db() {
DB=/var/db/spamd
if [ -f ${DB} ]; then
OWN=`ls -l ${DB} | awk '{print $3}'`
GRP=`ls -l ${DB} | awk '{print $4}'`
if [ "x${OWN}" != "x${SPAMDUSER}" ]; then
echo "change ${DB} owner to ${SPAMDUSER}"
/usr/sbin/chown ${SPAMDUSER} ${DB}
fi
if [ "x${GRP}" != "x${SPAMDGROUP}" ]; then
echo "change ${DB} group to ${SPAMDGROUP}"
/usr/sbin/chown :${SPAMDGROUP} ${DB}
fi
fi
}
check_service() {
local name number type comment
name=$1
number=$2
type=$3
comment=$4
FILE="/etc/services"
# check
OK=no
HAS_SERVICE=no
COUNT=1
for i in `grep $name $FILE `; do
if [ $COUNT = 1 ] && [ X"$i" = X"$name" ]; then
HAS_SERVICE=yes
elif [ $COUNT = 2 ] && [ $HAS_SERVICE = yes ] && \
[ X"$i" = X"$number/$type" ]; then
OK=yes
break
fi
COUNT=`expr ${COUNT} + 1`
done
# add an entry for SERVICE to /etc/services
if [ $OK = no ]; then
echo "This system has no entry for $name in ${FILE}"
if yesno "Would you like to add it automatically?" y; then
mv ${FILE} ${FILE}.bak
(grep -v $name ${FILE}.bak ; \
echo "$name $number/$type # $comment") \
>> ${FILE}
rm ${FILE}.bak
else
echo "Please add '$name $number/$type' into ${FILE}, and try again."
return 1
fi
fi
return 0
}
# this msg is for users installing not from source,
# - show msg about changed sync protocol
if [ "$2" = "PRE-INSTALL" ]; then
echo "
**** UPGRADE WARNING: SYNC PROTOCOL CHANGED ****
If you have spamd in distributed environment stop
sync between old (4.1.x) and this new version
until every node is updated
read UPDATING in your PORTSDIR
**** UPGRADE WARNING: SYNC PROTOCOL CHANGED ****
"
read -p "Hit ^c now to stop, any key to continue: " -t 5 a || true
echo ""
echo ""
fi
if [ "$2" = "PRE-INSTALL" ]; then
check_dbown=0
if /usr/sbin/pw group show "${SPAMDGROUP}" 2>&1 >/dev/null; then
echo "You already have a \"${SPAMDGROUP}\" group, so I will use it."
check_dbown=1
else
echo "You need a \"${SPAMDGROUP}\" group."
if yesno "Would you like me to create it" "YES"; then
/usr/sbin/pw groupadd "${SPAMDGROUP}" -g "${SPAMDGID}" -h - || \
/usr/sbin/pw groupadd "${SPAMDGROUP}" -h - || exit
echo "Done."
check_dbown=1
else
echo "Please create the \"${SPAMDGROUP}\" group manually and try again."
exit 1
fi
fi
if /usr/sbin/pw user show "${SPAMDUSER}" 2>&1 >/dev/null; then
echo "You already have a \"${SPAMDUSER}\" user, so I will use it."
check_dbown=1
else
echo "You need a \"${SPAMDUSER}\" user."
if yesno "Would you like me to create it" "YES"; then
/usr/sbin/pw useradd "${SPAMDUSER}" -u "${SPAMDUID}" -g "${SPAMDGROUP}" -h - -d "${SPAMDDIR}" \
-s /sbin/nologin -c "spamd pseudo-user" || \
/usr/sbin/pw useradd "${SPAMDUSER}" -g "${SPAMDGROUP}" -h - -d "${SPAMDDIR}" \
-s /sbin/nologin -c "spamd pseudo-user" || exit
check_dbown=1
else
echo "Please create the \"${SPAMDUSER}\" user manually and try again."
exit 1
fi
fi
if [ ${check_dbown} -eq 1 ]; then
check_db
fi
if ! check_service spamd 8025 tcp "spamd(8)"; then
exit 1
fi
if ! check_service spamd-cfg 8026 tcp "spamd(8) configuration"; then
exit 1
fi
if ! check_service spamd-sync 8025 udp "spamd(8) synchronisation"; then
exit 1
fi
fi
|