Merge pull request #617 from tom-ee/maxage-for__package_update_index

Maxage for  package update index
remotes/origin/key_value-onchange
Darko Poljak 7 years ago committed by GitHub
commit 4d4d76bb38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 34
      cdist/conf/type/__package_update_index/explorer/currage
  2. 20
      cdist/conf/type/__package_update_index/gencode-remote
  3. 17
      cdist/conf/type/__package_update_index/man.rst
  4. 1
      cdist/conf/type/__package_update_index/parameter/optional

@ -0,0 +1,34 @@
#!/bin/sh
#
# 2018 Thomas Eckert (tom at it-eckert.de)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
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
;;
*) echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
echo "Please contribute an implementation for it if you can." >&2
exit 1
;;
esac

@ -22,6 +22,10 @@
#
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
type="$(cat "$type")"
@ -39,9 +43,23 @@ else
esac
fi
if [ -n "$maxage" ] && [ "$type" != "apt" ]; then
echo "ERROR: \"--maxage\" only supported for \"apt\" pkg-manager." >&2
exit 1
fi
case "$type" in
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" ;;
*)
echo "Don't know how to manage packages on: $os" >&2

@ -27,6 +27,16 @@ type
* yum for Red Hat
* 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.
MESSAGES
--------
apt-cache updated (age was: currage)
apt-cache was updated (run of `apt-get update`). `currage` is the time
in seconds since the previous run.
EXAMPLES
--------
@ -39,10 +49,15 @@ EXAMPLES
# Force use of a specific package manager
__package_update_index --type apt
# Only update every hour:
__package_update_index --maxage 3600 --type apt
# same as above (on apt-type systems):
__package_update_index --maxage 3600
AUTHORS
-------
Ricardo Catalinas Jiménez <jimenezrick--@--gmail.com>
| Ricardo Catalinas Jiménez <jimenezrick--@--gmail.com>
| Thomas Eckert <tom--@--it-eckert.de>
COPYING

Loading…
Cancel
Save