diff --git a/formatlto b/formatlto index d43d465..de4d36c 100755 --- a/formatlto +++ b/formatlto @@ -18,17 +18,17 @@ _usage(){ exit } -unset middleoptions +unset MIDDLE_OPTIONS while getopts ":fh" opt ; do case "${opt}" in - f) middleoptions+="-f";; + f) MIDDLE_OPTIONS+="-f";; h) _usage ;; *) echo "bad option -$OPTARG" ; _usage ;; :) echo "Option -$OPTARG requires an argument" ; exit 1 ;; esac done -if [ ! ${LTO_ARRAY} ] ; then +if [ ! "${LTO_ARRAY}" ] ; then if [[ $(uname -s) == "Darwin" ]] ; then LTO_ARRAY=($(system_profiler SPSASDataType | grep "SCSI Target Identifier" | cut -d : -f2 | xargs)) # try to figure out how many lto decks are attached else @@ -44,28 +44,28 @@ NC="$(tput sgr0)" # No Color if [[ "${#LTO_ARRAY[@]}" -gt 1 ]] ; then PS3="${BLUE}Which LTO deck?${NC} " eval set "${LTO_ARRAY[@]}" - select deck in "$@" + select DECK in "$@" do break done - if [ ! $deck ] ; then + if [ ! "${DECK}" ] ; then echo "${RED}Error, you selected an invalid deck.${NC}" exit 1 fi else - deck=0 + DECK=0 fi printf "${BLUE}Enter the 6 character tape number:${NC} " -read tapeid -if [[ ! $(echo "$tapeid" | grep -E "^[A-Z0-9]{6}$") ]] ; then +read TAPE_ID +if [[ ! $(echo "${TAPE_ID}" | grep -E "^[A-Z0-9]{6}$") ]] ; then echo "${RED}ERROR The tape id must contain exactly 6 capital letters and/or numbers.${NC}" exit 1 fi if [[ $(which ltfs_ldun) ]] ; then - ltfs_ldun load "${deck}" + ltfs_ldun load "${DECK}" fi -mkltfs ${middleoptions[@]} --device=$deck --tape-serial="$tapeid" -c --volume-name="$tapeid" +mkltfs ${MIDDLE_OPTIONS[@]} --device=${DECK} --tape-serial="${TAPE_ID}" -c --volume-name="${TAPE_ID}" if [[ $(which ltfs_ldun) ]] ; then - ltfs_ldun unload "${deck}" + ltfs_ldun unload "${DECK}" fi diff --git a/lto2filemaker b/lto2filemaker index cb88e82..dae5b10 100755 --- a/lto2filemaker +++ b/lto2filemaker @@ -6,25 +6,25 @@ SCRIPTDIR=$(dirname "${0}") LTO_TAPE_TMP=$(_maketemp) -xml sel -t -m "/ltfsindex" -o " --data-urlencode \"creator=" -v creator -o "\" --data-urlencode \"volumeuuid=" -v volumeuuid -o "\" --data-urlencode \"generationnumber=" -v generationnumber -o "\" --data-urlencode \"accesstime=" -v directory[1]/accesstime -o "\" --data-urlencode \"backuptime=" -v directory[1]/backuptime -o "\" --data-urlencode \"changetime=" -v directory[1]/changetime -o "\" --data-urlencode \"creationtime=" -v directory[1]/creationtime -o "\" --data-urlencode \"modifytime=" -v directory[1]/modifytime -o "\" --data-urlencode \"updatetime=" -v updatetime -o "\" --data-urlencode \"readonly=" -v directory[1]/readonly -o "\" --data-urlencode \"allowpolicyupdate=" -v allowpolicyupdate -o "\" --data-urlencode \"highestfileuid=" -v highestfileuid -o "\" --data-urlencode \"name=" -v directory[1]/name -o "\" --data-urlencode \"uniq=" -v directory[1]/modifytime -o "." -v directory[1]/highestfileuid -o "." -v volumeuuid -o "." -v updatetime -o "\"" -n "$1" > "$LTO_TAPE_TMP" +xml sel -t -m "/ltfsindex" -o " --data-urlencode \"creator=" -v creator -o "\" --data-urlencode \"volumeuuid=" -v volumeuuid -o "\" --data-urlencode \"generationnumber=" -v generationnumber -o "\" --data-urlencode \"accesstime=" -v directory[1]/accesstime -o "\" --data-urlencode \"backuptime=" -v directory[1]/backuptime -o "\" --data-urlencode \"changetime=" -v directory[1]/changetime -o "\" --data-urlencode \"creationtime=" -v directory[1]/creationtime -o "\" --data-urlencode \"modifytime=" -v directory[1]/modifytime -o "\" --data-urlencode \"updatetime=" -v updatetime -o "\" --data-urlencode \"readonly=" -v directory[1]/readonly -o "\" --data-urlencode \"allowpolicyupdate=" -v allowpolicyupdate -o "\" --data-urlencode \"highestfileuid=" -v highestfileuid -o "\" --data-urlencode \"name=" -v directory[1]/name -o "\" --data-urlencode \"uniq=" -v directory[1]/modifytime -o "." -v directory[1]/highestfileuid -o "." -v volumeuuid -o "." -v updatetime -o "\"" -n "$1" > "${LTO_TAPE_TMP}" -while read tape ; do - if [[ "$tape" ]] ; then - tapecmd="curl -s -S -G $tape \"http://${FILEMAKER_XML_URL}?-db=${FILEMAKER_DB}&-lay=lto_tapes&-new\" 1>/dev/null" - tapeid=$(echo "$tape" | grep -o "name=[^ ]*" | sed 's/"//g') - echo "Uploading tape metadata for tape $tapeid. Please wait…" - eval "$tapecmd" +while read TAPE ; do + if [[ "${TAPE}" ]] ; then + TAPE_CMD="curl -s -S -G "${TAPE}" \"http://"${FILEMAKER_XML_URL}"?-db="${FILEMAKER_DB}"&-lay=lto_tapes&-new\" 1>/dev/null" + TAPE_ID=$(echo "${TAPE}" | grep -o "name=[^ ]*" | sed 's/"//g') + echo "Uploading tape metadata for tape "${TAPE_ID}". Please wait…" + eval "${TAPE_CMD}" fi -done < "$LTO_TAPE_TMP" -echo "Uploading file metadata for tape $tapeid. Please wait…" +done < "${LTO_TAPE_TMP}" +echo "Uploading file metadata for tape "${TAPE_ID}". Please wait…" LTO_FILE_TMP=$(_maketemp) -xml sel -t -m ".//file" -o " --data-urlencode \"name=" -v name -o "\" --data-urlencode \"length=" -v "length" -o "\" --data-urlencode \"path=" -m "ancestor-or-self::directory" -v "name" -o "/" -b -v name -o "\" --data-urlencode \"readonly=" -v readonly -o "\" --data-urlencode \"creationtime=" -v creationtime -o "\" --data-urlencode \"changetime=" -v changetime -o "\" --data-urlencode \"modifytime=" -v modifytime -o "\" --data-urlencode \"accesstime=" -v accesstime -o "\" --data-urlencode \"backuptime=" -v backuptime -o "\" --data-urlencode \"fileuid=" -v fileuid -o "\" --data-urlencode \"uniq=" -v fileuid -o "." -v modifytime -o "." -v length -o "." -v name -o "\"" -n "$1" > "$LTO_FILE_TMP" +xml sel -t -m ".//file" -o " --data-urlencode \"name=" -v name -o "\" --data-urlencode \"length=" -v "length" -o "\" --data-urlencode \"path=" -m "ancestor-or-self::directory" -v "name" -o "/" -b -v name -o "\" --data-urlencode \"readonly=" -v readonly -o "\" --data-urlencode \"creationtime=" -v creationtime -o "\" --data-urlencode \"changetime=" -v changetime -o "\" --data-urlencode \"modifytime=" -v modifytime -o "\" --data-urlencode \"accesstime=" -v accesstime -o "\" --data-urlencode \"backuptime=" -v backuptime -o "\" --data-urlencode \"fileuid=" -v fileuid -o "\" --data-urlencode \"uniq=" -v fileuid -o "." -v modifytime -o "." -v length -o "." -v name -o "\"" -n "$1" > "${LTO_FILE_TMP}" -while read file ; do - if [[ "$file" ]] ; then - filecmd="curl -s -S -G $file \"http://${FILEMAKER_XML_URL}?-db=${FILEMAKER_DB}&-lay=lto_files&-new\" 1>/dev/null" - eval "$filecmd" +while read FILE ; do + if [[ "${FILE}" ]] ; then + FILE_CMD="curl -s -S -G "${FILE}" \"http://${FILEMAKER_XML_URL}?-db=${FILEMAKER_DB}&-lay=lto_files&-new\" 1>/dev/null" + eval "${FILE_CMD}" fi -done < "$LTO_FILE_TMP" -echo "Done uploading metadata for $tapeid." +done < "${LTO_FILE_TMP}" +echo "Done uploading metadata for ${TAPE_ID}." diff --git a/ltofunctions b/ltofunctions index 7af9235..a6390e5 100644 --- a/ltofunctions +++ b/ltofunctions @@ -14,7 +14,7 @@ elif [ ! "${CONFIG}" = "Y" -a "${REQUIRECONFIG}" = "Y" ] ; then fi _maketemp(){ - mktemp -q "/tmp/$(basename $0).XXXXXX" + mktemp -q "/tmp/$(basename ${0}).XXXXXX" if [ ${?} -ne 0 ]; then echo "${0}: Can't create temp file, exiting..." exit 1 @@ -30,68 +30,68 @@ _report(){ local GREEN="$(tput setaf 2)" # Green - For Declarations local BLUE="$(tput setaf 4)" # Blue - For Questions local NC="$(tput sgr0)" # No Color - local color="" - local startmessage="" - local endmessage="" - local echoopt="" + local COLOR="" + local START_MESSAGE="" + local END_MESSAGE="" + local ECHOOPT="" OPTIND=1 while getopts ":qdwstn" opt; do case "$opt" in - q) color="$BLUE" ;; # question mode, use color blue - d) color="$GREEN" ;; # declaration mode, use color green - w) color="$RED" ; log="Y";; # warning mode, use color red - s) startmessage+=([$(basename $0)] ) ;; # prepend scriptname to the message - t) startmessage+=($(_get_iso8601) '- ' ) ;; # prepend timestamp to the message - n) echoopt="-n" ;; # to avoid line breaks after echo + q) COLOR="${BLUE}" ;; # question mode, use color blue + d) COLOR="${GREEN}" ;; # declaration mode, use color green + w) COLOR="${RED}" ; LOG="Y";; # warning mode, use color red + s) START_MESSAGE+=([$(basename $0)] ) ;; # prepend scriptname to the message + t) START_MESSAGE+=($(_get_iso8601) '- ' ) ;; # prepend timestamp to the message + n) ECHOOPT="-n" ;; # to avoid line breaks after echo esac done - shift $(( ${OPTIND} - 1 )) - message="$1" - echo $echoopt "${color}${startmessage[@]}${message}${NC}" - [ "$log" = "Y" ] && _log -w "$message" + shift $(( "${OPTIND}" - 1 )) + MESSAGE="$1" + echo "${ECHOOPT}" "${COLOR}${START_MESSAGE[@]}${MESSAGE}${NC}" + [ "${LOG}" = "Y" ] && _log -w "${MESSAGE}" } _config_edit(){ - [ -z "$1" -o -z "$2" ] && { _report -w "The config_edit function requires two arguments. Error." ; exit ;}; - sedtemp=$(_maketemp) - sed "s:^$1=[^ ]*:$1=$2:" "$CONFIG_FILE" > "$sedtemp" - cp "$sedtemp" "$CONFIG_FILE" + [ -z "${1}" -o -z "${2}" ] && { _report -w "The config_edit function requires two arguments. Error." ; exit ;}; + SEDTEMP=$(_maketemp) + sed "s:^$1=[^ ]*:$1=$2:" "${CONFIG_FILE}" > "${SEDTEMP}" + cp "${SEDTEMP}" "${CONFIG_FILE}" } _test_config(){ - for directoryvariable in OUTDIR_INGESTFILE OUTDIR_INGESTXDCAM OUTDIR_PAPER AIP_STORAGE PODCASTDELIVER YOUTUBEDELIVER TMPDIR CUSTOM_LOG_DIR LTO_INDEX_DIR ; do - if [ -d "${!directoryvariable}" ] ; then - _report -d "${directoryvariable} is a valid directory" + for DIRECTORYVARIABLE in OUTDIR_INGESTFILE OUTDIR_INGESTXDCAM OUTDIR_PAPER AIP_STORAGE PODCASTDELIVER YOUTUBEDELIVER TMPDIR CUSTOM_LOG_DIR LTO_INDEX_DIR ; do + if [ -d "${!DIRECTORYVARIABLE}" ] ; then + _report -d "${DIRECTORYVARIABLE} is a valid directory" else - _report -w "${directoryvariable} is NOT a valid directory" + _report -w "${DIRECTORYVARIABLE} is NOT a valid directory" fi done } _add_key(){ - key_to_add="$1" - grep -q "^$key_to_add=" "$CONFIG_FILE" ; grep_code="$?" - if [[ ! "${grep_code}" -eq "0" ]] ; then - _report -td "Adding NEW variable $key_to_add to $CONFIG_FILE" - echo "$key_to_add=" >> "$CONFIG_FILE" + KEY_TO_ADD="${1}" + grep -q "^$KEY_TO_ADD=" "${CONFIG_FILE}" ; GREP_CODE="$?" + if [[ ! "${GREP_CODE}" -eq "0" ]] ; then + _report -td "Adding NEW variable $key_to_add to ${CONFIG_FILE}" + echo "$KEY_TO_ADD=" >> "${CONFIG_FILE}" fi } _cleanup(){ - if [ -d "${mountdir}" ] ; then + if [ -d "${MOUNT_DIR}" ] ; then echo calling umount - umount "${mountdir}" - rmdir "${mountdir}" + umount "${MOUNT_DIR}" + rmdir "${MOUNT_DIR}" fi } _version_schema(){ - schemafile="$LTOLOGS/${TAPE_SERIAL}.schema" - if [ -f "${schemafile}" ] ; then + SCHEMA_FILE="$LTO_LOGS/${TAPE_SERIAL}.schema" + if [ -f "${SCHEMA_FILE}" ] ; then echo "${GREEN}Creating a new version of the ltfs schema file.${NC}" - LASTSCHEMA="${schemafile%.*}_$(stat -t '%Y%m%d-%H%M%S' -l "${schemafile}" | awk '{print $6}').schema" - mv -v "${schemafile}" "${LASTSCHEMA}" - echo "${GREEN}$(basename ${0}): schema file is versioned - ${schemafile} -> ${LASTSCHEMA}.${NC}" + LASTSCHEMA="${SCHEMA_FILE%.*}_$(stat -t '%Y%m%d-%H%M%S' -l "${SCHEMA_FILE}" | awk '{print $6}').schema" + mv -v "${SCHEMA_FILE}" "${LASTSCHEMA}" + echo "${GREEN}$(basename ${0}): schema file is versioned - ${SCHEMA_FILE} -> ${LASTSCHEMA}.${NC}" fi } @@ -113,34 +113,34 @@ _pashua_run() { # , as in a doubleclickable application, cwd is / # BTW, all these quotes below are necessary to handle paths # containing spaces. - bundlepath="Pashua.app/Contents/MacOS/Pashua" - mypath=`dirname "$0"` - for searchpath in "$mypath/Pashua" "$mypath/$bundlepath" "./$bundlepath" \ - "/Applications/$bundlepath" "$HOME/Applications/$bundlepath" + BUNDLE_PATH="Pashua.app/Contents/MacOS/Pashua" + MY_PATH=`dirname "${0}"` + for SEARCH_PATH in "$mypath/Pashua" "$mypath/${BUNDLE_PATH}" "./${BUNDLE_PATH}" \ + "/Applications/${BUNDLE_PATH}" "$HOME/Applications/${BUNDLE_PATH}" do - if [ -f "$searchpath" -a -x "$searchpath" ] + if [ -f "${SEARCH_PATH}" -a -x "${SEARCH_PATH}" ] then - pashuapath=$searchpath + PASHUA_PATH="${SEARCH_PATH}" break fi done - if [ ! "$pashuapath" ] ; then + if [ ! "${PASHUA_PATH}" ] ; then echo "Error: Pashua is used to edit but is not found." - if [[ "${pashuainstall}" == "" ]] ; then + if [[ "${PASHUA_INSTALL}" == "" ]] ; then echo "Attempting to run: brew cask install pashua" - if [[ "${pashuainstall}" != "Y" ]] ; then + if [[ "${PASHUA_INSTALL}" != "Y" ]] ; then brew cask install pashua - pashuainstall="Y" + PASHUA_INSTALL="Y" _pashua_run else break 2 fi fi else - encoding="" + ENCODING="" # Get result - result=`"$pashuapath" $encoding $pashua_configfile | sed 's/ /;;;/g'` + result=`"${PASHUAPATH}" ${ENCODING} ${pashua_configfile} | sed 's/ /;;;/g'` # Parse result for line in $result diff --git a/ltoperconfig b/ltoperconfig index 25dbef6..6495ff7 100755 --- a/ltoperconfig +++ b/ltoperconfig @@ -12,33 +12,33 @@ SCRIPTDIR=$(dirname "${0}") REQUIRED_VARIABLES=("FILEMAKER_USER" "FILEMAKER_PASS" "FILEMAKER_DB" "FILEMAKER_XML_URL") # set up configuration file if required -if [[ ! -f "$CONFIG_FILE" ]] ; then - echo "# $(basename $CONFIG_FILE)" > "$CONFIG_FILE" - echo "# This configuration file contains variables used throughout $WHAT_IS_THIS." >> "$CONFIG_FILE" +if [[ ! -f "${CONFIG_FILE}" ]] ; then + echo "# $(basename ${CONFIG_FILE})" > "${CONFIG_FILE}" + echo "# This configuration file contains variables used throughout ${WHAT_IS_THIS}." >> "${CONFIG_FILE}" echo "# Edit the lines below to form KEY=VALUE. Please do not add or remove the existing KEYs. Do not edit CONFIG_FILE_VERSION. Warning this stores a filemaker password in plain text, patches welcome." >> "$CONFIG_FILE" - echo "CONFIG_FILE_VERSION=$CONFIG_VERSION" >> "$CONFIG_FILE" + echo "CONFIG_FILE_VERSION=${CONFIG_VERSION}" >> "${CONFIG_FILE}" fi for KEY in "${REQUIRED_VARIABLES[@]}" ; do - _add_key "$KEY" + _add_key "${KEY}" done _report -d "Table of existing variables:" for KEY in "${REQUIRED_VARIABLES[@]}" ; do - VALUE=$(grep "^$KEY=" "$CONFIG_FILE" | cut -d= -f2) - printf '\t%-40s %-40s\n' "$KEY" "$VALUE" + VALUE=$(grep "^${KEY}=" "${CONFIG_FILE}" | cut -d= -f2) + printf '\t%-40s %-40s\n' "${KEY}" "${VALUE}" done while true ; do - EDITOPTION="Edit config file in nano" + EDIT_OPTION="Edit config file in nano" _report -q "Edit a variable? " PS3="Selection (enter by number)? " - select CONFIG_KEY in "$EDITOPTION" "${REQUIRED_VARIABLES[@]}" "Quit" + select CONFIG_KEY in "${EDIT_OPTION}" "${REQUIRED_VARIABLES[@]}" "Quit" do break done - [ "$CONFIG_KEY" = "Quit" ] && { echo Goodbye. ; exit 1 ;}; - [ "$CONFIG_KEY" = "$EDITOPTION" ] && { nano "$CONFIG_FILE" ; exit 1 ;}; - echo -n "Enter the value for $CONFIG_KEY: " + [ "${CONFIG_KEY}" = "Quit" ] && { echo Goodbye. ; exit 1 ;}; + [ "${CONFIG_KEY}" = "${EDIT_OPTION}" ] && { nano "${CONFIG_FILE}" ; exit 1 ;}; + echo -n "Enter the value for ${CONFIG_KEY}: " read "CONFIG_VALUE" - echo "$CONFIG_KEY is now set to $CONFIG_VALUE" - _config_edit "$CONFIG_KEY" "$CONFIG_VALUE" + echo "${CONFIG_KEY} is now set to ${CONFIG_VALUE}" + _config_edit "${CONFIG_KEY}" "${CONFIG_VALUE}" done diff --git a/mountlto b/mountlto index 4ca2184..a5c95e3 100755 --- a/mountlto +++ b/mountlto @@ -5,10 +5,10 @@ SCRIPTDIR=$(dirname "${0}") . "${SCRIPTDIR}/ltofunctions" || { echo "Missing '${SCRIPTDIR}/ltofunctions'. Exiting." ; exit 1 ;}; -unset ${LTO_ARRAY} -unset ${LTFS_OPTIONS} -LTOLOGS="$HOME/Documents/lto_indexes" -if [[ -z ${LTO_ARRAY} ]] ; then +unset "${LTO_ARRAY}" +unset "${LTFS_OPTIONS}" +LTO_LOGS="${HOME}/Documents/lto_indexes" +if [[ -z "${LTO_ARRAY}" ]] ; then if [[ $(uname -s) == "Darwin" ]] ; then LTO_ARRAY=($(system_profiler SPSASDataType | grep "SCSI Target Identifier" | cut -d : -f2 | xargs)) # try to figure out how many lto decks are attached else @@ -21,23 +21,23 @@ GREEN="$(tput setaf 2)" # Green - For Declarations BLUE="$(tput setaf 4)" # Blue - For Questions NC="$(tput sgr0)" # No Color -[ ! -d "$LTOLOGS" ] && mkdir -p "$LTOLOGS" +[ ! -d "${LTO_LOGS}" ] && mkdir -p "${LTO_LOGS}" if [[ "${#LTO_ARRAY[@]}" -gt 1 ]] ; then PS3="${BLUE}Which LTO deck?${NC} " eval set "${LTO_ARRAY[@]}" - select deck in "$@" + select DECK in "$@" do break done - if [ ! $deck ] ; then + if [ ! ${DECK} ] ; then echo "${RED}Error, you selected an invalid deck.${NC}" exit 1 fi else - deck=0 + DECK=0 fi -deckfile="$LTOLOGS/${deck}_last_used.txt" -touch "$deckfile" +DECKFILE="${LTO_LOGS}/${DECK}_last_used.txt" +touch "${DECKFILE}" printf "${BLUE}Enter the 6 character tape number:${NC} " read TAPE_SERIAL if [[ ! $(echo "$TAPE_SERIAL" | grep -E "^[A-Z0-9]{6}$") ]] ; then @@ -45,25 +45,25 @@ if [[ ! $(echo "$TAPE_SERIAL" | grep -E "^[A-Z0-9]{6}$") ]] ; then exit 1 fi if [[ $(uname -s) == "Darwin" ]] ; then - mountdir="/Volumes/${TAPE_SERIAL}" + MOUNT_DIR="/Volumes/${TAPE_SERIAL}" else - mountdir="/mnt/${TAPE_SERIAL}" + MOUNT_DIR="/mnt/${TAPE_SERIAL}" fi -echo "${GREEN}MOUNTING TAPE : THE TAPE WILL MOUNT TO THE ${RED}${mountdir}${GREEN} FOLDER${NC}" +echo "${GREEN}MOUNTING TAPE : THE TAPE WILL MOUNT TO THE ${RED}${MOUNT_DIR}${GREEN} FOLDER${NC}" echo "${GREEN}MOUNTING TAPE : AFTER MOUNT PRESS ${RED}CONTROL-C${GREEN} TO EJECT${NC}" trap _cleanup SIGHUP SIGINT SIGTERM if [ $(which ltfs_ldun) ] ; then - ltfs_ldun load $deck + ltfs_ldun load ${DECK} fi -mkdir -p "${mountdir}" +mkdir -p "${MOUNT_DIR}" #_version_schema LTFS_OPTIONS+=(-o eject) LTFS_OPTIONS+=(-o capture_index) -LTFS_OPTIONS+=(-o devname=$deck) +LTFS_OPTIONS+=(-o devname=${DECK}) LTFS_OPTIONS+=(-o volname="$TAPE_SERIAL") LTFS_OPTIONS+=(-o uid=$(id -u)) LTFS_OPTIONS+=(-o sync_type=unmount) -ltfs -f -o work_directory="$LTOLOGS" ${LTFS_OPTIONS[@]} "${mountdir}" -[ -d "${mountdir}" ] && rmdir "${mountdir}" +ltfs -f -o work_directory="$LTO_LOGS" ${LTFS_OPTIONS[@]} "${MOUNT_DIR}" +[ -d "${MOUNT_DIR}" ] && rmdir "${MOUNT_DIR}" diff --git a/writelto b/writelto index 3344b8d..54b98fb 100755 --- a/writelto +++ b/writelto @@ -1,10 +1,10 @@ #!/bin/bash # name: writelto # description: writelto writes the contents of a specified directory onto a mounted LTFS-formated LTO tape. -hiddenfiles="" +HIDDEN_FILES="" TAPE_MOUNT_POINT="/Volumes" TAPE_SERIAL_REGEX="[A-Z0-9]\{6\}" -LTOLOGS="$HOME/Documents/lto_indexes" +LTO_LOGS="$HOME/Documents/lto_indexes" SCRIPTDIR=$(dirname "${0}") . "${SCRIPTDIR}/ltofunctions" || { echo "Missing '${SCRIPTDIR}/ltofunctions'. Exiting." ; exit 1 ;}; @@ -24,11 +24,11 @@ while getopts ":t:" opt ; do :) echo "Option -${OPTARG} requires an argument" ; exit 1 ;; esac done -shift $(( ${OPTIND} - 1 )) +shift $(( "${OPTIND}" - 1 )) SOURCE_DIR="${1}" -if [[ ! $(echo "${TAPE_SERIAL}" | grep "$TAPE_SERIAL_REGEX") ]] ; then +if [[ ! $(echo "${TAPE_SERIAL}" | grep "${TAPE_SERIAL_REGEX}") ]] ; then echo "${TAPE_SERIAL}" is not a capital letter followed by a 5 digit number usage exit 1 @@ -44,18 +44,18 @@ _checkdir "${TAPE_PATH}" rsync -rtvO --progress "${SOURCE_DIR}/" "${TAPE_PATH}" RSYNC_ERR_1="$?" -hiddenfiles=$(find "${TAPE_PATH}" -name ".*") -if [[ "${hiddenfiles}" ]] ; then +HIDDEN_FILES=$(find "${TAPE_PATH}" -name ".*") +if [[ "${HIDDEN_FILES}" ]] ; then echo "Removing hidden files from tape." find "${TAPE_PATH}" -name ".*" -delete rsync -rtvO --progress "${SOURCE_DIR}/" "${TAPE_PATH}" RSYNC_ERR_2="$?" fi umount "${TAPE_PATH}" -echo "rsync exited with $RSYNC_ERR_1 on the first pass and $RSYNC_ERR_2 on the second pass." -echo "rsync exited with $RSYNC_ERR_1 on the first pass and $RSYNC_ERR_2 on the second pass." >> "${HOME}/Documents/${TAPE_SERIAL}_writelto.txt" +echo "rsync exited with ${RSYNC_ERR_1} on the first pass and ${RSYNC_ERR_2} on the second pass." +echo "rsync exited with ${RSYNC_ERR_1} on the first pass and ${RSYNC_ERR_2} on the second pass." >> "${HOME}/Documents/${TAPE_SERIAL}_writelto.txt" -schemafile="$LTOLOGS/${TAPE_SERIAL}.schema" +SCHEMA_FILE="$LTO_LOGS/${TAPE_SERIAL}.schema" if [[ -n "${FILEMAKER_XML_URL}" ]] ; then - "${SCRIPTDIR}/lto2filemaker" "${schemafile}" + "${SCRIPTDIR}/lto2filemaker" "${SCHEMA_FILE}" fi