freebsd-ports/japanese/ebnetd/pkg-install
Pav Lucistnik 63547225fa - After repocopy from japanese/ndtpd, rename to japanese/ebnetd and update
to version 1.0

PR:		ports/73131
Submitted by:	KIMURA Yasuhiro <yasu@utahime.org>
2004-10-31 21:56:08 +00:00

119 lines
2.3 KiB
Bash

#!/bin/sh -
# an installation script for ebnetd
BATCH=${BATCH:=no}
basename=`basename $0`
ask() {
local question default answer
question=$1
default=$2
if [ -z "${PACKAGE_BUILDING}" -a x${BATCH} = xno ]; then
read -p "${question} (y/n) [${default}]? " answer
[ "${answer}" ] && default=${answer}
fi
echo ${default}
}
yesno() {
local question default
question=$1
default=$2
while :; do
case `ask "${question}" ${default}` in
[Yy]*) return 0;;
[Nn]*) return 1;;
esac
echo "Please answer yes or no."
done
}
check() {
local file entry
file=$1
entry=$2
sed 's/#.*//' ${file} | grep -qw ${entry}
}
checkall() {
local file list item
file=$1
shift
list=$*
for item in $list; do
if check ${file} ${item}; then
:
else
return 1
fi
done
return 0
}
add() {
local oldfile newfile entry port comment
file=$1
entry=$2
port=$3
comment=$4
if check ${file} ${entry}; then
:
elif sed 's/#.*//' ${file} | grep -qw ${port} ; then
oldumask=`umask`
umask 0077
tmpfile=`mktemp -q /tmp/${basename}.XXXXXX`
if [ $? -ne 0 ]; then
echo "Can't create temp file" 1>&2
exit 1
fi
cp $file $tmpfile
trap '' 1 2 15
sed 's,^\([^#]*[ ]'${port}'\),\1 '${entry}, ${tmpfile} > ${file}
trap 1 2 15
rm $tmpfile
umask $oldumask
else
echo "${entry} ${port} #${comment}" >> ${file}
fi
}
[ "$2" = POST-INSTALL ] || exit 0
#
# Add entries for EBNETD (`ebnet' and `ndtp') to /etc/services.
#
file=/etc/services
back=${file}.bak
entrylist='ebnet ndtp'
entry_ebnet=ebnet
port_ebnet=22010/tcp
comment_ebnet='EBNET Protocol'
entry_ndtp=ndtp
port_ndtp=2010/tcp
comment_ndtp='Network Dictionary Transfer Protocol'
echo "************************************************************************"
if checkall ${file} ${entrylist}; then
echo "This system has already all entries for EBNETD in ${file}."
else
echo "This system doesn't have some of entries for EBNETD in ${file}."
if yesno " Would you like to add them automatically?" y; then
cp -f ${file} ${back}
echo " The original file is saved as ${back}."
add ${file} ${entry_ebnet} ${port_ebnet} ${comment_ebnet}
add ${file} ${entry_ndtp} ${port_ndtp} ${comment_ndtp}
fi
fi
echo "************************************************************************"
exit 0