POC: add smart index updating

This commit is contained in:
ander 2021-11-01 22:50:31 +02:00
parent 560374a686
commit f74a06a257
No known key found for this signature in database
GPG key ID: 0A2971E562D618F3
2 changed files with 12 additions and 9 deletions

View file

@ -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

View file

@ -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