contrib/paclog-pkglist: rework as bash wrapping awk

Avoid some pain in awk's limited handling of command line arguments by
wrapping this in a Bash script. We also default to
@localstatedir@/log/pacman.log when no args are specified, meaning that
-h or --help is required to get the help message.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dave Reisner 2011-07-17 11:04:03 -04:00 committed by Dan McGee
parent 0b92d9ed9c
commit 3294039a00
2 changed files with 23 additions and 10 deletions

View File

@ -2,6 +2,7 @@ OURSCRIPTS = \
bacman \
pacdiff \
paclist \
paclog-pkglist \
pacscripts \
pacsearch
@ -13,7 +14,7 @@ EXTRA_DIST = \
PKGBUILD.vim \
bacman.in \
bash_completion.in \
paclog-pkglist \
paclog-pkglist.in \
pacdiff.in \
paclist.in \
pacscripts.in \
@ -51,6 +52,7 @@ bacman: $(srcdir)/bacman.in
bash_completion: $(srcdir)/bash_completion.in
pacdiff: $(srcdir)/pacdiff.in
paclist: $(srcdir)/paclist.in
paclog-pkglist: $(srcdir)/paclog-pkglist.in
pacscripts: $(srcdir)/pacscripts.in
pacsearch: $(srcdir)/pacsearch.in
pactree: $(srcdir)/pactree.in

View File

@ -1,4 +1,4 @@
#!/bin/awk -f
#!/bin/bash
#
# paclog-pkglist - Parse a log file into a list of currently installed packages
#
@ -17,14 +17,23 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
BEGIN {
if (ARGC < 2) {
printf "usage: log2pkglist <pacman log>\n"
printf "example: log2pkglist /var/log/pacman.log\n"
exit
}
}
export TEXTDOMAIN='pacman'
export TEXTDOMAINDIR='/usr/share/locale'
declare logfile=${1:-@localstatedir@/log/pacman.log}
if [[ $1 ]]; then
if [[ $1 = -@(h|-help) ]]; then
printf 'usage: %s [pacman log]\n' "${0##*/}"
printf 'example: %s @localstatedir@/log/pacman.log\n' "${0##*/}"
printf '\ndefaults to: @localstatedir@/log/pacman.log\n'
exit 0
elif [[ ! -e $logfile ]]; then
printf $"target not found: %s\n" "$1"
exit 1
fi
fi
<"$logfile" awk '
{
action = $3
pkgname = $4
@ -54,4 +63,6 @@ END {
printf "%s %s\n",i,pkg[i]
}
}
}
}' | sort
# vim: set ts=2 sw=2 noet: