#!/bin/bash
get_commanet_apt_version(){
rm -f index.html*
wget http://update.commanet.co.za/apt/pool/main/$1/$2/ 2&>1 > /dev/null
if [ "$4" == 1 ]; then
APT_VERSION=$(grep "$3" index.html | grep -vi "index of" | grep -v "$3-" | grep -v "
" | cut -d'.' -f2-4 | cut -d'"' -f5 | cut -d'_' -f2)
else
APT_VERSION=$(grep "$3" index.html | grep -vi "index of" | grep -v "" | cut -d'.' -f2-4 | cut -d'"' -f5 | cut -d'_' -f2)
fi
}
get_misdn_modules_apt_version(){
rm -f index.html*
wget http://update.commanet.co.za/apt/pool/main/m/misdn/ 2&>1 > /dev/null
APT_VERSION=$(grep "misdn-modules" index.html | grep -vi "index of" | grep -v "" | cut -d'.' -f4-9 | cut -d'_' -f2)
}
get_dahdi_modules_apt_version(){
rm -f index.html*
wget http://update.commanet.co.za/apt/pool/main/d/dahdi/ 2&>1 > /dev/null
APT_VERSION=$(grep "dahdi-modules" index.html | grep -vi "index of" | grep -v "" | cut -d'.' -f4-9 | cut -d'_' -f2)
}
get_system_apt_version(){
if [ "$4" == 1 ]; then
if [ "$6" != "" ]; then
INTERIM=$(dpkg -l | grep "$3" | grep -v "$6" | grep -v "$3-" | tr -s ' ' ' ' | cut -d' ' -f3)
else
INTERIM=$(dpkg -l | grep "$3" | grep -v "$3-" | tr -s ' ' ' ' | cut -d' ' -f3)
fi
else
if [ "$6" != "" ]; then
INTERIM=$(dpkg -l | grep "$3" | grep -v "$6" | tr -s ' ' ' ' | cut -d' ' -f3)
else
INTERIM=$(dpkg -l | grep "$3" | tr -s ' ' ' ' | cut -d' ' -f3)
fi
fi
if [ "$5" == "1" ]; then
SYSTEM_VERSION=$(echo $INTERIM | cut -d":" -f2)
else
SYSTEM_VERSION=$INTERIM
fi
}
# Usage: compare_packages
compare_packages(){
if [ "$1" == "" -o "$2" == "" ]; then
# Do nothing
echo ""
else
if [ "$1" != "$2" ]; then
echo "Update server version ($2) for package $3 which has local version $1"
else
echo "package $3 version $1 is up to date"
fi
fi
}
# Compare two package versions, one from the commanet update server and the other local. Notify the
# user when there is an update available
# Usage: compare_package <0|1 where 1 means base package> <0|1 where 1 means version delimiter '=' required (exclude)
# example: compare_package a asteriskcomma asteriskcomma 1 1
# compare_package a asteriskcomma asteriskcomma-sounds-main 0 1
compare_package(){
get_commanet_apt_version $1 $2 $3 $4 $5
get_system_apt_version $1 $2 $3 $4 $5 $6
compare_packages $SYSTEM_VERSION $APT_VERSION $3
}
# Treat modules special
get_misdn_modules_apt_version
get_system_apt_version m misdn misdn-modules 0 1
compare_packages $SYSTEM_VERSION $APT_VERSION misdn_modules
get_dahdi_modules_apt_version
get_system_apt_version d dahdi dahdi-modules 0 1
compare_packages $SYSTEM_VERSION $APT_VERSION dahdi_modules
#asteriskcomma
compare_package a asteriskcomma asteriskcomma 1 1
compare_package a asteriskcomma asteriskcomma-sounds-main 0 1
#freepbx
compare_package f freepbx-comma-gui freepbx-comma-gui 1 0
compare_package f freepbx-comma-gui freepbx-common-comma-gui 0 0
compare_package f freepbx-comma-gui freepbx-mysql 0 0
compare_package f freepbx-comma-gui freepbx-panel 0 0
compare_package f freepbx-comma-gui freepbx-sounds-extra 0 0
compare_package f freepbx-comma-gui asterisk-config-freepbx 0 0
compare_package f freepbx-comma-gui asterisk-sounds-moh-freepbx 0 0
#freepbx-modules
compare_package f freepbx-modules-comma-gui freepbx-modules-comma-gui 0 0
#dahdi
compare_package d dahdi dahdi 1 1 dahdi-modules
compare_package d dahdi libtonezone1 0 1
#misdn
compare_package m misdn misdn 1 0 misdn-modules
#comx
compare_package c comx-meta comx-base 0 0
compare_package c comx-meta comx-gui 0 0
#comma-gui
compare_package c comma-gui comma-gui 0 0 freepbx