2025-10-30 23:54:40 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
|
|
# check if a command is available
|
|
|
|
|
has_command() { # $command
|
|
|
|
|
command -v "${1}" 1>/dev/null 2>/dev/null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
needs_commands() { # $status $cmd1 $cmd2 ...
|
|
|
|
|
_nc_status="${1}"
|
|
|
|
|
shift 1
|
|
|
|
|
|
|
|
|
|
for _nc_cmd in "${@}"; do
|
|
|
|
|
if ! has_command "${_nc_cmd}"; then
|
|
|
|
|
echo "Command '${_nc_cmd}' not available!" >&2
|
|
|
|
|
exit "${_nc_status}"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
}
|
2025-11-11 23:50:05 +00:00
|
|
|
|
|
|
|
|
download_gui() { # $uri $file $sha256
|
|
|
|
|
needs_commands "curl" "zenity" "sha256sum" || return 1
|
|
|
|
|
echo "Downloading '${1}' to '${2}'"
|
|
|
|
|
|
|
|
|
|
curl --show-error --fail --location \
|
|
|
|
|
--output "${2}" \
|
|
|
|
|
"${1}" &
|
|
|
|
|
_dg_curlpid=$!
|
|
|
|
|
|
|
|
|
|
yes | zenity \
|
|
|
|
|
--progress --pulsate --auto-close \
|
|
|
|
|
--title="Downloading" \
|
|
|
|
|
--text="Downloading '${2}' ..." &
|
|
|
|
|
_dg_zenpid=$!
|
|
|
|
|
|
|
|
|
|
while kill -0 "${_dg_curlpid}" 2>/dev/null; do
|
|
|
|
|
if ! kill -0 "${_dg_zenpid}" 2>/dev/null; then
|
|
|
|
|
# progress bar died; ask for abort
|
|
|
|
|
if zenity \
|
|
|
|
|
--question \
|
|
|
|
|
--text="Abort Download?"; then
|
|
|
|
|
kill "${_dg_curlpid}" 2>/dev/null || true
|
|
|
|
|
echo "Download cancelled!" >&2
|
|
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# restart progress bar
|
|
|
|
|
yes | zenity \
|
|
|
|
|
--progress --pulsate --auto-close \
|
|
|
|
|
--title="Downloading" \
|
|
|
|
|
--text="Downloading '${2}' ..." &
|
|
|
|
|
_dg_zenpid=$!
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
sleep 0.2
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
kill "${_dg_zenpid}" 2>/dev/null || true
|
|
|
|
|
wait "${_dg_curlpid}"
|
|
|
|
|
|
|
|
|
|
if [ -z "${3}" ]; then
|
|
|
|
|
echo "No SHA256 (OK)!" >&2
|
|
|
|
|
return 0
|
|
|
|
|
elif [ "$( sha256sum "${2}" | cut -d' ' -f1 )" = "${3}" ]; then
|
|
|
|
|
echo "SHA256 ${3} OK!" >&2
|
|
|
|
|
return 0
|
|
|
|
|
else
|
|
|
|
|
echo "SHA256 ${3} mismatch!" >&2
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
}
|