bin/pams

103 lines
2.4 KiB
Bash
Executable File

#!/bin/sh
# pams - the posix aur management script
# simple script for interacting with the aur
# options:
# -S - synchronize list of aur packages.
# -a pkg_name - audit a specific package's pkgbuild.
# -d pkg_name - downloads a specific package from the aur to $aur and shows the pkgbuild file.
# -i pkg_name - install downloaded packages using the 'makepkg -si' command.
# -r pkg_name - removes package from the ~/aur directory
# -s search_term - list packages with the search team in the title.
# -u pkg_name - updates a package.
# error messages
err_usage() {
echo "usage: [-S | -a pkg_name | -d pkg_name | -i pkg_name | -r pkg_name | -s search_term]"
exit 1
}
err_add_args() {
echo "this flag requires an additional argument"
exit 1
}
audit() {
less "$aur"/"$1"/PKGBUILD
}
download() {
mkdir "$aur" 2>/dev/null
cd "$aur" || exit
echo downloading "$1"
git clone https://aur.archlinux.org/"$1".git 2>/dev/null
audit "$1"
}
# main program
if [ $# -eq 0 ]; then
err_usage
else
aur="$HOME/aur"
case "$1" in
-S) mkdir "$aur" 2>/dev/null
curl https://aur.archlinux.org/packages.gz \
--silent --output - \
| gunzip > "$aur"/aurlist
;;
-a) if [ $# -ne 2 ]; then
err_add_args
else
audit "$2"
fi
;;
-d) if [ $# -ne 2 ]; then
err_add_args
else
download "$2"
fi
;;
-i) if [ $# -ne 2 ]; then
err_add_args
else
cd "$aur"/"$2" 2>/dev/null || (echo "package not downloaded" && download "$2")
cd "$aur"/"$2"
makepkg -si
fi
;;
-r) if [ $# -ne 2 ]; then
err_add_args
else
echo "deleting $aur/$2"
rm -rf "$aur/$2"
fi
;;
-s) if [ $# -ne 2 ]; then
err_add_args
else
grep "$2" "$aur"/aurlist
fi
;;
-u) if [ $# -ne 2 ]; then
err_add_args
else
rm -rf "{$aur/$2:?}"
pams -d "$2"
pams -i "$2"
fi
;;
*) err_usage
esac
fi