Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 88 lines (74 sloc) 1.83 KB
#!/bin/bash
set -e
PACDIR=/home/pacman
function usage {
echo "Usage: pkglist [OPTIONS]"
echo " -L[nmtv] list packages (n: native; m: foreign; v: verbose; t: install time;)"
echo " -C clean global pacman;"
echo " -P save local packages;"
echo " -U update local pacman;"
exit 2
}
creset="\e[0m"
cpurple="\e[1;35m"
cgray="\e[0;37m"
cbold="\e[1m"
format="$cpurple%n$creset"
format_time=""
while getopts "hCPULmntv" opt; do
case $opt in
h) operation=usage;;
C) operation=clean;;
P) operation=save_packages;;
U) operation=update_repo;;
L) operation=list_packages;;
v) format="$format: $cgray$cbold%d$creset $cgray(%u)$creset";;
t) format_time="%l ";;
n) filter="n";;
m) filter="m";;
esac
done
function clean {
if [[ ! -n $(pacman -Qdt) ]]; then
echo "No orphans to remove."
else
sudo pacman -Rs $(pacman -Qdtq)
fi
}
function update_repo {
if [ $2 ]; then
clean_repo $2 1
exit;
fi
clean_repo main 1
clean_repo abs 1
# Sync pacman local db
sudo pacman --config=$PACDIR/pacman.conf -Sy
}
function clean_repo {
cd $PACDIR/$1
dbfile="naspeh-$1.db"
sudo rm -f $dbfile*
sudo paccache -rvu -c. -k0
sudo paccache -rv -c. -k2
if [ $2 ]; then
sudo repo-add "$dbfile.tar.gz" *.pkg.tar.xz
fi
}
function save_packages {
pkglist -Ln > $PACDIR/main.txt
pkglist -Lm > $PACDIR/abs.txt
pacman -Q > $PACDIR/all.txt
clean_repo abs
sudo rsync -av /var/cache/pacman/pkg/ $PACDIR/main/
clean_repo main
}
function list_packages {
list=$(comm -23 <(pacman -Qeq$filter) <(pacman -Qgq base base-devel | sort))
expac -Q -t '%Y-%m-%d %H:%M' "$format_time$format" $(echo $list)
}
if [ $operation ]; then
$operation "$@"
else
usage
fi