Skip to content

Commit

Permalink
Use curl in addition to wget and lynx. Exit early when downloading fa…
Browse files Browse the repository at this point in the history
…ils.
  • Loading branch information
ilatypov committed Jun 21, 2017
1 parent 2cd4176 commit 7007489
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions apt-cyg
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ repl() {
}

getfile () {
if wget -h > /dev/null 2>&1
if wget --version > /dev/null 2>&1
then
if ! wget --no-verbose "$@"
then
error "Downloading \"$1\" to \"${of}\"" || return 1
error "wget --no-verbose $*" || return 1
fi
else
of=
Expand All @@ -167,17 +167,28 @@ getfile () {
if [ ${#of} -eq 0 ] ; then
of="${1##*/}"
fi
qecho "lynx -source \"$1\""
# Lynx fails when it cannot access the home directory for user
# configuration. Creating the home directory works this around.
if [ ! -d "${HOME}" ]
if curl --version > /dev/null 2>&1
then
mkdir -p "${HOME}"
fi
echo "Downloading \"$1\" ..."
if ! { lynx -source "$1" > "${of}" ; }
then
error "Downloading \"$1\" to \"${of}\"" || return 1
if ! curl -s -o "${of}" "$1"
then
error "curl -s -o \"${of}\" \"$1\"" || return 1
fi
else
if type lynx > /dev/null 2>&1
then
# Lynx fails when it cannot access the home directory for user
# configuration. Creating the home directory works this around.
if [ ! -d "${HOME}" ]
then
mkdir -p "${HOME}"
fi
if ! { lynx -source "$1" > "${of}" ; }
then
error "lynx -source \"$1\" > \"${of}\"" || return 1
fi
else
error "No wget, lynx or curl found" || return 1
fi
fi
fi
}
Expand Down Expand Up @@ -232,7 +243,7 @@ find_workspace () {
get_setup () {
u="${mirrorsource%/}/${arch}/setup.xz"
d="$(cygpath -aw .)"
getfile -N "${u}"
getfile -N "${u}" || return 1
if [ -e setup.xz ] && unxz setup.xz
then
if [ -f setup.ini ]
Expand Down Expand Up @@ -497,7 +508,7 @@ download () {
cd "${cacheslash}${mirrordir}/${dn}"
if ! test -e "${bn}" || ! echo "${digest} ${bn}" | "${hash}" --check ${hflags} > /dev/null 2> /dev/null
then
getfile -O "${bn}" "${mirror%/}/${dn}/${bn}"
getfile -O "${bn}" "${mirror%/}/${dn}/${bn}" || return 1
rm -f "${bn}.unpacked"
echo "$digest $bn" | "${hash}" --check ${hflags} > /dev/null 2> /dev/null \
|| error "Hash ${hash} of ${cacheslash}${mirrordir}/${dn}/${bn} did not result in ${digest}" || return 1
Expand Down Expand Up @@ -535,7 +546,7 @@ apt_searchall () {
for pkg in $pks
do
qs="text=1&arch=${arch}&grep=${pkg}"
getfile -O "/tmp/matches$$.txt" "http://cygwin.com/cgi-bin2/package-grep.cgi?$qs"
getfile -O "/tmp/matches$$.txt" "http://cygwin.com/cgi-bin2/package-grep.cgi?$qs" || return 1
awk '
NR == 1 {next}
mc[$1]++ {next}
Expand Down

0 comments on commit 7007489

Please sign in to comment.