Imported Upstream version 3.1.0
[debian/amanda] / client-src / patch-system.sh
1 #! @SHELL@
2 #
3 # patch inetd.conf and services
4 # originally by Axel Zinser (fifi@hiss.han.de)
5 #
6
7 prefix="@prefix@"
8 exec_prefix="@exec_prefix@"
9 sbindir="@sbindir@"
10 amlibexecdir="@amlibexecdir@"
11 . "${amlibexecdir}/amanda-sh-lib.sh"
12
13 SERVICE_SUFFIX="@SERVICE_SUFFIX@"
14
15 USER="@CLIENT_LOGIN@"
16
17 INETDCONF=/etc/inetd.conf
18 [ ! -f $INETDCONF ] && INETDCONF=/usr/etc/inetd.conf
19
20 SERVICES=/etc/services
21 [ ! -f $SERVICES ] && SERVICES=/usr/etc/services
22
23 ENABLE_AMANDAD=true
24
25 case `uname -n` in
26 "@DEFAULT_SERVER@" | "@DEFAULT_SERVER@".*)
27     ENABLE_INDEX=true
28     ENABLE_TAPE=true
29     ;;
30 *)
31     ENABLE_INDEX=false
32     ENABLE_TAPE=false
33     ;;
34 esac
35
36 CLIENT_PORT=10080
37 KCLIENT_PORT=10081
38 INDEX_PORT=10082
39 TAPE_PORT=10083
40
41 while [ $# != 0 ]; do
42     case "$1" in
43     --service-suffix=*)
44         SERVICE_SUFFIX=`echo $1 | sed -e 's/[^=]*=//'`;;
45     --version-suffix=*)
46         SUF=`echo $1 | sed -e 's/[^=]*=//'`;;
47     --inetd=*)
48         INETDCONF=`echo $1 | sed -e 's/[^=]*=//' -e 's%^$%/dev/null%'`;;
49     --services=*)
50         SERVICES=`echo $1 | sed -e 's/[^=]*=//' -e 's%^$%/dev/null%'`;;
51     --libexecdir=?*)
52         libexecdir=`echo $1 | sed -e 's/[^=]*=//'`;;
53     --user=?*)
54         USER=`echo $1 | sed -e 's/[^=]*=//'`;;
55     --enable-client)
56         ENABLE_AMANDAD=true;;
57     --disable-client)
58         ENABLE_AMANDAD=false;;
59     --enable-index)
60         ENABLE_INDEX=true;;
61     --disable-index)
62         ENABLE_INDEX=false;;
63     --enable-tape)
64         ENABLE_TAPE=true;;
65     --disable-tape)
66         ENABLE_TAPE=false;;
67     --client-port=?*)
68         CLIENT_PORT=`echo $1 | sed -e 's/[^=]*=//'`;;
69     --kclient-port=?*)
70         KCLIENT_PORT=`echo $1 | sed -e 's/[^=]*=//'`;;
71     --index-port=?*)
72         INDEX_PORT=`echo $1 | sed -e 's/[^=]*=//'`;;
73     --tape-port=?*)
74         TAPE_PORT=`echo $1 | sed -e 's/[^=]*=//'`;;
75     --usage | --help | -h)
76         echo `_ 'call this script with zero or more of the following arguments:'`
77         echo `_ '--version-suffix=<suffix>: deprecated option' ""`
78         echo `_ '--service-suffix=<suffix>: append to service names [%s]' "$SERVICE_SUFFIX"`
79         echo `_ '--libexecdir=<dirname>: where daemons should be looked for [%s]' "$libexecdir"`
80         echo `_ '--inetd=<pathname>: full pathname of inetd.conf [%s]' "$INETDCONF"`
81         echo `_ '--services=<pathname>: full pathname of services [%s]' "$SERVICES"`
82         echo `_ '\tan empty pathname or /dev/null causes that file to be skipped'`
83         echo `_ '--user=<username>: run deamons as this user [%s]' "$USER"`
84         echo `_ '--enable/disable-client: enable/disable amandad [%s]' \`$ENABLE_AMANDAD && echo enabled || echo disabled\``
85         echo `_ '--enable/disable-index: enable/disable index server [%s]' \`$ENABLE_INDEX && echo enabled || echo disabled\``
86         echo `_ '--enable/disable-tape: enable/disable tape server [%s]' \`$ENABLE_TAPE && echo enabled || echo disabled\``
87         echo `_ '--client-port=<num>: amandad port number [%s]' "$CLIENT_PORT"`
88         echo `_ '--kclient-port=<num>: kamandad port number [%s]' "$KCLIENT_PORT"`
89         echo `_ '--index-port=<num>: index server port number [%s]' "$INDEX_PORT"`
90         echo `_ '--tape-port=<num>: tape server port number [%s]' "$TAPE_PORT"`
91         exec true;;
92     *)
93         echo `_ '%s: invalid argument %s.  run with -h for usage\n' "$0" "$1"` >&2
94         exec false;;
95     esac
96     shift
97 done
98
99 if [ "$SERVICES" = /dev/null ]; then :
100 elif [ -f "$SERVICES" ]; then
101         TEMP="$SERVICES.new"
102         {
103             egrep < "$SERVICES" -v "^(amanda|kamanda|amandaidx|amidxtape)${SERVICE_SUFFIX}[     ]"
104             echo "amanda${SERVICE_SUFFIX} ${CLIENT_PORT}/udp"
105             echo "amanda${SERVICE_SUFFIX} ${CLIENT_PORT}/tcp"
106             echo "kamanda${SERVICE_SUFFIX} ${KCLIENT_PORT}/udp"
107             echo "amandaidx${SERVICE_SUFFIX} ${INDEX_PORT}/tcp"
108             echo "amidxtape${SERVICE_SUFFIX} ${TAPE_PORT}/tcp"
109         } > "$TEMP"
110         if diff "$SERVICES" "$TEMP" >/dev/null 2>/dev/null; then
111                 echo `_ '%s is up to date' "$SERVICES"`
112         else
113                 cp "$TEMP" "$SERVICES" || echo `_ 'cannot patch %s' "$SERVICES"`
114         fi
115         rm -f "$TEMP"
116 else
117         echo `_ '%s not found!' "$SERVICES"`
118 fi
119 if [ "$INETDCONF" = /dev/null ]; then :
120 elif [ -f "$INETDCONF" ]; then
121         err=`_ 'warning: %s/amandad%s does not exist' "$libexecdir" ""`
122         $ENABLE_AMANDAD && test ! -f $libexecdir/amandad && echo "$err" >&2
123         err=`_ 'warning: %s/amindexd%s does not exist' "$libexecdir" ""`
124         $ENABLE_INDEX && test ! -f $libexecdir/amindexd && echo "$err" >&2
125         err=`_ 'warning: %s/amidxtaped%s does not exist' "$libexecdir" ""`
126         $ENABLE_TAPE && test ! -f $libexecdir/amidxtaped && echo "$err" >&2
127         TEMP="$INETDCONF.new"
128         {
129             egrep < "$INETDCONF" -v "^(amanda|amandaidx|amidxtape)${SERVICE_SUFFIX}[    ]"
130             $ENABLE_AMANDAD && echo "amanda${SERVICE_SUFFIX}    dgram  udp wait   $USER $libexecdir/amandad    amandad"
131             $ENABLE_INDEX && echo "amandaidx${SERVICE_SUFFIX} stream tcp nowait $USER $libexecdir/amindexd   amindexd"
132             $ENABLE_TAPE && echo "amidxtape${SERVICE_SUFFIX} stream tcp nowait $USER $libexecdir/amidxtaped amidxtaped"
133         } > "$TEMP"
134         if diff "$INETDCONF" "$TEMP" >/dev/null 2>/dev/null; then
135                 fmt="%s is up to date\n"
136                 printf $fmt $INETDCONF
137         else
138                 fmt="cannot patch %s\n"
139                 cp "$TEMP" "$INETDCONF" || printf $fmt $INETDCONF
140         fi
141         rm -f "$TEMP"
142 else
143         fmt="%s not found!\n"
144         printf $fmt $INETDCONF
145 fi