85 lines
1.6 KiB
Text
85 lines
1.6 KiB
Text
|
#!/bin/sh
|
||
|
# an installation script for spamd copied from pf_freebsd
|
||
|
|
||
|
ask() {
|
||
|
local question default answer
|
||
|
|
||
|
question=$1
|
||
|
default=$2
|
||
|
if [ -z "${PACKAGE_BUILDING}" ]; then
|
||
|
read -p "${question} (y/n) [${default}]? " answer
|
||
|
fi
|
||
|
if [ x${answer} = x ]; then
|
||
|
answer=${default}
|
||
|
fi
|
||
|
echo ${answer}
|
||
|
}
|
||
|
|
||
|
yesno() {
|
||
|
local dflt question answer
|
||
|
|
||
|
question=$1
|
||
|
dflt=$2
|
||
|
while :; do
|
||
|
answer=$(ask "${question}" "${dflt}")
|
||
|
case "${answer}" in
|
||
|
[Yy]*) return 0;;
|
||
|
[Nn]*) return 1;;
|
||
|
esac
|
||
|
echo "Please answer yes or no."
|
||
|
done
|
||
|
}
|
||
|
|
||
|
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
|
||
|
}
|
||
|
|
||
|
case $2 in
|
||
|
PRE-INSTALL)
|
||
|
|
||
|
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
|
||
|
;;
|
||
|
|
||
|
esac
|