aboutsummaryrefslogtreecommitdiff
path: root/japanese/ebnetd/pkg-install
blob: 747d2672696cb011d10d562e506db1fbabb15496 (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
#!/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