-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreceive.sh
executable file
·72 lines (40 loc) · 3.93 KB
/
receive.sh
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
#!/bin/bash
echo "s3-xxHash-transfer receive.sh version 2.0.0"
# Lets check to make sure that mhl is properly installed https://stackoverflow.com/a/677212/
command -v mhl >/dev/null 2>&1 || { echo >&2 "This script requires mhl but it does not appear to be properly installed. Aborting. Please see https://mediahashlist.org/mhl-tool/ for more information."; exit 1; }
# Lets check to make sure that aws is properly installed https://stackoverflow.com/a/677212/
command -v aws >/dev/null 2>&1 || { echo >&2 "This script requires aws but it does not appear to be properly installed. Aborting. Please see https://aws.amazon.com/cli/ for more information."; exit 1; }
# Let's have the user specify from where on S3 they'll be downloading
read -e -p "From where on S3 will you be downloading? Enter an S3 URL: " s3url
# Let's have the user specify exactly into which directory on the local system they want the data to go
read -e -p "Into which local directory on your system are you downloading the data? Please enter the absolute path and escape any spaces if necessary: " destinationLocalDirectory
# Now $destinationLocalDirectory will work as the variable for the destination folder on the local system into which the data will go
# Let's now sync from S3 to the local system https://docs.aws.amazon.com/cli/latest/reference/s3/sync.html
aws s3 sync $s3url "$destinationLocalDirectory" &&
# Let's check to make sure that a .mhl file exists in the destination.
cd "$destinationLocalDirectory"
# We're putting that variable inside double quotes, just in case the path has any spaces https://stackoverflow.com/questions/43787476/how-to-add-path-with-space-in-bash-variable/#43793896
# Now let's see if the root level of the folder contains exactly one MHL file https://stackoverflow.com/questions/3856747/check-whether-a-certain-file-type-extension-exists-in-directory/3856879#3856879
count=`ls -1 *.mhl 2>/dev/null | wc -l`
if [ $count = 1 ];
# If it does contain exactly one MHL file, we'll grab the name of that one filename and set it as the $mhlFileName variable. We'll use the `find` command https://stackoverflow.com/a/5927391/
# We're going to use process substitution to set the results of the `find` command to a variable, $mhlFileName https://askubuntu.com/a/1022178/
# We're going to use the `-maxdepth 1` flag in the `find` command to make sure that we're only grabbing the very root level of the folder, since there might be other MHL files down in the depths of subdirectories https://stackoverflow.com/a/3925376/
then
mhlFileName=$(find "$destinationLocalDirectory" -maxdepth 1 -type f -name "*.mhl");
# If there are no MHL files in this directory, we'll throw an error.
elif [ $count = 0 ];
then
echo "ERROR: The local directory does not seem to have an MHL file with which to verify the contents. The data integrity of the contents of this directory cannot be verified."; exit 1;
# If there are more than one MHL files in this directory, we don't know which one to use to verify, so we'll throw an error.
elif [ $count > 1 ];
then
echo "ERROR: There are more than one MHL files in the directory, so this script does not know which MHL to use to verify the contents of the directory. The data integrity of the contents of this directory cannot be verified."; exit 1;
fi
# Let's go ahead and verify the MHL file we found
# We're incuding the variable in double quotes, in case there are spaces in the filename https://stackoverflow.com/questions/43787476/how-to-add-path-with-space-in-bash-variable/#43793896
echo "Verifying the 64-bit xxHash checksums. Please wait..."
mhl verify -f "$mhlFileName" &&
# Whatever the mhl binary displays will just get passed through into the script: https://unix.stackexchange.com/a/266111/
# Once the download has finished and the MHL file has been verified, let's let the user know that the data has been downloaded and verified.
echo "Success! The data from <$s3url> has been downloaded into $destinationLocalDirectory and has been verified."