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