This file is indexed.

/usr/lib/amanda/chg-manual is in amanda-server 1:3.3.9-5.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#!/bin/sh
#
# Exit Status:
# 0 Alles Ok
# 1 Illegal Request
# 2 Fatal Error
#

prefix=/usr
exec_prefix=${prefix}
amlibexecdir=/usr/lib/amanda
. ${amlibexecdir}/chg-lib.sh

#
#	Changer config file (changerfile)
#
#	resend_mail=900		# 15 minutes
#	timeout_mail=604800	# 7 days
#	request="tty"		# Use the tty to ask the user to change tape.
#				# Can't be use by cron
#	request="email"		# Send an email to ask the user to change tape.
#	request="tty_email"	# Use the tty if it exist or send an email.
#			#Default is "tty_email"
#       mtx_binary="/path/to/mtx" # path of 'mtx'; default is value discovered by
#                               # configure
#
#

if [ -d "/var/log/amanda" ]; then
	logfile=/var/log/amanda/changer.debug
else
	logfile=/dev/null
fi

myname=`basename $0`

EGREP='/bin/grep -E'

if ! error=`try_find_mt`; then
    echo <none> $error
    exit 2
fi

ONLINEREGEX="ONLINE|READY|sense[_ ]key[(]0x0[)]|sense key error = 0|^er=0$|, mt_erreg: 0x0|^Current Driver State: at rest$"
REPORTTO=`amgetconf mailto`
MAILER=`amgetconf mailer`
tape=`amgetconf tapedev`

if [ -z "$tape" ]; then
  echo `_ '<none> tapedev not specified in amanda.conf.'`
  exit 2
fi

ORG=`amgetconf ORG`

firstslot=1
lastslot=99
resend_mail=900		# 15 minutes
timeout_mail=604800 	# 7 days
abort_file="chg-manual.abort"
abort_dir=`pwd`

changerfile=`amgetconf changerfile`

conf_match=`expr "$changerfile" : .\*\.conf\$`
if [ $conf_match -ge 6 ]; then
        configfile=$changerfile
        changerfile=`echo $changerfile | sed 's/.conf$//g'`
else
        configfile=$changerfile.conf
fi

cleanfile=$changerfile-clean
accessfile=$changerfile-access
slotfile=$changerfile-slot
[ ! -f $cleanfile ] && echo 0 > $cleanfile
[ ! -f $accessfile ] && echo 0 > $accessfile
[ ! -f $slotfile ] && echo $firstslot > $slotfile
cleancount=`cat $cleanfile`
accesscount=`cat $accessfile`
slot=`cat $slotfile`

# define these functions early so that they can be overridden in changerfile.conf

request_tty() {
	if > /dev/tty; then
		echo "$amdevcheck_message" >> /dev/tty
		# message parsed by ZMC:
		echo `_ 'Insert tape into slot %s and press return' "$1"` > /dev/tty
		echo `_ ' or type "NONE" to abort'` > /dev/tty
		read ANSWER < /dev/tty
		if [ X"$ANSWER" = X"NONE" ]; then
			echo `_ 'Aborting by user request'` > /dev/tty
			answer=`_ '<none> Aborting by user request'`
			echo `_ 'Exit ->'` $answer >> $logfile
			echo $answer
			exit 2
		fi
	else
		answer=`_ '<none> no /dev/tty to ask to change tape'`
		echo `_ 'Exit ->'` $answer >> $logfile
		echo $answer
		exit 2
	fi
}

###
# If $changerfile exists, source it into this script.  One reason is to
# override the request() function above which gets called to request
# that a tape be mounted.  Here is an alternate versions of request()
# that does things more asynchronous:
#
request_email() {
	# Send E-mail about the mount request and wait for the drive
	# to go ready by checking the status once a minute.  Repeat
	# the E-mail once an hour in case it gets lost.
	timeout=0
	gtimeout=$timeout_mail
	rm -f $abort_filename
	while true;do
	    if [ $gtimeout -le 0 ]; then
		answer=`_ '%s %s: timeout waiting for tape online' "$load" "$myname"`
		echo `_ 'Exit ->'` $answer >> $logfile
		echo $answer
		exit 2;
	    fi
	    if [ -f $abort_filename ]; then
		rm -f $abort_filename
		answer=`_ '<none> Aborting by user request'`
		echo `_ 'Exit ->'` $answer >> $logfile
		echo $answer
		exit 2
	    fi
	    if [ $timeout -le 0 ]; then
		msg=`_ '%s\nInsert Amanda tape into slot %s (%s)\nor \`touch %s\` to abort.' "$amdevcheck_message" "$1" "$tape" "$abort_filename"` 
		subject=`_ '%s AMANDA TAPE MOUNT REQUEST FOR SLOT %s' "$ORG" "$1"`
		echo "$msg" | $MAILER -s "$subject" $REPORTTO
		timeout=$resend_mail
	    fi
            echo `_ '     -> status %s' "$tape"` >> $logfile
            if amdevcheck_status $tape; then
		break
	    fi
	    sleep 60
	    timeout=`expr $timeout - 60`
	    gtimeout=`expr $gtimeout - 60`
	done
}

