Tweak japanese/xyaku version 1.4.0_5
[dports.git] / japanese / ebnetd / pkg-install
1 #!/bin/sh -
2 # an installation script for ebnetd
3
4 BATCH=${BATCH:=no}
5 basename=`basename $0`
6
7 ask() {
8     local question default answer
9
10     question=$1
11     default=$2
12
13     if [ -z "${PACKAGE_BUILDING}" -a x${BATCH} = xno ]; then
14         read -p "${question} (y/n) [${default}]? " answer
15         [ "${answer}" ] && default=${answer}
16     fi
17     echo ${default}
18 }
19
20 yesno() {
21     local question default
22
23     question=$1
24     default=$2
25
26     while :; do
27         case `ask "${question}" ${default}` in
28             [Yy]*) return 0;;
29             [Nn]*) return 1;;
30         esac
31         echo "Please answer yes or no."
32     done
33 }
34
35 check() {
36     local file entry
37
38     file=$1
39     entry=$2
40
41     sed 's/#.*//' ${file} | grep -qw ${entry}
42 }
43
44 checkall() {
45     local file list item
46
47     file=$1
48     shift
49     list=$*
50
51     for item in $list; do
52         if check ${file} ${item}; then
53             :
54         else
55             return 1
56         fi
57     done
58     return 0
59 }
60
61 add() {
62     local oldfile newfile entry port comment
63
64     file=$1
65     entry=$2
66     port=$3
67     comment=$4
68
69     if check ${file} ${entry}; then
70         :
71     elif sed 's/#.*//' ${file} | grep -qw ${port} ; then
72         oldumask=`umask`
73         umask 0077
74         tmpfile=`mktemp -q /tmp/${basename}.XXXXXX`
75         if [ $? -ne 0 ]; then
76             echo "Can't create temp file" 1>&2
77             exit 1
78         fi
79         cp $file $tmpfile
80         trap '' 1 2 15
81         sed 's,^\([^#]*[        ]'${port}'\),\1 '${entry}, ${tmpfile} > ${file}
82         trap 1 2 15
83         rm $tmpfile
84         umask $oldumask
85     else
86         echo "${entry}          ${port}   #${comment}" >> ${file}
87     fi
88 }
89
90 [ "$2" = POST-INSTALL ] || exit 0
91
92 #
93 # Add entries for EBNETD (`ebnet' and `ndtp') to /etc/services.
94 #
95 file=/etc/services
96 back=${file}.bak
97 entrylist='ebnet ndtp'
98 entry_ebnet=ebnet
99 port_ebnet=22010/tcp
100 comment_ebnet='EBNET Protocol'
101 entry_ndtp=ndtp
102 port_ndtp=2010/tcp
103 comment_ndtp='Network Dictionary Transfer Protocol'
104
105 echo "************************************************************************"
106 if checkall ${file} ${entrylist}; then
107     echo "This system has already all entries for EBNETD in ${file}."
108 else
109     echo "This system doesn't have some of entries for EBNETD in ${file}."
110     if yesno "  Would you like to add them automatically?" y; then
111         cp -f ${file} ${back}
112         echo "    The original file is saved as ${back}."
113         add ${file} ${entry_ebnet} ${port_ebnet} ${comment_ebnet}
114         add ${file} ${entry_ndtp} ${port_ndtp} ${comment_ndtp}
115     fi
116 fi
117 echo "************************************************************************"
118
119 exit 0