My last csh script is gone, replaced by org-fied bash

My oldest extant operational script was the one I used to back up my files at home. It’s now gone and has become a small literate programming (you be the judge) example, complete with definition of key environment variables in org-mode data blocks which are then defined in bash via eval, and in-line collection of run results (via :results prepend)

https://github.com/eludom/dotfiles/blob/e407058bd499e9a89a03774bd695c49e33a65860/bin/backup.org

Advertisements

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.