request_tty_email() {
	if > /dev/tty; then
		request_tty "$1"
	else
		request_email "$1"
	fi
}

request() {
	if [ X"$request" = X"tty" ]; then
		request_tty "$1"
	else if [ X"$request" = X"email" ]; then
		request_email "$1"
	else
		request_tty_email "$1"
	fi
	fi
}

# source the changer configuration file (see description, top of file)
if [ -f $configfile ]; then
	. $configfile
fi

# adjust MTX, if necessary
test -n "${mtx_binary}" && MTX="${mtx_binary}"

# check that MAILER is defined
if test -z "$MAILER"; then
    if test x"$request" = x"email" || test x"$request" = x"tty-email"; then
	answer=`_ "<none> %s: Can't send email because MAILER is not defined" "$myname"`
	echo `_ 'Exit ->'` $answer >> $logfile
	echo $answer
	exit 2
    fi
fi

#

eject() { 
	echo `_ '     -> status %s' "$tape"` >> $logfile
        if amdevcheck_status $tape; then
	    echo `_ '     -> offline %s' "$tape"` >> $logfile
            try_eject_device $tape
	    answer="$slot $tape"
	    code=0
	else
	    answer=`_ '<none> %s: %s' "$myname" "$amdevcheck_message"`
	    code=1
	fi
	echo `_ 'Exit ->'` $answer >> $logfile
	echo $answer
	exit $code
}

abort_filename="$abort_dir/$abort_file"

#

reset() {
	echo `_ '     -> status %s' "$tape"` >> $logfile
        if amdevcheck_status $tape; then
		answer="$slot $tape"
	else
		answer="0 $tape $amdevcheck_message"
	fi
	echo `_ 'Exit ->'` $answer >> $logfile
	echo $answer
	exit 0
}

# load #

loadslot() {
	echo `_ '     -> status %s' "$tape"` >> $logfile
        # amdevcheck returns zero if the tape exists.
        amdevcheck_status $tape;
        tape_status=$?

	whichslot=$1
	case $whichslot in
	current)
		load=$slot
		;;
	next|advance)
		load=`expr $slot + 1`
		[ $load -gt $lastslot ] && load=$firstslot
		;;
	prev)
		load=`expr $slot - 1`
		[ $load -lt $firstslot ] && load=$lastslot
		;;
	first)
		load=$firstslot
		;;
	last)
		load=$lastslot
		;;
	[0-9]|[0-9][0-9])
		if [ $1 -lt $firstslot -o $1 -gt $lastslot ]; then
			answer=`_ '<none> %s: slot must be %s .. %s' "$myname" "firstslot" "$lastslot"`
			echo `_ 'Exit ->'` $answer >> $logfile
			echo $answer
			exit 1
		fi
		load=$1
		;;
	*)
		answer=`_ '<none> %s: illegal slot: %s' "$myname" "$1"`
		echo `_ 'Exit ->'` $answer >> $logfile
		echo $answer
		exit 1
		;;
	esac
	#
	if [ $tape_status -eq 0 -a $load = $slot ];then
		# already loaded
		answer="$slot $tape"
		echo `_ 'Exit ->'` $answer >> $logfile
		echo $answer
		exit 0
	fi

	if [ X"$whichslot" = X"current" ]; then
		answer="<none> Current slot not loaded"
		echo `_ 'Exit ->'` $answer>> $logfile
		echo $answer
		exit 1
	fi

	expr $accesscount + 1 > $accessfile

	if [ $tape_status -eq 0 ]; then
		echo `_ "     -> offline %s" "$tape"` >> $logfile
                try_eject_device $tape
		tape_status=1
	fi
	if [ $whichslot = advance ]; then
		tape=/dev/null
	else
		echo `_ '     -> load   %s' "$load"` >> $logfile
		while true; do
			request $load
			echo `_ '     -> status %s' "$tape"` >> $logfile
                        if amdevcheck_status $tape; then
                            break;
                        fi
		done
	fi
	echo $load > $slotfile
	answer="$load $tape"
	echo `_ 'Exit ->'` $answer >> $logfile
	echo $answer
	exit 0
}

#

info() {
	echo `_ '     -> status %s' "$tape"` >> $logfile
        if amdevcheck_status $tape; then
		answer="$slot $lastslot 1"
	else
		answer="0 $lastslot 1"
	fi
	echo `_ 'Exit ->'` $answer >> $logfile
	echo $answer
	exit 0
}

#
# main part
#

echo `gettext "args ->"` "$@" >> $logfile
while [ $# -ge 1 ];do
	case $1 in
	-slot)
		shift
		loadslot $*
		;;
	-info)
		shift
		info
		;;
	-reset)
		shift
		reset
		;;
	-eject)
		shift
		eject
		;;
	*)
		fmt=`gettext "<none> %s: Unknown option %s\n"`
		printf $fmt $myname $1
		exit 2
		;;
	esac
done

exit 0