Skip to content

Commit 7630104

Browse files
committed
Use curl in addition to wget and lynx. Exit early when downloading fails.
1 parent 2cd4176 commit 7630104

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

apt-cyg

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ repl() {
149149
}
150150

151151
getfile () {
152-
if wget -h > /dev/null 2>&1
152+
if wget --version > /dev/null 2>&1
153153
then
154154
if ! wget --no-verbose "$@"
155155
then
156-
error "Downloading \"$1\" to \"${of}\"" || return 1
156+
error "wget --no-verbose $*" || return 1
157157
fi
158158
else
159159
of=
@@ -167,17 +167,28 @@ getfile () {
167167
if [ ${#of} -eq 0 ] ; then
168168
of="${1##*/}"
169169
fi
170-
qecho "lynx -source \"$1\""
171-
# Lynx fails when it cannot access the home directory for user
172-
# configuration. Creating the home directory works this around.
173-
if [ ! -d "${HOME}" ]
170+
if curl --version > /dev/null 2>&1
174171
then
175-
mkdir -p "${HOME}"
176-
fi
177-
echo "Downloading \"$1\" ..."
178-
if ! { lynx -source "$1" > "${of}" ; }
179-
then
180-
error "Downloading \"$1\" to \"${of}\"" || return 1
172+
if ! curl -s -o "${of}" "$1"
173+
then
174+
error "curl -s -o \"${of}\" \"$1\"" || return 1
175+
fi
176+
else
177+
if lynx -version > /dev/null 2>&1
178+
then
179+
# Lynx fails when it cannot access the home directory for user
180+
# configuration. Creating the home directory works this around.
181+
if [ ! -d "${HOME}" ]
182+
then
183+
mkdir -p "${HOME}"
184+
fi
185+
if ! { lynx -source "$1" > "${of}" ; }
186+
then
187+
error "lynx -source \"$1\" > \"${of}\"" || return 1
188+
fi
189+
else
190+
error "No wget, lynx or curl found" || return 1
191+
fi
181192
fi
182193
fi
183194
}
@@ -232,7 +243,7 @@ find_workspace () {
232243
get_setup () {
233244
u="${mirrorsource%/}/${arch}/setup.xz"
234245
d="$(cygpath -aw .)"
235-
getfile -N "${u}"
246+
getfile -N "${u}" || return 1
236247
if [ -e setup.xz ] && unxz setup.xz
237248
then
238249
if [ -f setup.ini ]
@@ -497,7 +508,7 @@ download () {
497508
cd "${cacheslash}${mirrordir}/${dn}"
498509
if ! test -e "${bn}" || ! echo "${digest} ${bn}" | "${hash}" --check ${hflags} > /dev/null 2> /dev/null
499510
then
500-
getfile -O "${bn}" "${mirror%/}/${dn}/${bn}"
511+
getfile -O "${bn}" "${mirror%/}/${dn}/${bn}" || return 1
501512
rm -f "${bn}.unpacked"
502513
echo "$digest $bn" | "${hash}" --check ${hflags} > /dev/null 2> /dev/null \
503514
|| error "Hash ${hash} of ${cacheslash}${mirrordir}/${dn}/${bn} did not result in ${digest}" || return 1
@@ -535,7 +546,7 @@ apt_searchall () {
535546
for pkg in $pks
536547
do
537548
qs="text=1&arch=${arch}&grep=${pkg}"
538-
getfile -O "/tmp/matches$$.txt" "http://cygwin.com/cgi-bin2/package-grep.cgi?$qs"
549+
getfile -O "/tmp/matches$$.txt" "http://cygwin.com/cgi-bin2/package-grep.cgi?$qs" || return 1
539550
awk '
540551
NR == 1 {next}
541552
mc[$1]++ {next}

0 commit comments

Comments
 (0)