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