Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub tools #1039

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions scripts/install/emby.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/install/jackett.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions scripts/install/mango.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ 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")
echo_error "Currently unsupported but might be in the future. Please check back later!\nhttps://github.com/hkalexling/Mango/issues/131"
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?"
Expand All @@ -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
Expand Down
8 changes: 2 additions & 6 deletions scripts/install/sabnzbd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions scripts/upgrade/emby.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
16 changes: 6 additions & 10 deletions scripts/upgrade/sabnzbd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

${github_sabnzbd_version} is undefined

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
Expand All @@ -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
Expand Down Expand Up @@ -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
38 changes: 38 additions & 0 deletions sources/functions/utils
Original file line number Diff line number Diff line change
Expand Up @@ -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"

}