Limiting apt-get update times

I’d like to limit apt-get upate to actually only go out and update if it hasn’t been done in the last T time (seconds, horus, etc), ‘case everything I install seems to want do an apt-get update first:

From http://askubuntu.com/questions/410247/how-to-know-last-time-apt-get-was-executed

stat /var/cache/apt/pkgcache.bin

so we could do something like

howOften=600

sourcesUpdate=false
if [[ /etc/apt/sources.list -nt /var/cache/apt/pkgcache.bin  ]]; then
  sourcesUpdate=true
  echo sources updated
  ls -lt /etc/apt/sources.list /var/cache/apt/pkgcache.bin
fi

cmd="find /var/cache/apt/pkgcache.bin -mmin -${howOften}"
aptGetRun=`$cmd`

needToUpdate=false
if [ -z "${aptGetRun}" ]; then
  echo need to update
  ls -l /var/cache/apt/pkgcache.bin      
  needToUpdate=true
fi

if $needToUpdate || $sourcesUpdate; then
     sudo apt-get update
else
     echo no update
fi

It needs some cleanup, but it could be dropped as a shell wrapper in front of /usr/bin/apt … pick off apt-get update, execute this logic or pass $* to the real binary… or possibly incorporated into the apt-get source with a new flag howOften.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s