This file is indexed.

/usr/share/doc/bacula-common/examples/autochangers/rc-chio-changer is in bacula-common 7.0.5+dfsg-4build1.

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

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
#!/bin/sh
#
# Bacula interface to chio autoloader
# (by Rudolf Cejka <cejkar@fit.vutbr.cz>)
#
# $Id$
#
# If you set in your Device resource
#   Changer Command = "path-to-this-script/chio-changer %c %o %S %a %d"
# you will have the following input to this script:
#   chio-changer "changer-device" "command" "slot" "tape-device" "drive-index"
#                       $1           $2       $3         $4            $5
# for example (on a FreeBSD system):
#   chio-changer /dev/ch0 load 1 /dev/nsa0 0
#
# If you change the script, take care to return either the chio exit
# code or a 0. If the script exits with a non-zero exit code, Bacula
# will assume the request failed.
#

# Uncomment the following line, if you need to eject a tape before moving
# it from the drive.
#OFFLINE=yes

# Uncomment the following line, if you need to wait for some time
# (in seconds) after (un)loading a tape.
#SLEEP=10

# Uncomment the following line, if you do not have a changer with volume
# reader.
#FAKE_BARCODES=/usr/local/etc/bacula-barcodes

PROGNAME=`basename $0`

usage()
{
  cat <<EOF
Usage: ${PROGNAME} <changer-device> <cmd> [slot] [tape-device] [drive-index]

Commands (<cmd>):
  unload          Unloads a tape into the slot from where it was loaded.
  load <slot>     Loads a tape from the slot <slot> (1-based).
  list            Lists full storage slots.
  loaded          Gives slot from where the tape was loaded (0 = empty drive).
  slots           Gives number of available slots.

Example:
  ${PROGNAME} /dev/ch0 load 1        Loads a tape from first slot 1.

EOF
}

# Default settings
CHANGER=/dev/ch0
TAPE=/dev/nsa0
DRIVE=0

CHIO=/bin/chio
MT=/usr/bin/mt

if [ $# -lt 2 ]; then
  usage
  exit 1
fi

if [ -n "$1" ]; then
  CHANGER=$1;
fi
COMMAND=$2
SLOT=$3
if [ -n "$4" ]; then
  TAPE=$4
fi
if [ -n "$5" ]; then
  DRIVE=$5
fi

case ${COMMAND} in
unload)
  if [ "${OFFLINE}" = yes ]; then
    ${MT} -f ${TAPE} offline
  fi
  if [ -n "${SLEEP}" ]; then
    sleep ${SLEEP}
  fi
  if [ -z "${SLOT}" ]; then
    ${CHIO} -f ${CHANGER} return drive ${DRIVE}
  else
    ${CHIO} -f ${CHANGER} move drive ${DRIVE} slot $((${SLOT} - 1))
  fi
  if [ $? -ne 0 ]; then
    # Try to unload the cartridge to the first free slot.
    FREE=`${CHIO} -f ${CHANGER} status slot | \
      sed -ne '/FULL/d;s/^slot *\([0-9]*\):.*/\1/p' | head -1`
    if [ -n "${FREE}" ]; then
      ${CHIO} -f ${CHANGER} move drive ${DRIVE} slot ${FREE}
    else
      exit 1
    fi
  fi
  ;;
load)
  ${CHIO} -f ${CHANGER} move slot $((${SLOT} - 1)) drive ${DRIVE}
  RET=$?
  if [ -n "${SLEEP}" ]; then
    sleep ${SLEEP}
  fi
  exit ${RET}
  ;;
list)
  if [ -z "${FAKE_BARCODES}" ]; then
    ${CHIO} -f ${CHANGER} status -v slot | \
      sed -ne 's/^slot *\([0-9]*:\).*FULL.*voltag.*<\(.*\):.*/\1\2/p' | \
      awk -F: '{print $1 + 1 ":" $2 }'
  else
    if [ -f "${FAKE_BARCODES}" ]; then
      grep -v -e "^#" -e "^$" < ${FAKE_BARCODES}
    else
      echo "${PROGNAME}: Barcode file ${FAKE_BARCODES} is missing"
      exit 1
    fi
  fi
  ;;
loaded)
  FREE=`${CHIO} -f ${CHANGER} status slot | \
    sed -ne '/FULL/d;s/^slot *\([0-9]*\):.*/\1/p' | \
    awk 'BEGIN { n = 0 } { n = $1 + 1 ; exit } END { print n }'`
  ${CHIO} -f ${CHANGER} status -S drive | \
    sed -ne 's/^drive *'${DRIVE}':.*FULL.*source.*<[^0-9]*\([0-9]*\)>.*/\1/p' \
    | awk 'BEGIN { n = 0 } { n = ($1 == "") ? '${FREE}' : $1 + 1 } \
      END { print n }'
  ;;
slots)
  ${CHIO} -f ${CHANGER} status | grep -c "^slot "
  ;;
*)
  usage
  ;;
esac