-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmart_download.sh
executable file
·51 lines (40 loc) · 1.59 KB
/
smart_download.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
# TODO- Add support for incompletely downloaded files, by veryfing the MD5 hash
echo "LFS is "$LFS
if [ "${LFS}" != "" ]
then
export source_directory=$LFS"/sources/"
else
export source_directory="sources/"
fi
echo "Source directory is "$source_directory
# This function takes the download url for a package as argument
# Then, it extracts the filename from download url, storing it in `name`
# Then, it checks if a file with that name exists in the source_directory
# If exists, then skip
# Else download the file
fn() {
url=$1
name=$(echo ${url} | rev | awk -F '/' '{print $1}' | rev)
if [ -e $source_directory$name ]
then
# This has one problem: There maybe an incomplete file existing
echo $source_directory$name" exists"
else
echo "Downloading "$source_directory$name
wget --continue $url -P $source_directory -q --show-progress || exit 1
fi
# echo $name
}
export -f fn
mkdir -pv $source_directory # create the source directory if doesn't exist yet (wget would automatically create either way)
# This line first extracts all download urls from lfs_packages.txt, then executes `fn` parallely for each download url
# The `sed 's/\r$//'` part removes line feeds, that may be there, if you created the txt file on Windows
awk '/Download: / {print $2}' lfs_packages.txt | sed 's/\r$//' | xargs -P 0 -I {} bash -c 'fn "$@"' _ {}
echo ""
echo "Downloads Completed... Verifying MD5 Hashes"
curr_path=$(pwd)
pushd $LFS/sources
md5sum -c $curr_path"/md5sums.txt"
popd
unset source_directory
unset fn