42 lines
976 B
Bash
42 lines
976 B
Bash
|
#!/bin/bash
|
||
|
|
||
|
# pkglistbu.sh
|
||
|
|
||
|
# Automatically back up package lists to a file
|
||
|
# intended to run as a cron/timer job
|
||
|
|
||
|
pluser=dthurstenson
|
||
|
pldate=`date +%Y%m%d`
|
||
|
pldir=/home/$pluser/.pkglists/
|
||
|
plist=$pldir$HOSTNAME.$pldate.list
|
||
|
plog=$pldir$HOSTNAME.list.log
|
||
|
platest=$(ls -t -d -1 $pldir$HOSTNAME*.list | head -1)
|
||
|
|
||
|
echo Last list: $platest
|
||
|
|
||
|
echo Getting package list for: $HOSTNAME
|
||
|
|
||
|
pacman -Qqen > $plist
|
||
|
chown $pluser:$pluser $plist
|
||
|
|
||
|
echo Comparing $platest to $plist
|
||
|
|
||
|
# If $platest differs from $plist
|
||
|
if ! cmp $platest $plist >/dev/null 2>&1
|
||
|
then
|
||
|
# Add diff to log
|
||
|
printf "\n\n=== $(date +%m.%d.%Y) ==\n" >> $plog
|
||
|
diff $platest $plist | grep '[<>]' >> $plog
|
||
|
|
||
|
echo "Adding and commiting changes to git repo"
|
||
|
git -C /home/$pluser add $pldir
|
||
|
git -C /home/$pluser commit -m "Pkglistbu auto commit for $date"
|
||
|
|
||
|
echo Done: Package list stored at: $plist
|
||
|
else
|
||
|
echo $platest and $plist are identical!
|
||
|
echo "Package list hasn't changed since last run"
|
||
|
rm $plist
|
||
|
echo Done.
|
||
|
fi
|