esac
}
pupdate() {
- local s f; [[ $EUID != 0 ]] && s=sudo
+ local now t s f cachetime limittime; [[ $EUID != 0 ]] && s=sudo
# update package list if its more than an 2 hours old
f=/var/cache/apt/pkgcache.bin
- if [[ ! -r $f ]] \
- || (( $(( $(date +%s) - $(stat -c %Y $f ) )) > 60*60*2 )); then
+ if [[ -r $f ]]; then
+ cachetime=$(stat -c %Y $f )
+ else
+ cachetime=0
+ fi
+ now=$(date +%s)
+ limittime=$(( now - 60*60*2 ))
+ for f in /etc/apt/sources.list /etc/apt/sources.list.d/*.list; do
+ if [[ -r $f ]]; then
+ t=$(stat -c %Y $f )
+ if (( t > limittime )); then
+ limittime=$t
+ fi
+ fi
+ done
+ if (( cachtime > limittime )); then
$s apt-get update
fi
}