From 27d38a28abfe79657828953c365b62bd1ab14a55 Mon Sep 17 00:00:00 2001 From: Thomas Eckert Date: Tue, 30 Jan 2018 13:16:29 +0100 Subject: [PATCH 1/7] __package_update_index: optional `--maxage `-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 --- .../__package_update_index/explorer/currage | 15 ++++++++++++++ .../__package_update_index/gencode-remote | 20 ++++++++++++++++++- .../conf/type/__package_update_index/man.rst | 10 +++++++++- .../__package_update_index/parameter/optional | 1 + 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 cdist/conf/type/__package_update_index/explorer/currage diff --git a/cdist/conf/type/__package_update_index/explorer/currage b/cdist/conf/type/__package_update_index/explorer/currage new file mode 100644 index 00000000..bd53a789 --- /dev/null +++ b/cdist/conf/type/__package_update_index/explorer/currage @@ -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 diff --git a/cdist/conf/type/__package_update_index/gencode-remote b/cdist/conf/type/__package_update_index/gencode-remote index 20beed5b..d84e7953 100755 --- a/cdist/conf/type/__package_update_index/gencode-remote +++ b/cdist/conf/type/__package_update_index/gencode-remote @@ -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 diff --git a/cdist/conf/type/__package_update_index/man.rst b/cdist/conf/type/__package_update_index/man.rst index 454aa05b..ac954faa 100644 --- a/cdist/conf/type/__package_update_index/man.rst +++ b/cdist/conf/type/__package_update_index/man.rst @@ -27,6 +27,9 @@ 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. EXAMPLES -------- @@ -39,10 +42,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 avove (on apt-type systems): + __package_update_index --maxage 3600 AUTHORS ------- -Ricardo Catalinas Jiménez +| Ricardo Catalinas Jiménez +| Thomas Eckert COPYING diff --git a/cdist/conf/type/__package_update_index/parameter/optional b/cdist/conf/type/__package_update_index/parameter/optional index aa80e646..7a0be716 100644 --- a/cdist/conf/type/__package_update_index/parameter/optional +++ b/cdist/conf/type/__package_update_index/parameter/optional @@ -1 +1,2 @@ type +maxage From 2dc5550fa4f6fb4acb20e6fc2a8a8ef996aa6221 Mon Sep 17 00:00:00 2001 From: Thomas Eckert Date: Tue, 30 Jan 2018 13:24:28 +0100 Subject: [PATCH 2/7] __package_update_index: update man-page w/ `--magage` and MESSAGING --- cdist/conf/type/__package_update_index/man.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cdist/conf/type/__package_update_index/man.rst b/cdist/conf/type/__package_update_index/man.rst index ac954faa..b63af654 100644 --- a/cdist/conf/type/__package_update_index/man.rst +++ b/cdist/conf/type/__package_update_index/man.rst @@ -31,6 +31,13 @@ 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 -------- @@ -44,7 +51,7 @@ EXAMPLES # Only update every hour: __package_update_index --maxage 3600 --type apt - # same as avove (on apt-type systems): + # same as above (on apt-type systems): __package_update_index --maxage 3600 AUTHORS From 179c5a2dfee051dcac544b3070a0e8fbfea98494 Mon Sep 17 00:00:00 2001 From: Thomas Eckert Date: Tue, 30 Jan 2018 13:16:29 +0100 Subject: [PATCH 3/7] __package_update_index: optional `--maxage `-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 --- .../__package_update_index/explorer/currage | 15 ++++++++++++++ .../__package_update_index/gencode-remote | 20 ++++++++++++++++++- .../conf/type/__package_update_index/man.rst | 10 +++++++++- .../__package_update_index/parameter/optional | 1 + 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 cdist/conf/type/__package_update_index/explorer/currage diff --git a/cdist/conf/type/__package_update_index/explorer/currage b/cdist/conf/type/__package_update_index/explorer/currage new file mode 100644 index 00000000..bd53a789 --- /dev/null +++ b/cdist/conf/type/__package_update_index/explorer/currage @@ -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 diff --git a/cdist/conf/type/__package_update_index/gencode-remote b/cdist/conf/type/__package_update_index/gencode-remote index 20beed5b..d84e7953 100755 --- a/cdist/conf/type/__package_update_index/gencode-remote +++ b/cdist/conf/type/__package_update_index/gencode-remote @@ -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 diff --git a/cdist/conf/type/__package_update_index/man.rst b/cdist/conf/type/__package_update_index/man.rst index 454aa05b..ac954faa 100644 --- a/cdist/conf/type/__package_update_index/man.rst +++ b/cdist/conf/type/__package_update_index/man.rst @@ -27,6 +27,9 @@ 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. EXAMPLES -------- @@ -39,10 +42,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 avove (on apt-type systems): + __package_update_index --maxage 3600 AUTHORS ------- -Ricardo Catalinas Jiménez +| Ricardo Catalinas Jiménez +| Thomas Eckert COPYING diff --git a/cdist/conf/type/__package_update_index/parameter/optional b/cdist/conf/type/__package_update_index/parameter/optional index aa80e646..7a0be716 100644 --- a/cdist/conf/type/__package_update_index/parameter/optional +++ b/cdist/conf/type/__package_update_index/parameter/optional @@ -1 +1,2 @@ type +maxage From e31de114e35ee1642d8944d354d58b4b0b46e2b8 Mon Sep 17 00:00:00 2001 From: Thomas Eckert Date: Tue, 30 Jan 2018 13:24:28 +0100 Subject: [PATCH 4/7] __package_update_index: update man-page w/ `--magage` and MESSAGING --- cdist/conf/type/__package_update_index/man.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cdist/conf/type/__package_update_index/man.rst b/cdist/conf/type/__package_update_index/man.rst index ac954faa..b63af654 100644 --- a/cdist/conf/type/__package_update_index/man.rst +++ b/cdist/conf/type/__package_update_index/man.rst @@ -31,6 +31,13 @@ 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 -------- @@ -44,7 +51,7 @@ EXAMPLES # Only update every hour: __package_update_index --maxage 3600 --type apt - # same as avove (on apt-type systems): + # same as above (on apt-type systems): __package_update_index --maxage 3600 AUTHORS From cb21b3679a6f23b2a97e5bb2b7f8c6d19b38fe4c Mon Sep 17 00:00:00 2001 From: Thomas Eckert Date: Wed, 31 Jan 2018 09:22:19 +0100 Subject: [PATCH 5/7] add missing legal boilerplate to explorer --- .../__package_update_index/explorer/currage | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cdist/conf/type/__package_update_index/explorer/currage b/cdist/conf/type/__package_update_index/explorer/currage index bd53a789..543d1b29 100644 --- a/cdist/conf/type/__package_update_index/explorer/currage +++ b/cdist/conf/type/__package_update_index/explorer/currage @@ -1,4 +1,21 @@ -#!/bin/sh -e +#!/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 . os="$("$__explorer/os")" From 6a6fdac25dc56a86f9d4db9b2c1f33d95aefac8c Mon Sep 17 00:00:00 2001 From: Thomas Eckert Date: Wed, 31 Jan 2018 10:37:30 +0100 Subject: [PATCH 6/7] add error-message if OS is unsuppored; fix indentation --- .../__package_update_index/explorer/currage | 39 ++++++------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/cdist/conf/type/__package_update_index/explorer/currage b/cdist/conf/type/__package_update_index/explorer/currage index 543d1b29..c2742b6d 100644 --- a/cdist/conf/type/__package_update_index/explorer/currage +++ b/cdist/conf/type/__package_update_index/explorer/currage @@ -1,32 +1,17 @@ -#!/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 . +#!/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 - ;; + 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 From fa91dbfcdbb57673ca87090b8a3834d6cbffd816 Mon Sep 17 00:00:00 2001 From: Thomas Eckert Date: Wed, 31 Jan 2018 11:08:39 +0100 Subject: [PATCH 7/7] (re-) copyright msg --- .../__package_update_index/explorer/currage | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/cdist/conf/type/__package_update_index/explorer/currage b/cdist/conf/type/__package_update_index/explorer/currage index c2742b6d..cd042bd5 100644 --- a/cdist/conf/type/__package_update_index/explorer/currage +++ b/cdist/conf/type/__package_update_index/explorer/currage @@ -1,4 +1,21 @@ -#!/bin/sh -e +#!/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 . os="$("$__explorer/os")"