Hi,
Below is the actual code that I am using FWIW, I don't claim it is
perfect, but it does the job of collecting the WinSCP files of a
release, as well as compiling checksum files from the release's readme file.
The format of the readme file has been constant for quite some time (if
not since it was first devised). The files I want haven't changed either.
Of course it would be easier if they released proper md5sum, sha1sum and
sha256sum files so that I didn't need to construct them.
The download version is within the file name of the shell script. I
could just as easily use the directory name to determine the version
though. Basically I create a directory, copy in or hard link the file
from "last time", adjust it if necessary (name at least) and run it.
The script seems to be quite effective in getting all the files and
confirming they are valid according to the checksums provided in the readme.
I actually haven't used WinSCP itself for a while now as I only use
Windows for very few things these days (aside from when I am working on
other people's machines providing IT support services).
Cheers
A.
$ cat get-files--5.9.5.sh
#!/bin/bash
set -eu
get_files() {
for TARGET_FILE in ${files_to_download}
do
while [ ! -f "${TARGET_FILE}" ]
do
FILE_URL="${URL_BASE}/download/${TARGET_FILE}"
CURL_SAVE_FILE="${TARGET_FILE}--curl-ILs.out"
curl -ILs "${FILE_URL}" | \
tr -d "\r" | \
tee "${CURL_SAVE_FILE}"
FINAL_DOWNLOAD_URL=$(
grep -i ^Location: "${CURL_SAVE_FILE}" | \
tail -1 | \
cut -d" " -f2
)
[[ -z "${FINAL_DOWNLOAD_URL}" ]] && \
FINAL_DOWNLOAD_URL="${FILE_URL}"
echo " -------------------------------------------"
echo " File URL: ${FILE_URL}"
echo "Final Download URL: ${FINAL_DOWNLOAD_URL}"
echo
wget -c "${FINAL_DOWNLOAD_URL}"
echo
done
done
return 0
}
make_checksum_files() {
declare -a files_with_checksums checksums
files_with_checksums=(
$(
grep ^W "${README_FILE}" | tr -d "\r"
)
)
for sum_type in MD5 SHA-1 SHA-256
do
checksums=(
$(
grep "${sum_type}" "${README_FILE}" | \
tr -d "\r" | \
cut -d" " -f4
)
)
case "${sum_type}" in
MD5) OUT_FILE=md5sums ;;
SHA-1) OUT_FILE=sha1sums ;;
SHA-256) OUT_FILE=sha256sums ;;
esac
for ((i=0;i<${#files_with_checksums[@]};i++))
do
printf "%s %s\n" \
"${checksums[${i}]}" \
"${files_with_checksums[${i}]}"
done | tee "${OUT_FILE}"
touch -r "${README_FILE}" "${OUT_FILE}"
echo
done
return 0
}
FN=$0
echo "${FN}"
# Strip prefix up to double dash
VER=${FN#*--}
URL_BASE=https://winscp.net/
# Strip suffix .sh
VER=${VER%%.sh}
files_to_download="
WinSCP-${VER}-Automation.zip
WinSCP-${VER}-Portable.zip
WinSCP-${VER}-ReadMe.txt
WinSCP-${VER}-Setup.exe
WinSCP-${VER}-Source.zip
"
(
echo
echo "WinSCP Website: ${URL_BASE}"
echo
echo "-- download version: $VER"
echo
get_files
echo " -------------------------------------------"
README_FILE=WinSCP-${VER}-ReadMe.txt
[ -f "${README_FILE}" ] || {
echo Missing "${README_FILE}"
exit
}
echo
cat "${README_FILE}"
echo
echo
make_checksum_files
echo
echo
for sum_file in md5sums sha1sums sha256sums
do
[ -f "${sum_file}" ] || {
echo missing "${sum_file}"
exit
}
echo checking "${sum_file}" ....
${sum_file:0:(-1)} -c "${sum_file}"
echo
done
echo
chown -R andrewm:andrewm .
ls -lart
) 2>&1 | tee "$(basename "$0")".out
_______________________________________________
luv-main mailing list
[email protected]
https://lists.luv.asn.au/cgi-bin/mailman/listinfo/luv-main