Add Debian and make update call more robust

- Debian based systems need to update the index before being able to report upgradable packages.
- Debian old-stable doesn't have `apt` yet and Ubuntu 14.04 emits the following warning when using `apt` in a script:
`WARNING: /usr/bin/apt does not have a stable CLI interface yet. Use with caution in scripts.`

By using `apt-get`, issuing a `update` call first and then counting the result of `grep 'Inst'`, this script now works on Debian 7, Debian 8, Ubuntu 14.04 and Ubuntu 16.04.
This commit is contained in:
Florian Beer
2016-08-03 04:51:35 +02:00
committed by GitHub
parent 3740f3e147
commit fac01628a0
+7 -5
View File
@@ -12,8 +12,9 @@ BIN_ZYPPER='/usr/bin/zypper'
CMD_ZYPPER='lu'
BIN_YUM='/usr/bin/yum'
CMD_YUM='check-update'
BIN_APT='/usr/bin/apt'
CMD_APT='list --upgradable'
BIN_APT='/usr/bin/apt-get'
CMD_APT='-s upgrade'
CMD_UPDATE='-qq update'
#general check for os based on /etc/os-release
if [ -f /etc/os-release ]; then
@@ -32,10 +33,11 @@ if [ -f /etc/os-release ]; then
else
echo "0";
fi
elif [ $OS == "ubuntu" ]; then
UPDATES=`$BIN_APT $CMD_APT | $BIN_WC $CMD_WC`
elif [ $OS == "ubuntu" ] || [ $OS == "debian" ]; then
`$BIN_APT $CMD_UPDATE`
UPDATES=`$BIN_APT $CMD_APT | grep 'Inst' | $BIN_WC $CMD_WC`
if [ $UPDATES -gt 1 ]; then
echo $(($UPDATES-1));
echo $UPDATES;
else
echo "0";
fi