🔧 various fixes
- add `download_gui` to the `common` script - unify indentation - prefer `notify-send` over `zenity` for better notifications
This commit is contained in:
parent
13f1bec42b
commit
bc40c2e4d5
3 changed files with 177 additions and 181 deletions
|
|
@ -16,3 +16,55 @@ needs_commands() { # $status $cmd1 $cmd2 ...
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,27 +4,16 @@
|
||||||
# summary: Startup script: Downloads and installs "Citrix Workspace"
|
# summary: Startup script: Downloads and installs "Citrix Workspace"
|
||||||
# params: none
|
# params: none
|
||||||
|
|
||||||
|
THISDIR="$(dirname "$(readlink -f "${0}")")"
|
||||||
|
# shellcheck disable=SC1091
|
||||||
|
. "${THISDIR}/.inc/common"
|
||||||
|
|
||||||
########
|
########
|
||||||
# INIT #
|
# INIT #
|
||||||
########
|
########
|
||||||
# find all download links on update page
|
# find all download links on update page
|
||||||
# find corresponding checksums
|
# find corresponding checksums
|
||||||
|
|
||||||
has_command() { # $command
|
|
||||||
command -v "$1" &>/dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
needs_commands() { # $cmd1 $cmd2 ...
|
|
||||||
local cmd
|
|
||||||
for cmd in "${@}"; do
|
|
||||||
if ! has_command "${cmd}"; then
|
|
||||||
echo "Command '${cmd}' not available!" >&2
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
needs_commands "xidel" "curl" || exit 1
|
needs_commands "xidel" "curl" || exit 1
|
||||||
|
|
||||||
echo -n "Downloading citrix update page ... " >&2
|
echo -n "Downloading citrix update page ... " >&2
|
||||||
|
|
@ -42,33 +31,33 @@ echo "OK!" >&2
|
||||||
# parse using XPath
|
# parse using XPath
|
||||||
declare -a links csums
|
declare -a links csums
|
||||||
eval "$( \
|
eval "$( \
|
||||||
echo "${html_data}" | xidel - \
|
echo "${html_data}" | xidel - \
|
||||||
--silent \
|
--silent \
|
||||||
--output-format bash \
|
--output-format bash \
|
||||||
--extract "links:=//div[contains(@class, 'ctx-dl-content')]//a[contains(@class, 'ctx-dl-link') and @rel]/@rel" \
|
--extract "links:=//div[contains(@class, 'ctx-dl-content')]//a[contains(@class, 'ctx-dl-link') and @rel]/@rel" \
|
||||||
--extract "csums:=//div[contains(@class, 'ctx-dl-content')]//ul[contains(@class, 'ctx-checksum-list')]/li[1]/text()" \
|
--extract "csums:=//div[contains(@class, 'ctx-dl-content')]//ul[contains(@class, 'ctx-checksum-list')]/li[1]/text()" \
|
||||||
)"
|
)"
|
||||||
|
|
||||||
# ensure every link has a checksum
|
# ensure every link has a checksum
|
||||||
if [[ "${!links[*]}" != "${!csums[*]}" ]]; then
|
if [[ "${!links[*]}" != "${!csums[*]}" ]]; then
|
||||||
echo "Links and Checksums don't match up!" >&2
|
echo "Links and Checksums don't match up!" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# postprocess data
|
# postprocess data
|
||||||
declare -A citrix_data
|
declare -A citrix_data
|
||||||
for key in "${!links[@]}"; do
|
for key in "${!links[@]}"; do
|
||||||
link="${links["${key}"]}"
|
link="${links["${key}"]}"
|
||||||
|
|
||||||
# if link starts with "//" (no protocol), assume https
|
# if link starts with "//" (no protocol), assume https
|
||||||
if [[ "${link}" == "//"* ]]; then
|
if [[ "${link}" == "//"* ]]; then
|
||||||
link="https:${link}"
|
link="https:${link}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# extract checksum only (64 hex digits)
|
# extract checksum only (64 hex digits)
|
||||||
csum="$(echo "${csums["${key}"]}" | grep -Eo "\<[[:xdigit:]]{64}\>")"
|
csum="$(echo "${csums["${key}"]}" | grep -Eo "\<[[:xdigit:]]{64}\>")"
|
||||||
|
|
||||||
citrix_data["${csum}"]="${link}"
|
citrix_data["${csum}"]="${link}"
|
||||||
done
|
done
|
||||||
|
|
||||||
# remove intermediate containers
|
# remove intermediate containers
|
||||||
|
|
@ -78,181 +67,135 @@ unset links csums
|
||||||
# FUNCS #
|
# FUNCS #
|
||||||
#########
|
#########
|
||||||
|
|
||||||
find_link() { # $filename_regex
|
find_links() { # $filename_regex
|
||||||
local link_regex="://downloads\.citrix\.com/[[:digit:]]+/${1}\?__gda__=exp=[[:digit:]]+~acl=[^~]+~hmac=[[:digit:]a-f]{64}$"
|
local link_regex="://downloads\.citrix\.com/[[:digit:]]+/${1}\?__gda__=exp=[[:digit:]]+~acl=[^~]+~hmac=[[:digit:]a-f]{64}$"
|
||||||
|
|
||||||
for key in "${!citrix_data[@]}"; do
|
for key in "${!citrix_data[@]}"; do
|
||||||
if echo "${citrix_data["${key}"]}" | grep -E "${link_regex}" &>/dev/null; then
|
if echo "${citrix_data["${key}"]}" | grep -E "${link_regex}" &>/dev/null; then
|
||||||
echo "${key} ${citrix_data["${key}"]}"
|
echo "${key} ${citrix_data["${key}"]}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
find_link_deb() { # $name $arch
|
find_links_deb() { # $name $arch
|
||||||
case "${2}" in
|
case "${2}" in
|
||||||
x86_64) local arch="amd64" ;;
|
x86_64) local arch="amd64" ;;
|
||||||
arm64) local arch="arm64" ;;
|
arm64) local arch="arm64" ;;
|
||||||
*) local arch="${2}" ;;
|
*) local arch="${2}" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
find_link "${1}_[[:digit:]\.]+_${arch}\.deb"
|
find_links "${1}_[[:digit:]\.]+_${arch}\.deb"
|
||||||
}
|
}
|
||||||
|
|
||||||
find_link_rpm() { # $name $flavor $arch
|
find_links_rpm() { # $name $flavor $arch
|
||||||
find_link "${1}(:?-${2})?-[[:digit:]\.]+(:?-[[:digit:]]+)?.${3}\.rpm"
|
find_links "${1}(:?-${2})?-[[:digit:]\.]+(:?-[[:digit:]]+)?.${3}\.rpm"
|
||||||
}
|
}
|
||||||
|
|
||||||
find_link_targz() { # $arch
|
find_links_targz() { # $arch
|
||||||
case "${1}" in
|
case "${1}" in
|
||||||
x86_64) local arch="x64" ;;
|
x86_64) local arch="x64" ;;
|
||||||
arm64) local arch="arm64" ;;
|
arm64) local arch="arm64" ;;
|
||||||
*) local arch="${1}" ;;
|
*) local arch="${1}" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
find_link "linux${arch}-[[:digit:]\.]+\.tar.gz"
|
find_links "linux${arch}-[[:digit:]\.]+\.tar.gz"
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck disable=SC2155
|
# shellcheck disable=SC2155
|
||||||
list_all() {
|
list_all_links() {
|
||||||
local debs="$(find_link_deb "[[:lower:]]+" "[[:alnum:]]+")"
|
local debs="$(find_links_deb "[[:lower:]]+" "[[:alnum:]]+")"
|
||||||
local debc="$(echo "${debs}" | wc -l)"
|
local debc="$(echo "${debs}" | wc -l)"
|
||||||
echo "deb:"
|
echo "deb:"
|
||||||
echo "${debs}"
|
echo "${debs}"
|
||||||
|
|
||||||
local rpms="$(find_link_rpm "[[:alpha:]]+" "[[:lower:]]+" "[[:alnum:]_]+")"
|
local rpms="$(find_links_rpm "[[:alpha:]]+" "[[:lower:]]+" "[[:alnum:]_]+")"
|
||||||
local rpmc="$(echo "${rpms}" | wc -l)"
|
local rpmc="$(echo "${rpms}" | wc -l)"
|
||||||
echo "rpm:"
|
echo "rpm:"
|
||||||
echo "${rpms}"
|
echo "${rpms}"
|
||||||
|
|
||||||
local tars="$(find_link_targz "[[:alnum:]]+")"
|
local tars="$(find_links_targz "[[:alnum:]]+")"
|
||||||
local tarc="$(echo "${tars}" | wc -l)"
|
local tarc="$(echo "${tars}" | wc -l)"
|
||||||
echo "tar.gz:"
|
echo "tar.gz:"
|
||||||
echo "${tars}"
|
echo "${tars}"
|
||||||
|
|
||||||
local anys="$(find_link "[[:alnum:]\._-]+")"
|
local anys="$(find_links "[[:alnum:]\._-]+")"
|
||||||
local anyc="$(echo "${anys}" | wc -l)"
|
local anyc="$(echo "${anys}" | wc -l)"
|
||||||
echo "any:"
|
echo "any:"
|
||||||
echo "${anys}"
|
echo "${anys}"
|
||||||
|
|
||||||
if [ $(( debc + rpmc + tarc )) -ne $(( anyc )) ]; then
|
if [ $(( debc + rpmc + tarc )) -ne $(( anyc )) ]; then
|
||||||
echo "Not all links matched!" >&2
|
echo "Not all links matched!" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
download_gui() { # $link $csum $destfile
|
|
||||||
needs_commands "curl" "zenity" "sha256sum" || return 1
|
|
||||||
echo "Downloading '${1}' to '${3}'"
|
|
||||||
|
|
||||||
curl -fL -o "${3}" "${1}" &
|
|
||||||
local curlpid=$!
|
|
||||||
|
|
||||||
yes | zenity \
|
|
||||||
--progress --pulsate --auto-close \
|
|
||||||
--title="Downloading" \
|
|
||||||
--text="Downloading '${3}' ..." &
|
|
||||||
local zenpid=$!
|
|
||||||
|
|
||||||
while kill -0 "${curlpid}" 2>/dev/null; do
|
|
||||||
if ! kill -0 "${zenpid}" 2>/dev/null; then
|
|
||||||
# progress bar died; ask for abort
|
|
||||||
if zenity \
|
|
||||||
--question \
|
|
||||||
--text="Abort Download?"; then
|
|
||||||
kill "${curlpid}" 2>/dev/null || true
|
|
||||||
echo "Download cancelled!" >&2
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
|
|
||||||
# restart progress bar
|
|
||||||
yes | zenity \
|
|
||||||
--progress --pulsate --auto-close \
|
|
||||||
--title="Downloading" \
|
|
||||||
--text="Downloading '${3}' ..." &
|
|
||||||
zenpid=$!
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sleep 0.2
|
|
||||||
done
|
|
||||||
|
|
||||||
kill "${zenpid}" 2>/dev/null || true
|
|
||||||
wait "${curlpid}"
|
|
||||||
|
|
||||||
if [ "$( sha256sum "${3}" | cut -d' ' -f1 )" = "${2}" ]; then
|
|
||||||
echo "SHA256 ${2} OK!" >&2
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
echo "SHA256 ${2} mismatch!" >&2
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
install_deb() { # $name
|
install_deb() { # $name
|
||||||
needs_commands "dpkg-query" "zenity" "gdebi-gtk" || return 1
|
needs_commands "dpkg-query" "zenity" "notify-send" "gdebi-gtk" || return 1
|
||||||
|
|
||||||
local arch
|
local arch
|
||||||
arch="$(uname -m)"
|
arch="$(uname -m)"
|
||||||
echo "Trying to install ${1} DEB for ${arch}" >&2
|
echo "Trying to install ${1} DEB for ${arch}" >&2
|
||||||
|
|
||||||
local link
|
local link
|
||||||
if ! link="$(find_link_deb "${1}" "${arch}")"; then
|
if ! link="$(find_links_deb "${1}" "${arch}")"; then
|
||||||
echo "No DEB found!" >&2
|
echo "No DEB found!" >&2
|
||||||
return 1
|
return 1
|
||||||
elif [ "$(echo "${link}" | wc -l)" -ne 1 ]; then
|
elif [ "$(echo "${link}" | wc -l)" -ne 1 ]; then
|
||||||
echo "More than one DEB found!" >&2
|
echo "More than one DEB found!" >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local csum
|
local csum
|
||||||
csum="$(echo "${link}" | cut -d' ' -f1)"
|
csum="$(echo "${link}" | cut -d' ' -f1)"
|
||||||
link="$(echo "${link}" | cut -d' ' -f2)"
|
link="$(echo "${link}" | cut -d' ' -f2)"
|
||||||
|
|
||||||
local version_available
|
local version_available
|
||||||
version_available="$(echo "${link}" | sed -r 's/^.*\/[^_]+_([[:digit:]\.]+)_[^\.]+\.deb.*$/\1/')"
|
version_available="$(echo "${link}" | sed -r 's/^.*\/[^_]+_([[:digit:]\.]+)_[^\.]+\.deb.*$/\1/')"
|
||||||
|
|
||||||
local version_installed
|
local version_installed
|
||||||
if version_installed="$(dpkg-query --show --showformat='${Version}\n' "${1}")" \
|
if version_installed="$(dpkg-query --show --showformat='${Version}\n' "${1}")" \
|
||||||
&& [ "${version_available}" = "${version_installed}" ]; then
|
&& [ "${version_available}" = "${version_installed}" ]; then
|
||||||
echo "Newest version already installed!" >&2
|
echo "Newest version already installed!" >&2
|
||||||
zenity \
|
notify-send \
|
||||||
--notification \
|
--app-name "citrix-update" \
|
||||||
--window-icon="info" \
|
--icon "info" \
|
||||||
--text="Citrix \"${1}\": Newest version is installed!"
|
"Citrix Update" \
|
||||||
sleep 2
|
"Citrix \"${1}\": Newest version is installed!"
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! zenity \
|
||||||
|
--question \
|
||||||
|
--title="New Version Available" \
|
||||||
|
--text="<span size=\"xx-large\">Citrix Upgrade Available!</span>\n\nInstall ${1} version <b>${version_available}</b> now?"; then
|
||||||
|
echo "Installation of ${1} cancelled!" >&2
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
local destfile
|
||||||
|
destfile="$(mktemp --tmpdir "XXXXX_${1}_${version_available}.deb")"
|
||||||
|
|
||||||
|
if download_gui "${link}" "${destfile}" "${csum}"; then
|
||||||
|
echo "Download for ${1} successful!" >&2
|
||||||
|
gdebi-gtk "${destfile}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -f "${destfile}"
|
||||||
|
echo "Cleaned up '${destfile}'" >&2
|
||||||
return 0
|
return 0
|
||||||
fi
|
|
||||||
|
|
||||||
if ! zenity \
|
|
||||||
--question \
|
|
||||||
--title="New Version Available" \
|
|
||||||
--text="<span size=\"xx-large\">Citrix Upgrade Available!</span>\n\nInstall ${1} version <b>${version_available}</b> now?"; then
|
|
||||||
echo "Installation of ${1} cancelled!" >&2
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
local destfile
|
|
||||||
destfile="$(mktemp --tmpdir "XXXXX_${1}_${version_available}.deb")"
|
|
||||||
|
|
||||||
if download_gui "${link}" "${csum}" "${destfile}"; then
|
|
||||||
echo "Download for ${1} successful!" >&2
|
|
||||||
gdebi-gtk "${destfile}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
rm -f "${destfile}"
|
|
||||||
echo "Cleaned up '${destfile}'" >&2
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
########
|
########
|
||||||
# MAIN #
|
# MAIN #
|
||||||
########
|
########
|
||||||
|
|
||||||
list_all > /dev/null
|
list_all_links > /dev/null
|
||||||
|
|
||||||
if has_command "apt"; then
|
if has_command "apt"; then
|
||||||
install_deb "icaclient" || exit 1
|
install_deb "icaclient" || exit 1
|
||||||
install_deb "ctxusb" || exit 1
|
install_deb "ctxusb" || exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ needs_commands "curl" "notify-send"
|
||||||
|
|
||||||
version_available="$( \
|
version_available="$( \
|
||||||
curl --silent --verbose --retry-all-errors --retry-delay 3 --retry 5 \
|
curl --silent --verbose --retry-all-errors --retry-delay 3 --retry 5 \
|
||||||
'https://github.com/nextcloud-releases/desktop/releases/latest' 2>&1 \
|
'https://github.com/nextcloud-releases/desktop/releases/latest' 2>&1 \
|
||||||
| grep '^< location: ' \
|
| grep '^< location: ' \
|
||||||
| grep -Eo '[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+' \
|
| grep -Eo '[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+' \
|
||||||
| head -n1 \
|
| head -n1 \
|
||||||
|
|
@ -33,17 +33,18 @@ version_installed="$( \
|
||||||
if [ "${version_available}" != "${version_installed}" ]; then
|
if [ "${version_available}" != "${version_installed}" ]; then
|
||||||
echo "new nextcloud version available: ${version_available}" >&2
|
echo "new nextcloud version available: ${version_available}" >&2
|
||||||
notify-send \
|
notify-send \
|
||||||
--app-name "Nextcloud" \
|
--app-name "nextcloud-appimage-launch" \
|
||||||
--icon "${THISDIR}/.icon/nextcloud.svg" \
|
--icon "${THISDIR}/.icon/nextcloud.svg" \
|
||||||
"nextcloud-appimage-launch" \
|
"Nextcloud" \
|
||||||
"new nextcloud version available: ${version_available}"
|
"Installing new Nextcloud version: ${version_available}"
|
||||||
|
|
||||||
curl --silent --show-error --fail --location \
|
if download_gui \
|
||||||
"https://github.com/nextcloud-releases/desktop/releases/download/v${version_available}/Nextcloud-${version_available}-x86_64.AppImage" \
|
"https://github.com/nextcloud-releases/desktop/releases/download/v${version_available}/Nextcloud-${version_available}-x86_64.AppImage" \
|
||||||
--output "${INSTALL_DIR}/Nextcloud-${version_available}-x86_64.AppImage"
|
"${INSTALL_DIR}/Nextcloud-${version_available}-x86_64.AppImage" \
|
||||||
|
""; then # no sha256
|
||||||
chmod +x "${INSTALL_DIR}/Nextcloud-${version_available}-x86_64.AppImage"
|
chmod +x "${INSTALL_DIR}/Nextcloud-${version_available}-x86_64.AppImage"
|
||||||
ln -sf "./Nextcloud-${version_available}-x86_64.AppImage" "${INSTALL_DIR}/current"
|
ln -sf "./Nextcloud-${version_available}-x86_64.AppImage" "${INSTALL_DIR}/current"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec "${INSTALL_DIR}/current" --background "${@}"
|
exec "${INSTALL_DIR}/current" --background "${@}"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue