3 # $OpenBSD: chio-changer-openbsd,v 1.1 2012/07/04 12:02:56 ajacoutot Exp $
5 # Bacula interface to chio(1) autoloader for OpenBSD
7 # Adapted from NetBSD pkgsrc and examples/autochangers in bacula source)
8 # by Antoine Jacoutot <ajacoutot@openbsd.org> for OpenBSD.
9 # Tested on an LTO-4 device with 8 slots.
10 # The user Bacula is running as needs rw access to the ch(4) and st(4)
13 # If you set in your Device resource:
14 # Changer Command = "/path/to/chio-changer-openbsd %c %o %S %a %d"
15 # you will have the following input to this script:
16 # chio-changer-openbsd "changer-device" "command" "slot" "archive-device" "drive-index"
19 # So Bacula will always call with all the following arguments, even though
20 # in come cases, not all are used.
22 # N.B. If you change the script, take care to return either
23 # the chio exit code or a 0. If the script exits with a non-zero
24 # exit code, Bacula will assume the request failed.
28 # time (in seconds) for the unit to settle after (un)loading a tape
32 echo "usage: ${0##*/} ctl-device command [slot archive-device drive-index]"
35 # check parameters count
39 if test ${pCount} -lt ${pCountNeed}; then
41 echo "!!! insufficient number of arguments given"
43 if test ${pCount} -lt 2; then
45 echo "!!! mimimum usage is the first two arguments"
49 echo "!!! command expected ${pCountNeed} arguments"
57 # check arguments count for specific actions
83 ${CHIO} -f ${ctl} move drive ${drive} slot $((${slot} - 1))
85 [ ${rtn} -eq 0 ] && sleep ${SLEEP}
90 ${CHIO} -f ${ctl} move slot $((${slot} - 1)) drive ${drive}
92 [ ${rtn} -eq 0 ] && sleep ${SLEEP}
96 ${CHIO} -f ${ctl} status -v slot | \
97 sed -ne 's/^slot *\([0-9]*:\).*FULL.*voltag.*<\(.*\):.*/\1\2/p' | \
98 awk -F: '{ print $1 + 1 ":" $2 }'
103 echo "The listall command is not implemented on OpenBSD."
108 # XXX output the first empty slot if the drive is loaded
109 _slot=`${CHIO} -f ${ctl} status -v | egrep '^slot.*<ACCESS> voltag: <:[0-9]>$' | awk '{ print $2 }' | awk -F: '{ print $1 + 1 }'`
111 _loaded=`${CHIO} -f ${ctl} status -v | egrep "^drive ${drive}: <ACCESS,FULL> voltag: <.*:[0-9]>"`
112 [ -z "${_slot}" -o -z "${_loaded}" ] && _slot=0
113 echo ${_slot} | awk '{ print $1 }'
117 ${CHIO} -f ${ctl} params | awk "/slots/{print \$2}"
122 ${CHIO} -f ${ctl} move slot $((${slot} - 1)) slot ${slotdest}