conky-config/scripts/pacman_stats

36 lines
898 B
Plaintext
Raw Permalink Normal View History

#! /bin/bash
stat_file=/tmp/.conky_pacman
log_file=/var/log/pacman.log
get_log_date() {
sed -n "s/\[\(.*\)\] \[PACMAN\] $1/\1/p" \
/var/log/pacman.log | \
tail -1 \
| { read -r f; date -d "$f" +%m-%d-%Y; }
}
write_stats() {
now=$(date +%s)
last_upgrade=$(get_log_date "starting full system upgrade")
last_sync=$(get_log_date "synchronizing package lists")
tot=$(pacman -Qq | wc -l)
exp=$(pacman -Qeq | wc -l)
out=$(pacman -Quq | wc -l)
orp=$(pacman -Qdtq | wc -l)
loc=$(pacman -Qmq | wc -l)
echo "$now" "$last_upgrade" "$last_sync" "$tot" "$exp" "$out" \
"$orp" "$loc" > "$stat_file"
}
if [[ -f "$stat_file" ]]; then
last_pacman_update=$(stat -c %Y "$log_file")
last_stat_update=$(awk '{ print $1 }' "$stat_file")
if (( last_pacman_update > last_stat_update )); then
write_stats
fi
else
write_stats
fi