diff --git a/scripts/install/emby.sh b/scripts/install/emby.sh index a4a7e077e..629c3ca24 100755 --- a/scripts/install/emby.sh +++ b/scripts/install/emby.sh @@ -35,8 +35,8 @@ fi username=$(cut -d: -f1 < /root/.master.info) echo_progress_start "Downloading emby installer" -current=$(github_latest_version MediaBrowser/Emby.Releases) -wget -O /tmp/emby.dpkg https://github.com/MediaBrowser/Emby.Releases/releases/download/${current}/emby-server-deb_${current}_$(_os_arch).deb >> $log 2>&1 || { +dl_url=$(github_release_url MediaBrowser/Emby.Releases "$(_os_arch).deb") +wget -O /tmp/emby.dpkg "$dl_url" >> $log 2>&1 || { echo_error "Failed to download" exit 1 } diff --git a/scripts/install/jackett.sh b/scripts/install/jackett.sh index 96d3d8ea5..bff8e9415 100755 --- a/scripts/install/jackett.sh +++ b/scripts/install/jackett.sh @@ -35,12 +35,12 @@ case "$(_os_arch)" in ;; esac -version=$(github_latest_version "Jackett/Jackett") +dl_url=$(github_release_url "Jackett/Jackett" "Linux${arch}") password=$(cut -d: -f2 < /root/.master.info) echo_progress_start "Downloading and extracting jackett" cd /home/$username -wget "https://github.com/Jackett/Jackett/releases/download/${version}/Jackett.Binaries.Linux${arch}.tar.gz" >> "$log" 2>&1 +wget "$dl_url" >> "$log" 2>&1 tar -xvzf Jackett.Binaries.*.tar.gz > /dev/null 2>&1 rm -f Jackett.Binaries.*.tar.gz chown ${username}:${username} -R Jackett diff --git a/scripts/install/mango.sh b/scripts/install/mango.sh index b9e8bbf08..786504e9e 100755 --- a/scripts/install/mango.sh +++ b/scripts/install/mango.sh @@ -8,8 +8,6 @@ mangousr="mango" # Downloading the latest binary function _install_mango() { - echo_progress_start "Downloading binary" - mango_latest=$(github_latest_version getmango/Mango) case "$(_os_arch)" in "arm32" | "arm64") @@ -17,7 +15,7 @@ function _install_mango() { exit 1 ;; "amd64") - dlurl="https://github.com/getmango/Mango/releases/download/${mango_latest}/mango" + dlurl=$(github_release_url getmango/Mango | grep -e 'mango$') ;; *) echo_error "Unsupported arch?" @@ -28,6 +26,7 @@ function _install_mango() { mkdir -p "$mangodir" mkdir -p "$mangodir"/library + echo_progress_start "Downloading binary" wget "${dlurl}" -O $mangodir/mango >> "$log" 2>&1 || { echo_error "Failed to download binary" exit 1 diff --git a/scripts/install/sabnzbd.sh b/scripts/install/sabnzbd.sh index 9bbde660d..e521dc3ff 100755 --- a/scripts/install/sabnzbd.sh +++ b/scripts/install/sabnzbd.sh @@ -15,16 +15,12 @@ user=$(_get_master_username) password="$(_get_user_password ${user})" -latestversion=$(github_latest_version sabnzbd/sabnzbd) || { - echo_error "Failed to query GitHub for latest sabnzbd version" - exit 1 -} -latest="https://github.com/sabnzbd/sabnzbd/archive/refs/tags/${latestversion}.tar.gz" +latest="$(github_release_url sabnzbd/sabnzbd "src.tar.gz")" systempy3_ver=$(get_candidate_version python3) #Version 4.0 is going to raise the min python version to 3.8 so we have to differentiate whether or not to build a pyenv -if dpkg --compare-versions ${systempy3_ver} lt 3.8.0 && dpkg --compare-versions ${latestversion} ge 3.5.0; then +if dpkg --compare-versions ${systempy3_ver} lt 3.8.0 && dpkg --compare-versions ${github_sabnzbd_version} ge 3.5.0; then LIST='par2 p7zip-full libffi-dev libssl-dev libglib2.0-dev libdbus-1-dev' PYENV=True else diff --git a/scripts/upgrade/emby.sh b/scripts/upgrade/emby.sh index b7550a1bb..89eaba444 100755 --- a/scripts/upgrade/emby.sh +++ b/scripts/upgrade/emby.sh @@ -2,12 +2,12 @@ # Simple tool to grab the latest release of emby . /etc/swizzin/sources/functions/utils -latest=$(github_latest_version MediaBrowser/Emby.Releases) +dl_url=$(github_release_url MediaBrowser/Emby.Releases "$(_os_arch).deb") current=$(dpkg-query -f='${Version}' --show emby-server) -if dpkg --compare-versions ${latest} gt ${current}; then +if dpkg --compare-versions ${github_Emby_tag} gt ${current}; then echo_info "Upgrading Emby" - wget -O /tmp/emby.dpkg https://github.com/MediaBrowser/Emby.Releases/releases/download/${latest}/emby-server-deb_${latest}_$(_os_arch).deb >> $log 2>&1 || { + wget -O /tmp/emby.dpkg "$dl_url" >> $log 2>&1 || { echo_error "Emby failed to download" exit 1 } diff --git a/scripts/upgrade/sabnzbd.sh b/scripts/upgrade/sabnzbd.sh index 93a2ac2da..e47a22d59 100755 --- a/scripts/upgrade/sabnzbd.sh +++ b/scripts/upgrade/sabnzbd.sh @@ -10,15 +10,11 @@ fi . /etc/swizzin/sources/functions/pyenv localversion=$(/opt/.venv/sabnzbd/bin/python /opt/sabnzbd/SABnzbd.py --version | grep -m1 SABnzbd | cut -d- -f2) #latest=$(curl -s https://sabnzbd.org/downloads | grep -m1 Linux | grep download-link-src | grep -oP "href=\"\K[^\"]+") -latestversion=$(github_latest_version sabnzbd/sabnzbd) || { - echo_error "Failed to query GitHub for latest sabnzbd version" - exit 1 -} -latest="https://github.com/sabnzbd/sabnzbd/archive/refs/tags/${latestversion}.tar.gz" +latest=$(github_release_url sabnzbd/sabnzbd "src.tar.gz") pyvenv_version=$(/opt/.venv/sabnzbd/bin/python --version | awk '{print $2}') -if dpkg --compare-versions ${pyvenv_version} lt 3.8.0 && dpkg --compare-versions ${latestversion} ge 3.5.0; then +if dpkg --compare-versions ${pyvenv_version} lt 3.8.0 && dpkg --compare-versions ${github_sabnzbd_version} ge 3.5.0; then LIST='par2 p7zip-full libffi-dev libssl-dev libglib2.0-dev libdbus-1-dev' PYENV_REBUILD=True elif [[ -f /opt/.venv/sabnzbd/bin/python2 ]]; then @@ -29,7 +25,7 @@ else fi apt_install $LIST -if dpkg --compare-versions ${localversion:-0.0} lt ${latestversion}; then +if dpkg --compare-versions ${localversion:-0.0} lt ${github_sabnzbd_version}; then if [[ $PYENV_REBUILD == True ]]; then echo_progress_start "Upgrading SABnzbd python virtual environment" rm -rf /opt/.venv/sabnzbd @@ -79,14 +75,14 @@ if dpkg --compare-versions ${localversion:-0.0} lt ${latestversion}; then rm /tmp/sabnzbd.tar.gz echo_progress_start "Checking pip requirements" - if [[ $latestversion =~ ^3\.0\.[1-2] ]]; then + if [[ $github_sabnzbd_version =~ ^3\.0\.[1-2] ]]; then sed -i "s/feedparser.*/feedparser<6.0.0/g" /opt/sabnzbd/requirements.txt fi sudo -u ${user} bash -c "/opt/.venv/sabnzbd/bin/pip install -r /opt/sabnzbd/requirements.txt" >> "$log" 2>&1 echo_progress_done systemctl try-restart sabnzbd - echo_info "SABnzbd has been upgraded to version ${latestversion}!" + echo_info "SABnzbd has been upgraded to version ${github_sabnzbd_version}!" else - echo_info "Nothing to do! Current version (${localversion}) matches the remote version (${latestversion})" + echo_info "Nothing to do! Current version (${localversion}) matches the remote version (${github_sabnzbd_version})" exit 0 fi diff --git a/sources/functions/utils b/sources/functions/utils index 72c0c3263..84ffc5b28 100644 --- a/sources/functions/utils +++ b/sources/functions/utils @@ -168,3 +168,41 @@ function github_latest_version() { repo=$1 curl -fsSLI -o /dev/null -w %{url_effective} https://github.com/${repo}/releases/latest | grep -o '[^/]*$' } + +function github_release_url() { + # Argument expects the author/repo format, defaults to all DL links of the latest release + # Usage: github_release_url "user/repo" ["name_filter"] ["tag"] + # Example: github_release_url "MediaBrowser/Emby.Releases" + # Example: github_release_url "MediaBrowser/Emby.Releases" "$(_os_arch).deb" + # Example: github_release_url "MediaBrowser/Emby.Releases" "$(_os_arch).deb" "v0.1.0" + # also exports a variable with the name of the repo and the tag, e.g. `github_Emby_tag` + repo="$1" + filter="$2" + + if [[ -z "$3" ]]; then + tag=$(github_latest_version "${repo}") || { + echo_error "Failed to query GitHub for latest version of $repo" + return 1 + } + else + tag="$3" + fi + + link_payload=$(curl -fsL https://github.com/${repo}/releases/expanded_assets/$tag) || { + echo_error "Failed to query GitHub for tag ${tag:='latest'} of $repo" + return 1 + } + + links=$(echo "${link_payload}" | grep -oP '(?<=href=")[^"]+' | sed -e 's|^|https://github.com|') + + if [[ -n "$filter" ]]; then + echo "$links" | grep "$filter" + else + echo "$links" + fi + + # e.g. MediaBrowser/Emby.Releases -> Emby.Releases -> Emby + project_name=$(echo "$repo" | cut -d'/' -f2 | grep -oe '^\w*') + export github_${project_name}_tag="$tag" + +}