-
Notifications
You must be signed in to change notification settings - Fork 1
/
prepareLTO
executable file
·58 lines (47 loc) · 1.98 KB
/
prepareLTO
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
#!/usr/bin/env bash
# a script to create a manifest of contents on an LTO tape, copy it to the tape and then copy it to a specified adtional folder
### CONSTANTS
biwhite=$(tput bold)$(tput setaf 7)
bired=$(tput bold)$(tput setaf 1)
color_off=$(tput sgr0)
today=$(date +"%Y%m%d")
script_path=${0%/*}
# script_path will be the directory path of {0} which is the script being called
. "$script_path/nmaahcmmfunctions"
# You can't directly call a function in another shell script.
# You can move your function definitions into a separate file and then load them into your script using the . command, like this:
# . /path/to/functions.sh
# This will interpret functions.sh as if it's content were actually present in your file at this point.
# This is a common mechanism for implementing shared libraries of shell functions.
[[ -f "$script_path/nmaahcmmfunctions" ]] || { echo "Missing '$script_path/nmaahcmmfunctions'. Exiting." ; exit 1 ;};
# will check to see that that nmaahcmmfunctions exists and if it doesn't (left side of || exits non-zero) then it will execute the right side of ||
### FUNCTIONS
prepareLTO ()
{
drive="$1"
target="${drive%/}" #strip the trailing /, if any
target="${target##*/}" #name $target as the basename of $drive
#for "$drive" ; do
if [ -d "$drive" ] ; then
#delete hidden files from $drive
echo
printf "%sFinding hidden files on %s and deleting.%s\n" "$biwhite" "$target" "$color_off"
removehidden "$drive"
else
printf "%s%s is not a valid input. exiting%s" "$drive" "$bired" "$color_off"
exit
fi
checksumtxt="$drive"/"$target"_checksums.txt
touch "$checksumtxt"
echo
printf "%sConcatenating and hashing all .md5 in %s into %s and sorting.%s" "$biwhite" "$target" "${checksumtxt##*/}" "$color_off"
find "$drive" -name "*.md5" -exec cat {} >> "$checksumtxt" \;
find "$drive" -name "*.md5" -exec md5deep -bre {} >> "$checksumtxt" \;
sortk2 "$checksumtxt"
echo
cowsay "Done. $target is ready to write to LTO."
#done
}
#call the function(s)
prepareLTO "$@"
exit "$?"