mirror of
https://github.com/ovh/debian-cis.git
synced 2025-07-02 23:39:49 +02:00
1.1 Install updates
This commit is contained in:
35
lib/utils.sh
35
lib/utils.sh
@ -16,3 +16,38 @@ is_installed()
|
||||
}
|
||||
|
||||
|
||||
# contains helper functions to work with apt
|
||||
|
||||
apt_update_if_needed()
|
||||
{
|
||||
if [ -e /var/cache/apt/pkgcache.bin ]
|
||||
then
|
||||
UPDATE_AGE=$(( $(date +%s) - $(stat -c '%Y' /var/cache/apt/pkgcache.bin) ))
|
||||
|
||||
if [ $UPDATE_AGE -gt 21600 ]
|
||||
then
|
||||
# update too old, refresh database
|
||||
apt-get update -y >/dev/null 2>/dev/null
|
||||
fi
|
||||
else
|
||||
apt-get update -y >/dev/null 2>/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
apt_check_updates()
|
||||
{
|
||||
local NAME="$1"
|
||||
local DETAILS="/dev/shm/${NAME}"
|
||||
LANGUAGE=C apt-get upgrade -s 2>/dev/null | grep -E "^Inst" > $DETAILS || :
|
||||
local COUNT=$(wc -l < "$DETAILS")
|
||||
FNRET=128 # Unknown function return result
|
||||
RESULT="" # Result output for upgrade
|
||||
if [ $COUNT -gt 0 ]; then
|
||||
RESULT="There is $COUNT updates available :\n$(cat $DETAILS)"
|
||||
FNRET=1
|
||||
else
|
||||
RESULT="OK, no updates available"
|
||||
FNRET=0
|
||||
fi
|
||||
rm $DETAILS
|
||||
}
|
||||
|
Reference in New Issue
Block a user