Created
July 5, 2023 19:21
-
-
Save cybersholt/2358fc69104433fbab54e273a9fda5fd to your computer and use it in GitHub Desktop.
VueTorrent Self Update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# need to have bsdtar installed to get it on raspberry pi | |
# sudo apt install libarchive-tools | |
# Use \033 if you need OS X compatibility | |
# e.g. RED='\033[0;31m' && echo -e ${RED}"My red text"... | |
# Reset | |
Color_Off='\e[0m' # Text Reset | |
# Regular Colors | |
Black='\e[0;30m' # Black | |
Red='\e[0;31m' # Red | |
Green='\e[0;32m' # Green | |
Yellow='\e[0;33m' # Yellow | |
Blue='\e[0;34m' # Blue | |
Purple='\e[0;35m' # Purple | |
Cyan='\e[0;36m' # Cyan | |
White='\e[0;37m' # White | |
# Bold | |
BBlack='\e[1;30m' # Black | |
BRed='\e[1;31m' # Red | |
BGreen='\e[1;32m' # Green | |
BYellow='\e[1;33m' # Yellow | |
BBlue='\e[1;34m' # Blue | |
BPurple='\e[1;35m' # Purple | |
BCyan='\e[1;36m' # Cyan | |
BWhite='\e[1;37m' # White | |
function banner { | |
cat << EOF | |
██╗░░░██╗██╗░░░██╗███████╗████████╗░█████╗░██████╗░██████╗░███████╗███╗░░██╗████████╗ | |
██║░░░██║██║░░░██║██╔════╝╚══██╔══╝██╔══██╗██╔══██╗██╔══██╗██╔════╝████╗░██║╚══██╔══╝ | |
╚██╗░██╔╝██║░░░██║█████╗░░░░░██║░░░██║░░██║██████╔╝██████╔╝█████╗░░██╔██╗██║░░░██║░░░ | |
░╚████╔╝░██║░░░██║██╔══╝░░░░░██║░░░██║░░██║██╔══██╗██╔══██╗██╔══╝░░██║╚████║░░░██║░░░ | |
░░╚██╔╝░░╚██████╔╝███████╗░░░██║░░░╚█████╔╝██║░░██║██║░░██║███████╗██║░╚███║░░░██║░░░ | |
░░░╚═╝░░░░╚═════╝░╚══════╝░░░╚═╝░░░░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝╚══════╝╚═╝░░╚══╝░░░╚═╝░░░ | |
Updater script Developed by cybersholt | |
EOF | |
} | |
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; } | |
## Example contents of version file. | |
## {"version" : "1.6.0"} | |
function write_version { | |
cat <<EOF >/home/cyber/vue_last.txt | |
{"version" : "$new_version"} | |
EOF | |
} | |
# 1. Create ProgressBar function | |
# 1.1 Input is currentState($1) and totalState($2) | |
function ProgressBar { | |
# Process data | |
let _progress=(${1}*100/${2}*100)/100 | |
let _done=(${_progress}*4)/10 | |
let _left=40-$_done | |
# Build progressbar string lengths | |
_fill=$(printf "%${_done}s") | |
_empty=$(printf "%${_left}s") | |
# 1.2 Build progressbar strings and print the ProgressBar line | |
# 1.2.1 Output example: | |
# 1.2.1.1 Progress : [########################################] 100% | |
printf "\rProgress : [${_fill// /#}${_empty// /-}] ${_progress}%%" | |
} | |
# Variables | |
_start=1 | |
# This accounts as the "totalState" variable for the ProgressBar function | |
_end=100 | |
# call the banner | |
banner | |
ProgressBar 20 ${_end} | |
# get the current version | |
current_version=`cat vue_last.txt | jq -r '.version'` | |
ProgressBar 40 ${_end} | |
# new version | |
new_version=`wget -q -O- https://api.github.com/repos/WDaan/VueTorrent/releases/latest | jq -r '.tag_name' | sed 's/v//'` | |
ProgressBar 60 ${_end} | |
# get the URL of the latest release | |
target=`wget -q -O- https://api.github.com/repos/WDaan/VueTorrent/releases/latest | jq -r '.assets[].browser_download_url'` | |
ProgressBar 80 ${_end} | |
if [ $(version $current_version) -ge $(version $new_version) ]; then | |
ProgressBar 100 ${_end} | |
echo " " | |
echo -e "${Green}Version $current_version is up to date." | |
else | |
ProgressBar 100 ${_end} | |
echo " " | |
echo -e "Version is outdated ${Red}$current_version${Color_Off}, new version is ${Green}$new_version${Color_Off}" | |
read -p "Do you want to update? [y/n]: " yn | |
case $yn in | |
[Yy]* ) `rm -rf /home/cyber/config/qBittorrent/public/ | wget -qO- $target | bsdtar -xvf- -C /home/cyber/config/qBittorrent | write_version`;; | |
[Nn]* ) exit;; | |
*) printf " \033[31m %s \n\033[0m" "invalid input" | |
esac | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment