RKT Electron: Ensure .deb file has a size>0

This commit is contained in:
Jeremy Gardais 2021-08-23 10:29:43 +02:00
parent b5089fd4df
commit 390e965ac0
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 35 additions and 7 deletions

View File

@ -59,6 +59,7 @@ rkt_new_version=$("${script_wd}"/releasetags "${rkt_repo_url}" | head -n1 | sed
rkt_new_version_file="/tmp/.github.rocketchat-electron.upgrade" rkt_new_version_file="/tmp/.github.rocketchat-electron.upgrade"
rkt_new_pkg_url="https://github.com/RocketChat/Rocket.Chat.Electron/releases/download/${rkt_new_version}/rocketchat_${rkt_new_version}_amd64.deb" rkt_new_pkg_url="https://github.com/RocketChat/Rocket.Chat.Electron/releases/download/${rkt_new_version}/rocketchat_${rkt_new_version}_amd64.deb"
rkt_tmp_pkg_path="/tmp/.rocketchat_${rkt_new_version}_amd64.deb"
rkt_new_pkg_path="/tmp/rocketchat_${rkt_new_version}_amd64.deb" rkt_new_pkg_path="/tmp/rocketchat_${rkt_new_version}_amd64.deb"
# }}} # }}}
@ -66,21 +67,48 @@ rkt_new_pkg_path="/tmp/rocketchat_${rkt_new_version}_amd64.deb"
if [ "${rkt_current_version}" != "${rkt_new_version}" ]; then if [ "${rkt_current_version}" != "${rkt_new_version}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — Current version (${rkt_current_version}) and new one (${rkt_new_version}) seems to be different." [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — Current version (${rkt_current_version}) and new one (${rkt_new_version}) seems to be different."
## Create a temp file to monitor
touch -- "${rkt_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Rocket.Chat client Electron (current: ${rkt_current_version}): ${rkt_new_version}." >> "${rkt_new_version_file}"
## If it doesn't already exists, download this new package ## If it doesn't already exists, download this new package
if [ ! -f "${rkt_new_pkg_path}" ]; then if [ ! -f "${rkt_new_pkg_path}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Download .deb file from Rocket.Chat.Electron repository on Github to ${rkt_new_pkg_path} ." [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Download .deb file from Rocket.Chat.Electron repository on Github to: ${rkt_new_pkg_path} ."
wget --quiet "${rkt_new_pkg_url}" --output-document="${rkt_new_pkg_path}" wget --quiet "${rkt_new_pkg_url}" --output-document="${rkt_new_pkg_path}"
fi fi
else else
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — The current version is up-to-date." [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Test version — The current version is up-to-date."
## Ensure to remove any temp file and useless .deb file ## Ensure to remove any temp file and useless .deb file
rm -f -- "${rkt_new_version_file}" "${rkt_new_pkg_path}" rm --force -- "${rkt_new_version_file}" "${rkt_new_pkg_path}" "${rkt_tmp_pkg_path}"
## Exit
exit 0
fi fi
# }}} # }}}
# Verify downloaded package {{{
## If the downloaded package has a size greater than zero {{{
if [ -s "${rkt_new_pkg_path}" ]; then
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Empty file ? — \
Downloaded package looks good."
### Create a temp file to monitor
touch -- "${rkt_new_version_file}"
printf '\e[1;35m%-6s\e[m\n' "An upgrade is available for Rocket.Chat client Electron (current: ${rkt_current_version}): ${rkt_new_version}." >> "${rkt_new_version_file}"
### Exit
exit 0 exit 0
else
[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG: Empty file ? — \
Empty file, don't need to go further."
### Ensure to remove the file to monitor
rm --force -- "${rkt_new_version_file}"
### Keep a record of the downloaded package because as a new release might come soon
mv --force -- "${rkt_new_pkg_path}" "${rkt_tmp_pkg_path}"
### Exit
exit 0
fi
## }}}
# }}}
exit 255