1
0
mirror of https://git.FreeBSD.org/ports.git synced 2024-12-27 05:10:36 +00:00
freebsd-ports/security/pf/pkg-install
Foxfair Hu 07b27b7bc8 Use a better comment in system passwd file when we create the user 'proxy'
at first time. No necessary to bump PRTREVISION so only force commit in
Makefile.
2003-06-26 18:04:43 +00:00

190 lines
4.1 KiB
Bash

#!/bin/sh
# an installation script for pf_freebsd copied from Wnn6
check_pw()
{
if which -s pw; then
:
else
cat <<EOF
This system looks like a pre-2.2 version of FreeBSD. We see that it
is missing the "pw" utility. We need this utility. Please get and
install it, and try again. You can get the source from:
ftp://ftp.freebsd.org/pub/FreeBSD/FreeBSD-current/src/usr.sbin/pw.tar.gz
EOF
exit 1
fi
}
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
}
check_group() {
local name id
name=$1
id=$2
#check
# We need a command 'pw(8)'
check_pw
if pw groupshow $name -q ; then
return 0
fi
if pw groupadd -g $id -n $name -N -q ; then
echo ""
echo "You need a group '$name' whose ID number is $id"
if yesno "Would you like to create it automatically?" y; then
pw groupadd -g $id -n $name
return 0
fi
fi
echo ""
echo "I was not able to add group 'proxy:*:62:' as pw reported:"
pw groupadd -g $id -n $name -N
echo "Please correct this and try again!"
echo ""
return 1
}
check_user() {
local name id group
name=$1
id=$2
group=$3
# check
id_id=`id -u $id 2> /dev/null`
id_name=`id -u $name 2> /dev/null`
if [ X"$id_name" = X$id ];then
return 0
elif [ X"$id_id" != X ]; then
cat <<EOF
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
This system already has an account whose name is not '$name' and ID
number is $id.
'`id $id`'
For ftp-proxy in this port or package, ID number of '$name' has to be $id.
Please try again after you delete the account.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
EOF
exit 1
elif [ X"$id_name" != X ]; then
cat <<EOF
There is a user '$name' with ID '$id_name'. I'll try to use this account.
EOF
return 0
fi
# add an account '$name' to this system
echo ""
echo "You need an account '$name' whose ID number is $id"
if yesno "Would you like to create it automatically?" y; then
# We need a command 'pw(8)'
check_pw
pw useradd $name -u $id -g $group -h - -d /nonexistent \
-s /nonexistent -c "Packet Filter pseudo-user" || exit
else
echo "Please create it, and try again."
return 1
fi
return 0
}
case $2 in
PRE-INSTALL)
if ! check_service ftp-proxy 8021 tcp "# ftp-proxy service port"; then
exit 1
fi
if [ "`grep ftp-proxy /etc/inetd.conf`" ]; then
echo "Found ftp-proxy entry in inetd.conf ..."
else
echo "Adding sample entry for ftp-proxy to /etc/inetd.conf"
echo "#ftp-proxy stream tcp nowait root ${PKG_PREFIX}/libexec/ftp-proxy ftp-proxy" >> /etc/inetd.conf
fi
if ! check_group proxy 62 ; then
exit 1
fi
groupid=`pw groupshow proxy | awk \
'{ split ($1,var,":"); print var[3] }' `
if ! check_user proxy 62 $groupid; then
exit 1
fi
;;
esac