Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented absolute paths for sources.list and sources.md5 #65

Merged
merged 1 commit into from
Oct 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions download_sources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,43 @@
# This particular script is dual-licensed between BSD 2-Clause
# or GPL3, at your preference.
# n() function taken from otto-pkg's posix-alt.shi lib.

# realpath() function taken from Pindorama/Copacabana version
# of this script.
# USAGE: ./download_sources.sh sources.list sources.md5

MD5CHECK=${MD5CHECK:-YES};
SRCDIR=${SRCDIR:-src}

# Workaround to the # macro in arrays
# which doesn't work properly in bash 4.3 for some reason.
n(){
echo ${@} | tr " " "\n" | wc -l;
}

realpath(){
file_basename=`basename $1`
file_dirname=`dirname $1`
# get the absolute directory name
# example: ./sources.txt -> /usr/src/copacabana-repo/sources.txt
echo "`cd "${file_dirname}"; pwd`/${file_basename}"
}


main(){
PARENTDIR=${PWD};
test ! -e src && mkdir src;
urls=( `cat ${1} | tr "\n" " "` );
sources_file="`realpath ${1}`"
test -n "${2}" && md5sum_file="`realpath ${2}`"
test ! -e "${SRCDIR}" && mkdir "${SRCDIR}";
urls=( `cat ${sources_file} | tr "\n" " "` );
n_urls=`n ${urls[*]}`;
cd src;
cd "${SRCDIR}";
for (( i=0; i < ${n_urls}; i++ )){
printf '%s\n' "Downloading $(basename ${urls[${i}]})";
curl -L ${urls[${i}]} -O;
printf 'Downloading %s\n' "$(basename ${urls[${i}]})";
curl -L "${urls[${i}]}" -O;
}
[ ${MD5CHECK} == 'YES' ] &&
md5sum -c ${PARENTDIR}/${2};
cd ${PARENTDIR};
if `echo ${MD5CHECK} | grep -i '^y' &>/dev/null`; then
md5sum -c "${md5sum_file}" \
&& cd "${OLDPWD}";
fi
return 0;
}

Expand Down