forked from amiaopensource/ltopers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformatlto
executable file
·92 lines (80 loc) · 2.61 KB
/
formatlto
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
#!/usr/bin/env bash
# formatlto
# Formats an LTO tape with LTFS.
SCRIPTDIR=$(dirname "${0}")
DEPENDENCIES=(mkltfs)
TAPE_SERIAL_REGEX="^[A-Z0-9]{6}$"
BLUE="$(tput setaf 4)" # Blue - For Questions
NC="$(tput sgr0)" # No Color
. "${SCRIPTDIR}/mmfunctions" || { echo "Missing '${SCRIPTDIR}/mmfunctions'. Exiting." ; exit 1 ; }
unset VERSION
if [[ $(dirname $(command -v "${0}")) = "/usr/local/bin" || $(dirname $(command -v "${0}")) = "${HOME}/.linuxbrew/bin" ]] ; then
VERSION=$(TMP=$(brew info ltopers | grep ".*\*$" | grep -Eo "/ltopers/.* \(") ; echo "${TMP:9:(${#TMP}-11)}")
fi
_usage(){
cat <<EOF
$(basename "${0}") ${VERSION}
This script formats an LTO tape with LTFS.
Dependencies: ${DEPENDENCIES[@]}
Usage: $(basename "${0}") [-f] [-c] | -h
-f force formatting
-c use compression
-x use barcode label as tape serial (caveat: this is not standard)
-h display this help
EOF
}
unset MIDDLE_OPTIONS
while getopts ":fcxh" opt ; do
case "${opt}" in
f) FORCE=1 ;;
c) COMPRESS=1 ;;
x) TAPE_SERIAL_REGEX="^[A-Z0-9]{6}(L[5-8]|M8)$" ;;
h) _usage ; exit 0 ;;
*) _report -w "Error: Bad option -${OPTARG}" ; _usage ; exit 1 ;;
esac
done
if [ "${FORCE}" = "1" ] ; then
MIDDLE_OPTIONS+=(-f)
_report -d "Will force formatting."
fi
if [ ! "${COMPRESS}" = "1" ] ; then
MIDDLE_OPTIONS+=(-c)
else
_report -d "Will use compression."
fi
if [ ! "${LTO_ARRAY}" ] ; then
if [[ "$(uname -s)" = "Darwin" ]] ; then
# try to figure out how many LTO decks are attached
LTO_ARRAY=($(system_profiler SPSASDataType | grep "SCSI Target Identifier" | cut -d : -f2 | sort | xargs))
else
#### TO DO: itemize when there are multiple LTO drives in Linux and Windows
LTO_ARRAY=(0)
fi
fi
if [[ "${#LTO_ARRAY[@]}" -gt 1 ]] ; then
PS3="${BLUE}Which LTO deck?${NC} "
eval set "${LTO_ARRAY[@]}"
select DECK in "$@" ; do
break
done
if [ ! "${DECK}" ] ; then
_report -w "Error: You selected an invalid deck."
exit 1
fi
else
#### TO DO: select the correct path to the drive on Linux and Windows
if [[ "$(uname -s)" = "Linux" ]] ; then
#ltfs -o device_list 2> log
#cat log | grep -o "Device Name.*" | grep -Eo "/dev/sg[0-9]|/dev/sg[0-9]{2}"
DECK='/dev/sg13'
else
DECK=0
fi
fi
_report -qn "Enter the tape identifier: "
read TAPE_SERIAL
if [[ ! $(echo "${TAPE_SERIAL}" | grep -E "${TAPE_SERIAL_REGEX}") ]] ; then
_report -w "Error: The tape serial is not valid."
exit 1
fi
mkltfs ${MIDDLE_OPTIONS[@]} --device=${DECK} --tape-serial="${TAPE_SERIAL}" --volume-name="${TAPE_SERIAL}"