forked from ungleich-public/cdist
__package_update_index: optional --maxage <seconds>
-parameter for apt
`--maxage 3600` ensures that `apt-get --quiet update` is only done if the previous run was at least 1 hour ago. This also adds messaging
This commit is contained in:
parent
950f00d1a4
commit
179c5a2dfe
4 changed files with 44 additions and 2 deletions
15
cdist/conf/type/__package_update_index/explorer/currage
Normal file
15
cdist/conf/type/__package_update_index/explorer/currage
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
os="$("$__explorer/os")"
|
||||||
|
|
||||||
|
case "$os" in
|
||||||
|
debian|ubuntu|devuan)
|
||||||
|
if [ -f "/var/cache/apt/pkgcache.bin" ]; then
|
||||||
|
echo $(($(date +"%s")-$(stat --format '%Y' /var/cache/apt/pkgcache.bin)))
|
||||||
|
else
|
||||||
|
echo 0
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*) ## not supported $os
|
||||||
|
;;
|
||||||
|
esac
|
|
@ -22,6 +22,10 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
type="$__object/parameter/type"
|
type="$__object/parameter/type"
|
||||||
|
if [ -f "$__object/parameter/maxage" ]; then
|
||||||
|
maxage="$(cat "$__object/parameter/maxage")"
|
||||||
|
currage="$(cat "$__object/explorer/currage")"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -f "$type" ]; then
|
if [ -f "$type" ]; then
|
||||||
type="$(cat "$type")"
|
type="$(cat "$type")"
|
||||||
|
@ -39,9 +43,23 @@ else
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -n "$maxage" ] && [ "$type" != "apt" ]; then
|
||||||
|
echo "ERROR: \"--maxage\" only supported for \"apt\" pkg-manager." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
case "$type" in
|
case "$type" in
|
||||||
yum) ;;
|
yum) ;;
|
||||||
apt) echo "apt-get --quiet update" ;;
|
apt) if [ -n "$maxage" ]; then
|
||||||
|
## check if we need to update:
|
||||||
|
if [ $currage -ge $maxage ]; then
|
||||||
|
echo "apt-get --quiet update"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "apt-get --quiet update"
|
||||||
|
fi
|
||||||
|
echo "apt-cache updated (age was: $currage)" >> "$__messages_out"
|
||||||
|
;;
|
||||||
pacman) echo "pacman --noprogressbar --sync --refresh" ;;
|
pacman) echo "pacman --noprogressbar --sync --refresh" ;;
|
||||||
*)
|
*)
|
||||||
echo "Don't know how to manage packages on: $os" >&2
|
echo "Don't know how to manage packages on: $os" >&2
|
||||||
|
|
|
@ -27,6 +27,9 @@ type
|
||||||
* yum for Red Hat
|
* yum for Red Hat
|
||||||
* pacman for Arch Linux
|
* pacman for Arch Linux
|
||||||
|
|
||||||
|
maxage
|
||||||
|
Available for package manager apt, max time in seconds since last update.
|
||||||
|
Repo update is skipped if maxage is not reached yet.
|
||||||
|
|
||||||
EXAMPLES
|
EXAMPLES
|
||||||
--------
|
--------
|
||||||
|
@ -39,10 +42,15 @@ EXAMPLES
|
||||||
# Force use of a specific package manager
|
# Force use of a specific package manager
|
||||||
__package_update_index --type apt
|
__package_update_index --type apt
|
||||||
|
|
||||||
|
# Only update every hour:
|
||||||
|
__package_update_index --maxage 3600 --type apt
|
||||||
|
# same as avove (on apt-type systems):
|
||||||
|
__package_update_index --maxage 3600
|
||||||
|
|
||||||
AUTHORS
|
AUTHORS
|
||||||
-------
|
-------
|
||||||
Ricardo Catalinas Jiménez <jimenezrick--@--gmail.com>
|
| Ricardo Catalinas Jiménez <jimenezrick--@--gmail.com>
|
||||||
|
| Thomas Eckert <tom--@--it-eckert.de>
|
||||||
|
|
||||||
|
|
||||||
COPYING
|
COPYING
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
type
|
type
|
||||||
|
maxage
|
||||||
|
|
Loading…
Reference in a new issue