Standardize variables and compare function with jitsi-update.sh

This commit is contained in:
Luis Guzmán 2021-02-18 01:15:52 -06:00
parent 55f8238506
commit f2d531f2db
1 changed files with 14 additions and 20 deletions

View File

@ -43,24 +43,20 @@ else
fi fi
} }
vlt() { # True if $1 is greater than $2
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ] version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; }
}
fc_ver() {
vlt $1 $2 && echo "yes" || echo "no"
}
JITSI_REPO=$(apt-cache policy | grep http | grep jitsi | grep stable | awk '{print $3}' | head -n 1 | cut -d "/" -f1) JITSI_REPO=$(apt-cache policy | grep http | grep jitsi | grep stable | awk '{print $3}' | head -n 1 | cut -d "/" -f1)
SND_AL_MODULE=$(lsmod | awk '{print$1}'| grep snd_aloop) SND_AL_MODULE=$(lsmod | awk '{print$1}'| grep snd_aloop)
HWE_VIR_MOD=$(apt-cache madison linux-image-generic-hwe-$(lsb_release -sr) 2>/dev/null|head -n1|grep -c "hwe-$(lsb_release -sr)") HWE_VIR_MOD=$(apt-cache madison linux-image-generic-hwe-$(lsb_release -sr) 2>/dev/null|head -n1|grep -c "hwe-$(lsb_release -sr)")
CONF_JSON="/etc/jitsi/jibri/config.json" CONF_JSON="/etc/jitsi/jibri/config.json"
JIBRI_CONF="/etc/jitsi/jibri/jibri.conf" JIBRI_CONF="/etc/jitsi/jibri/jibri.conf"
CHD_VER_LOCAL="$(/usr/local/bin/chromedriver --version 2>/dev/null| awk '{print$1,$2}')" CHDB="$(whereis chromedriver | awk '{print$2}')"
CHD_VER_LOCAL="$($CHDB --version 2>/dev/null| awk '{print$1,$2}')"
GOOGL_VER_LOCAL="$(/usr/bin/google-chrome --version 2>/dev/null)" GOOGL_VER_LOCAL="$(/usr/bin/google-chrome --version 2>/dev/null)"
CHD_VER_2D="$(echo $CHD_VER_LOCAL|awk '{print$2}'|cut -d "." -f 1,2)" CHD_VER_2D="$(echo $CHD_VER_LOCAL|awk '{print$2}'|cut -d "." -f 1,2)"
GOOGL_VER_2D="$(echo $GOOGL_VER_LOCAL|awk '{print$3}'|cut -d "." -f 1,2)" GOOGL_VER_2D="$(echo $GOOGL_VER_LOCAL|awk '{print$3}'|cut -d "." -f 1,2)"
CHD_VER=$(curl -sL https://chromedriver.storage.googleapis.com/LATEST_RELEASE) CHD_LTST=$(curl -sL https://chromedriver.storage.googleapis.com/LATEST_RELEASE)
#T1 #T1
echo -e "\n#1 -- Check repository --\n" echo -e "\n#1 -- Check repository --\n"
@ -96,12 +92,11 @@ if [ "$(apt-show-versions jibri | grep -c "uptodate")" = "1" ]; then
echo -e "Jibri is already up to date: \xE2\x9C\x94" echo -e "Jibri is already up to date: \xE2\x9C\x94"
else else
echo -e "\nAttempting jibri upgrade!" echo -e "\nAttempting jibri upgrade!"
apt -y install --only-upgrade jibri apt-get -y install --only-upgrade jibri
fi fi
T2=1 T2=1
#T3 #T3
echo -e "\n#3 -- Check Google Chrome/driver software. --\n" echo -e "\n#3 -- Check Google Chrome/driver software. --\n"
check_google_binaries "Google Chrome" "$GOOGL_VER_LOCAL" check_google_binaries "Google Chrome" "$GOOGL_VER_LOCAL"
check_google_binaries "Chromedriver" "$CHD_VER_LOCAL" check_google_binaries "Chromedriver" "$CHD_VER_LOCAL"
@ -112,21 +107,20 @@ if [ ! -z "$CHD_VER_LOCAL" ] && [ ! -z "$GOOGL_VER_LOCAL" ]; then
echo -e "Google Chrome is already up to date: \xE2\x9C\x94" echo -e "Google Chrome is already up to date: \xE2\x9C\x94"
else else
echo -e "\nAttempting Google Chrome upgrade!" echo -e "\nAttempting Google Chrome upgrade!"
apt -yq install --only-upgrade google-chrome-stable apt-get -yq install --only-upgrade google-chrome-stable
fi fi
# Only upgrade chromedriver if it's on a lower version, not just a different one. # Only upgrade chromedriver if it's on a lower version, not just a different one.
if [ $CHD_VER_2D = $GOOGL_VER_2D ]; then if [ $CHD_VER_2D = $GOOGL_VER_2D ]; then
echo -e "\nChromedriver version seems according to Google Chrome: \xE2\x9C\x94" echo -e "\nChromedriver version seems according to Google Chrome: \xE2\x9C\x94"
T3=1 T3=1
elif [ "$(fc_ver $GOOGL_VER_2D $CHD_VER_2D)" = "no" ]; then elif version_gt "$GOOGL_VER_2D" "$CHD_VER_2D" ; then
echo -e "\nAttempting Chromedriver update!" echo -e "\nAttempting Chromedriver update!"
wget -q https://chromedriver.storage.googleapis.com/$CHD_VER/chromedriver_linux64.zip -O /tmp/chromedriver_linux64.zip wget -q https://chromedriver.storage.googleapis.com/$CHD_LTST/chromedriver_linux64.zip -O /tmp/chromedriver_linux64.zip
unzip /tmp/chromedriver_linux64.zip -d /usr/local/bin/ unzip /tmp/chromedriver_linux64.zip -d /usr/local/bin/
chown root:root /usr/local/bin/chromedriver chown root:root $CHDB
chmod 0755 /usr/local/bin/chromedriver chmod 0755 $CHDB
rm -rf /tpm/chromedriver_linux64.zip rm -rf /tpm/chromedriver_linux64.zip
CHD_VER2D_U2D="$(echo $CHD_VER_LOCAL|awk '{print$2}'|cut -d "." -f 1,2)" if [ "$CHD_VER_2D" = "$GOOGL_VER_2D" ]; then
if [ "$(fc_ver $GOOGL_VER_2D $CHD_VER2D_U2D)" = "yes" ]; then
echo "Successfull update" echo "Successfull update"
T3=1 T3=1
else else