forked from amiaopensource/ltopers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmountlto
executable file
·96 lines (84 loc) · 3.23 KB
/
mountlto
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
#!/usr/bin/env bash
# mountlto
SCRIPTDIR=$(dirname "${0}")
DEPENDENCIES=(ltfs)
MINIMUM_TAPE_SERIAL_LENGTH=2
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ; }
_cleanup_mount_dir(){
if [[ -d "${MOUNT_DIR}" ]] ; then
echo "calling umount"
umount "${MOUNT_DIR}"
rmdir "${MOUNT_DIR}"
fi
}
unset LTO_COUNT
unset LTFS_OPTIONS
_check_for_lto_index_dir
LTO_LOGS="${LTO_INDEX_DIR}"
if [[ "$(uname -s)" = "Darwin" ]] ; then
# try to figure out how many lto decks are attached
LTO_COUNT=$(system_profiler SPSASDataType | grep "SCSI Target Identifier" | wc -l | awk '{print $1}')
else
# TO DO: itemize when there are multiple LTO drives in Linux and Windows
LTO_COUNT=1
#LTO_COUNT="/dev/sg13"
fi
if [[ "${LTO_COUNT}" -eq 0 ]] ; then
_report -w "No LTO decks were found."
echo "No LTO decks were found."
exit 1
fi
[[ ! -d "${LTO_LOGS}" ]] && mkdir -p "${LTO_LOGS}"
_report -d "Checking for ready tapes..."
for i in $(seq 1 "${LTO_COUNT}") ; do
#DECK=$(echo "$i - 1" | bc)
DECK=/dev/sg13
if [ $(command -v ltfs_ldun) ] ; then
ltfs_ldun load ${DECK} 1>/dev/null
fi
LOADTMP=$(_maketemp)
unset TAPE_SERIAL
COUNTER=0
echo -n "Checking for tape barcode"
while [[ "${#TAPE_SERIAL}" -lt "${MINIMUM_TAPE_SERIAL_LENGTH}" ]] && [[ "${COUNTER}" -lt 5 ]]; do
let COUNTER=COUNTER+1
ltfs -f -o devname="${DECK}" 2> "${LOADTMP}"
# find barcode by either "Volser(Barcode)" (Quantum style) or "Tape attribute: Barcode" (IBM style)
TAPE_SERIAL=$(cat "${LOADTMP}" | grep -o "Volser(Barcode).*\|Tape attribute: Barcode.*" | grep -Eo "\b[A-Z0-9]{6}\b|\b[A-Z0-9]{8}\b")
echo -n "."
done
echo
if [[ "${#TAPE_SERIAL}" -lt "${MINIMUM_TAPE_SERIAL_LENGTH}" ]] ; then
if [[ $(cat "${LOADTMP}" | grep -a "Mounting the volume") && ! $(cat "${LOADTMP}" | grep -a "failed to load the tape") ]] ; then
DECKSERIAL=$(cat "${LOADTMP}" | grep -a -o "serial number is [A-Z0-9]*" | awk '{print $4}')
TAPE_SERIAL="${DECKSERIAL}"
else
unset TAPE_SERIAL
fi
fi
if [[ "${#TAPE_SERIAL}" -ge "${MINIMUM_TAPE_SERIAL_LENGTH}" ]] ; then
echo "Deck ${DECK} found with tape ${TAPE_SERIAL}"
if [[ $(uname -s) = "Darwin" ]] ; then
MOUNT_DIR="/Volumes/${TAPE_SERIAL}"
else
MOUNT_DIR="/mnt/${TAPE_SERIAL}"
fi
_report -d "MOUNTING TAPE : THE TAPE WILL MOUNT TO THE ${MOUNT_DIR} FOLDER"
_report -d "MOUNTING TAPE : AFTER MOUNT PRESS CONTROL-C$ TO EJECT"
trap _cleanup_mount_dir SIGHUP SIGINT SIGTERM
mkdir -p "${MOUNT_DIR}"
LTFS_OPTIONS+=(-o eject)
LTFS_OPTIONS+=(-o noatime)
LTFS_OPTIONS+=(-o capture_index)
LTFS_OPTIONS+=(-o devname=${DECK})
#LTFS_OPTIONS+=(-o volname="${TAPE_SERIAL}")
LTFS_OPTIONS+=(-o uid=$(id -u))
ltfs -f -o work_directory="${LTO_LOGS}" ${LTFS_OPTIONS[@]} "${MOUNT_DIR}"
[[ -d "${MOUNT_DIR}" ]] && rmdir "${MOUNT_DIR}"
./renameschemas -u
break
fi
if [[ "$i" -eq "${LTO_COUNT}" ]] ; then
_report -d "Checked ${LTO_COUNT} decks and none appear to have tapes ready to mount."
fi
done