From f74a06a257f07a6b9cfc6b73685d70d5cd44c830 Mon Sep 17 00:00:00 2001 From: Ander Punnar Date: Mon, 1 Nov 2021 22:50:31 +0200 Subject: [PATCH 1/5] POC: add smart index updating --- cdist/conf/type/__package_apt/explorer/index | 9 +++++++++ cdist/conf/type/__package_apt/gencode-remote | 12 +++--------- 2 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 cdist/conf/type/__package_apt/explorer/index diff --git a/cdist/conf/type/__package_apt/explorer/index b/cdist/conf/type/__package_apt/explorer/index new file mode 100644 index 00000000..58215eff --- /dev/null +++ b/cdist/conf/type/__package_apt/explorer/index @@ -0,0 +1,9 @@ +#!/bin/sh -e + +if [ ! -d /var/lib/apt/lists ] \ + || [ -n "$( find /etc/apt -mindepth 1 -cnewer /var/lib/apt/lists )" ] \ + || [ ! -f /var/cache/apt/pkgcache.bin ] \ + || [ "$( stat --format %Y /var/cache/apt/pkgcache.bin )" -lt "$( date +%s -d '-1 day' )" ] +then + echo 'update' +fi diff --git a/cdist/conf/type/__package_apt/gencode-remote b/cdist/conf/type/__package_apt/gencode-remote index 79c0d9d3..ee9b3b5a 100755 --- a/cdist/conf/type/__package_apt/gencode-remote +++ b/cdist/conf/type/__package_apt/gencode-remote @@ -92,15 +92,9 @@ case "$state_should" in # See more: ticket #861 # https://code.ungleich.ch/ungleich-public/cdist/-/issues/861 apt_opts="-o Acquire::AllowReleaseInfoChange::Suite=true -o Acquire::AllowReleaseInfoChange::Version=true" - - # following is bit ugly, but important hack. - # due to how cdist config run works, there isn't - # currently better way to do it :( - cat << EOF -if [ ! -f /var/cache/apt/pkgcache.bin ] || [ "\$( stat --format %Y /var/cache/apt/pkgcache.bin )" -lt "\$( date +%s -d '-1 day' )" ] -then echo apt-get $apt_opts update > /dev/null 2>&1 || true -fi -EOF + if [ "$(cat "$__object/explorer/index")" = 'update' ]; then + echo "apt-get $apt_opts update || true" + fi if [ -n "$version" ]; then name="${name}=${version}" fi From e24165304c10950385195866f0aa20756d979f24 Mon Sep 17 00:00:00 2001 From: Ander Punnar Date: Mon, 1 Nov 2021 22:58:12 +0200 Subject: [PATCH 2/5] touch /var/lib/apt/lists to make it newer --- cdist/conf/type/__package_apt/gencode-remote | 1 + 1 file changed, 1 insertion(+) diff --git a/cdist/conf/type/__package_apt/gencode-remote b/cdist/conf/type/__package_apt/gencode-remote index ee9b3b5a..4508f249 100755 --- a/cdist/conf/type/__package_apt/gencode-remote +++ b/cdist/conf/type/__package_apt/gencode-remote @@ -93,6 +93,7 @@ case "$state_should" in # https://code.ungleich.ch/ungleich-public/cdist/-/issues/861 apt_opts="-o Acquire::AllowReleaseInfoChange::Suite=true -o Acquire::AllowReleaseInfoChange::Version=true" if [ "$(cat "$__object/explorer/index")" = 'update' ]; then + echo 'touch /var/lib/apt/lists' echo "apt-get $apt_opts update || true" fi if [ -n "$version" ]; then From e7d8fb874d38699ef579ae54410fdcbb5ee1e296 Mon Sep 17 00:00:00 2001 From: Ander Punnar Date: Mon, 1 Nov 2021 23:00:15 +0200 Subject: [PATCH 3/5] do not create it as file, it must be dir --- cdist/conf/type/__package_apt/gencode-remote | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__package_apt/gencode-remote b/cdist/conf/type/__package_apt/gencode-remote index 4508f249..2a86e37f 100755 --- a/cdist/conf/type/__package_apt/gencode-remote +++ b/cdist/conf/type/__package_apt/gencode-remote @@ -93,7 +93,7 @@ case "$state_should" in # https://code.ungleich.ch/ungleich-public/cdist/-/issues/861 apt_opts="-o Acquire::AllowReleaseInfoChange::Suite=true -o Acquire::AllowReleaseInfoChange::Version=true" if [ "$(cat "$__object/explorer/index")" = 'update' ]; then - echo 'touch /var/lib/apt/lists' + echo 'if [ -d /var/lib/apt/lists ]; then touch /var/lib/apt/lists; fi' echo "apt-get $apt_opts update || true" fi if [ -n "$version" ]; then From 4ddbf1e4114499a37e69cee28ebb23f76670a586 Mon Sep 17 00:00:00 2001 From: Ander Punnar Date: Mon, 1 Nov 2021 23:10:49 +0200 Subject: [PATCH 4/5] add comment about touching --- cdist/conf/type/__package_apt/gencode-remote | 1 + 1 file changed, 1 insertion(+) diff --git a/cdist/conf/type/__package_apt/gencode-remote b/cdist/conf/type/__package_apt/gencode-remote index 2a86e37f..ad53c2ea 100755 --- a/cdist/conf/type/__package_apt/gencode-remote +++ b/cdist/conf/type/__package_apt/gencode-remote @@ -93,6 +93,7 @@ case "$state_should" in # https://code.ungleich.ch/ungleich-public/cdist/-/issues/861 apt_opts="-o Acquire::AllowReleaseInfoChange::Suite=true -o Acquire::AllowReleaseInfoChange::Version=true" if [ "$(cat "$__object/explorer/index")" = 'update' ]; then + # make /var/lib/apt/lists newer because apt-get update might not always do this echo 'if [ -d /var/lib/apt/lists ]; then touch /var/lib/apt/lists; fi' echo "apt-get $apt_opts update || true" fi From 50186d13c9f8b23a66fe3e1a131ae77704e2e18f Mon Sep 17 00:00:00 2001 From: Ander Punnar Date: Tue, 2 Nov 2021 11:33:57 +0200 Subject: [PATCH 5/5] change find args --- cdist/conf/type/__package_apt/explorer/index | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__package_apt/explorer/index b/cdist/conf/type/__package_apt/explorer/index index 58215eff..af18d503 100644 --- a/cdist/conf/type/__package_apt/explorer/index +++ b/cdist/conf/type/__package_apt/explorer/index @@ -1,7 +1,7 @@ #!/bin/sh -e if [ ! -d /var/lib/apt/lists ] \ - || [ -n "$( find /etc/apt -mindepth 1 -cnewer /var/lib/apt/lists )" ] \ + || [ -n "$( find /etc/apt -newer /var/lib/apt/lists )" ] \ || [ ! -f /var/cache/apt/pkgcache.bin ] \ || [ "$( stat --format %Y /var/cache/apt/pkgcache.bin )" -lt "$( date +%s -d '-1 day' )" ] then