-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGet_CRTM_Binary_Files.sh
executable file
·83 lines (72 loc) · 2.87 KB
/
Get_CRTM_Binary_Files.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
73
74
75
76
77
78
79
80
81
82
83
#https://bin.ssec.wisc.edu/pub/s4/CRTM/fix_REL-3.1.1.2.tgz (use this for jedi and stand-alone, some files have changed).
# This script is used to manually download the tarball of binary and netcdf coefficient files.
# The same files also download automatically during the cmake step, so you don't have to actually run this manually.
foldername="fix_REL-3.1.1.2"
checksum=58e0a5c698a438a31dc4914fcda39846
filename="${foldername}.tgz"
download_url=https://bin.ssec.wisc.edu/pub/s4/CRTM/$filename
usage() {
echo "Usage: $0 [-h] [-d TARBALL_PATH/filename.tgz]" 1>&2
echo " Call without flags to download the coefficients and extract to a default location." 1>&2
echo " -h: show help" 1>&2
echo " -d: download tarball to specified location without extracting." 1>&2
}
DOWNLOAD_ONLY_PATH=""
while getopts "hd:" opt; do
case "$opt" in
h)
usage
exit 0
;;
d)
DOWNLOAD_ONLY_PATH=$OPTARG
;;
esac
done
if [ -n "${DOWNLOAD_ONLY_PATH}" ]; then
echo "Downloading coefficients ${foldername} to file \"${DOWNLOAD_ONLY_PATH}\" and exiting."
wget --no-verbose $download_url -O "${DOWNLOAD_ONLY_PATH}"
exit 0
fi
# Check if the fix directory already exists, indicating that no download is needed.
if [ -d "fix/" ]; then #fix directory exists
echo "fix/ already exists, doing nothing."
exit 0
fi
# If var $CRTM_BINARY_FILES_TARBALL is set, confirm the file exists and confirm
# the checksum then update the "filename" var.
if [ -n "${CRTM_BINARY_FILES_TARBALL}" ]; then
echo "Found CRTM_BINARY_FILES_TARBALL=${CRTM_BINARY_FILES_TARBALL}"
# Since the tarball var is set, verify the file exists then verify the
# checksum. Failure here will stop and throw an error.
if [ ! -f "$CRTM_BINARY_FILES_TARBALL" ]; then
echo "But no file exists at this path. Fix the file path or unset this variable"
exit 1
fi
local_checksum=$(md5sum $CRTM_BINARY_FILES_TARBALL | cut -d ' ' -f 1)
if [ "${local_checksum}" = "${checksum}" ]; then
filename=$CRTM_BINARY_FILES_TARBALL
else
# Exit with failure.
echo "Var CRTM_BINARY_FILES_TARBALL is set but does not match expected"
echo "checksum of $checksum. Confirm you have the correct tarball and"
echo "try again, or unset this variable"
exit 1
fi
fi
# If the file is not present in the pwd (or otherwise provided by
# CRTM_BINARY_FILES_TARBALL as already verified), download the coefficients file.
if ! test -f "$filename"; then
# Ensure that filename is set to the local directory.
filename="${foldername}.tgz"
echo "Downloading $filename (7 GB tar file)"
wget $download_url -O "${filename}"
fi
# Extract the file to the working directory.
# untar the file and move directory to fix
echo "Extracting ${filename}"
tar -zxvf $filename -C "$PWD"
mkdir -p fix
mv $foldername/fix/* fix/.
rm -rf $foldername
echo "Completed."