From 1461245d1619f57b878557672b869adc97e0a0a2 Mon Sep 17 00:00:00 2001 From: contradict Date: Sat, 30 Oct 2021 16:03:25 -0700 Subject: [PATCH 1/2] Handle missing apt lists On a newly imaged system, /var/lib/apt/lists may not exist. Check for this case before comparing dates to the sources. --- cdist/conf/type/__apt_update_index/gencode-remote | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__apt_update_index/gencode-remote b/cdist/conf/type/__apt_update_index/gencode-remote index 70b5971094..c591ea39c4 100755 --- a/cdist/conf/type/__apt_update_index/gencode-remote +++ b/cdist/conf/type/__apt_update_index/gencode-remote @@ -20,7 +20,7 @@ # run 'apt-get update' if anything in /etc/apt is newer then /var/lib/apt/lists cat << DONE -if find /etc/apt -mindepth 1 -cnewer /var/lib/apt/lists | grep . > /dev/null; then +if [ ! -d /var/lib/apt/lists ] || { find /etc/apt -mindepth 1 -cnewer /var/lib/apt/lists | grep . > /dev/null; }; then apt-get update || apt-get update fi DONE From 4a529547eeba5bd744f104919a0e925f987eeb15 Mon Sep 17 00:00:00 2001 From: contradict Date: Mon, 1 Nov 2021 08:46:16 -0700 Subject: [PATCH 2/2] Make date condition easier to read. --- cdist/conf/type/__apt_update_index/gencode-remote | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cdist/conf/type/__apt_update_index/gencode-remote b/cdist/conf/type/__apt_update_index/gencode-remote index c591ea39c4..f09530dd08 100755 --- a/cdist/conf/type/__apt_update_index/gencode-remote +++ b/cdist/conf/type/__apt_update_index/gencode-remote @@ -20,7 +20,8 @@ # run 'apt-get update' if anything in /etc/apt is newer then /var/lib/apt/lists cat << DONE -if [ ! -d /var/lib/apt/lists ] || { find /etc/apt -mindepth 1 -cnewer /var/lib/apt/lists | grep . > /dev/null; }; then +newer_sources=\$(find /etc/apt -mindepth 1 -cnewer /var/lib/apt/lists) +if [ ! -d /var/lib/apt/lists ] || [ -n "${newer_sources}" ]; then apt-get update || apt-get update fi DONE