35 lines
705 B
Bash
35 lines
705 B
Bash
|
#!/usr/bin/bash
|
||
|
set -e
|
||
|
|
||
|
# check dependencies
|
||
|
count=0
|
||
|
for dependency in curl tr cut grep sed sort tail; do
|
||
|
if [ ! -x "$(command -v $dependency)" ]; then
|
||
|
echo "$dependency missing"
|
||
|
count=$((count+1))
|
||
|
fi
|
||
|
done
|
||
|
|
||
|
# exit script if any dependencies missing
|
||
|
if [ $count -ne 0 ]; then
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# upstream URL
|
||
|
UPSTREAM_URL="ftp://ftp.gnu.org/gnu/time/"
|
||
|
|
||
|
# options to pass to cURL, including custom user agent
|
||
|
USER_AGENT="time-version-checker/1.0 george@rawlinson.net.nz"
|
||
|
CURL_OPTS=(--ftp-pasv --silent --user-agent "$USER_AGENT")
|
||
|
|
||
|
curl "${CURL_OPTS[@]}" "$UPSTREAM_URL" \
|
||
|
| tr -s ' ' \
|
||
|
| cut -d ' ' -f 9 \
|
||
|
| grep ".tar.gz$" \
|
||
|
| sort -n \
|
||
|
| tail -n 1 \
|
||
|
| sed -e "s/^time-//" -e "s/.tar.gz$//"
|
||
|
|
||
|
exit 0
|
||
|
|