scripts: add -q/--quiet option to repo-add and repo-remove

They are pretty noisy scripts in their normal course of operations, so allow
all messages to be squashed except for warning and error messages with this
new flag.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2008-05-09 19:26:57 -05:00
parent 502645c0e3
commit 2edd01a973
3 changed files with 33 additions and 10 deletions

View file

@ -16,9 +16,9 @@ repo-add - package database maintenance utility
Synopsis Synopsis
-------- --------
repo-add <path-to-db> <package> ... repo-add [-q] <path-to-db> <package> ...
repo-remove <path-to-db> <packagename> ... repo-remove [-q] <path-to-db> <packagename> ...
Description Description
@ -34,6 +34,13 @@ specified on the command line. Multiple packages to remove can be specified
on the command line. on the command line.
Options
-------
*-q, \--quiet*::
Force this program to keep quiet and run silent except for warning and
error messages.
See Also See Also
-------- --------
linkman:makepkg[8], linkman:pacman[8] linkman:makepkg[8], linkman:pacman[8]

View file

@ -3,7 +3,7 @@
# repo-add - add a package to a given repo database file # repo-add - add a package to a given repo database file
# @configure_input@ # @configure_input@
# #
# Copyright (c) 2006 Aaron Griffin <aaron@archlinux.org> # Copyright (c) 2006-2008 Aaron Griffin <aaron@archlinux.org>
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -25,17 +25,20 @@ export TEXTDOMAINDIR='@localedir@'
myver='@PACKAGE_VERSION@' myver='@PACKAGE_VERSION@'
confdir='@sysconfdir@' confdir='@sysconfdir@'
QUIET=0
REPO_DB_FILE="" REPO_DB_FILE=""
# ensure we have a sane umask set # ensure we have a sane umask set
umask 0022 umask 0022
msg() { msg() {
[ $QUIET -ne 0 ] && return
local mesg=$1; shift local mesg=$1; shift
printf "==> ${mesg}\n" "$@" >&1 printf "==> ${mesg}\n" "$@" >&1
} }
msg2() { msg2() {
[ $QUIET -ne 0 ] && return
local mesg=$1; shift local mesg=$1; shift
printf " -> ${mesg}\n" "$@" >&1 printf " -> ${mesg}\n" "$@" >&1
} }
@ -53,17 +56,20 @@ error() {
# print usage instructions # print usage instructions
usage() { usage() {
printf "repo-add (pacman) %s\n\n" "$myver" printf "repo-add (pacman) %s\n\n" "$myver"
printf "$(gettext "Usage: %s <path-to-db> <package> ...\n\n")" "$0" printf "$(gettext "Usage: %s [-q] <path-to-db> <package> ...\n\n")" "$0"
printf "$(gettext "\ printf "$(gettext "\
repo-add will update a package database by reading a package file.\n\ repo-add will update a package database by reading a package file.\n\
Multiple packages to add can be specified on the command line.\n\n")" Multiple packages to add can be specified on the command line.\n\n")"
printf "$(gettext "\
The -q/--quiet flag will force this program to run silently except\n\
in the case of warnings or errors.\n\n")"
echo "$(gettext "Example: repo-add /path/to/repo.db.tar.gz pacman-3.0.0.pkg.tar.gz")" echo "$(gettext "Example: repo-add /path/to/repo.db.tar.gz pacman-3.0.0.pkg.tar.gz")"
} }
version() { version() {
printf "repo-add (pacman) %s\n" "$myver" printf "repo-add (pacman) %s\n" "$myver"
printf "$(gettext "\ printf "$(gettext "\
Copyright (C) 2006 Aaron Griffin <aaron@archlinux.org>.\n\n\ Copyright (C) 2006-2008 Aaron Griffin <aaron@archlinux.org>.\n\n\
This is free software; see the source for copying conditions.\n\ This is free software; see the source for copying conditions.\n\
There is NO WARRANTY, to the extent permitted by law.\n")" There is NO WARRANTY, to the extent permitted by law.\n")"
} }
@ -231,7 +237,7 @@ db_write_entry()
if db_write_delta "$delta"; then if db_write_delta "$delta"; then
msg2 "$(gettext "Added delta '%s'")" "$(basename "$delta")" msg2 "$(gettext "Added delta '%s'")" "$(basename "$delta")"
else else
msg2 "$(gettext "Could not add delta '%s'")" "$(basename "$delta")" warning "$(gettext "Could not add delta '%s'")" "$(basename "$delta")"
fi fi
fi fi
done done
@ -295,6 +301,8 @@ for arg in "$@"; do
if [ "$arg" == "--force" -o "$arg" == "-f" ]; then if [ "$arg" == "--force" -o "$arg" == "-f" ]; then
warning "$(gettext "the -f and --force options are no longer recognized")" warning "$(gettext "the -f and --force options are no longer recognized")"
msg2 "$(gettext "use options=(force) in the PKGBUILD instead")" msg2 "$(gettext "use options=(force) in the PKGBUILD instead")"
elif [ "$arg" == "--quiet" -o "$arg" == "-q" ]; then
QUIET=1
elif [ -z "$REPO_DB_FILE" ]; then elif [ -z "$REPO_DB_FILE" ]; then
REPO_DB_FILE=$(readlink -f "$arg") REPO_DB_FILE=$(readlink -f "$arg")
if ! test_repo_db_file; then if ! test_repo_db_file; then

View file

@ -3,7 +3,7 @@
# repo-remove - remove a package entry from a given repo database file # repo-remove - remove a package entry from a given repo database file
# @configure_input@ # @configure_input@
# #
# Copyright (c) 2002-2007 by Judd Vinet <jvinet@zeroflux.org> # Copyright (c) 2007-2008 Dan McGee <dan@archlinux.org>
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -25,14 +25,17 @@ export TEXTDOMAINDIR='@localedir@'
myver='@PACKAGE_VERSION@' myver='@PACKAGE_VERSION@'
confdir='@sysconfdir@' confdir='@sysconfdir@'
QUIET=0
REPO_DB_FILE="" REPO_DB_FILE=""
msg() { msg() {
[ $QUIET -ne 0 ] && return
local mesg=$1; shift local mesg=$1; shift
printf "==> ${mesg}\n" "$@" >&1 printf "==> ${mesg}\n" "$@" >&1
} }
msg2() { msg2() {
[ $QUIET -ne 0 ] && return
local mesg=$1; shift local mesg=$1; shift
printf " -> ${mesg}\n" "$@" >&1 printf " -> ${mesg}\n" "$@" >&1
} }
@ -50,18 +53,21 @@ error() {
# print usage instructions # print usage instructions
usage() { usage() {
printf "$(gettext "repo-remove %s\n\n")" $myver printf "$(gettext "repo-remove %s\n\n")" $myver
printf "$(gettext "usage: %s <path-to-db> <packagename> ...\n\n")" "$0" printf "$(gettext "usage: %s [-q] <path-to-db> <packagename> ...\n\n")" "$0"
printf "$(gettext "\ printf "$(gettext "\
repo-remove will update a package database by removing the package name\n\ repo-remove will update a package database by removing the package name\n\
specified on the command line from the given repo database. Multiple\n\ specified on the command line from the given repo database. Multiple\n\
packages to remove can be specified on the command line.\n\n")" packages to remove can be specified on the command line.\n\n")"
printf "$(gettext "\
The -q/--quiet flag will force this program to run silently except\n\
in the case of warnings or errors.\n\n")"
echo "$(gettext "Example: repo-remove /path/to/repo.db.tar.gz kernel26")" echo "$(gettext "Example: repo-remove /path/to/repo.db.tar.gz kernel26")"
} }
version() { version() {
printf "repo-remove (pacman) %s\n" "$myver" printf "repo-remove (pacman) %s\n" "$myver"
printf "$(gettext "\ printf "$(gettext "\
Copyright (C) 2002-2007 Judd Vinet <jvinet@zeroflux.org>.\n\n\ Copyright (c) 2007-2008 Dan McGee <dan@archlinux.org>.\n\n\
This is free software; see the source for copying conditions.\n\ This is free software; see the source for copying conditions.\n\
There is NO WARRANTY, to the extent permitted by law.\n")" There is NO WARRANTY, to the extent permitted by law.\n")"
} }
@ -140,7 +146,9 @@ gstmpdir=$(mktemp -d /tmp/repo-remove.XXXXXXXXXX) || (\
success=0 success=0
# parse arguments # parse arguments
for arg in "$@"; do for arg in "$@"; do
if [ -z "$REPO_DB_FILE" ]; then if [ "$arg" == "--quiet" -o "$arg" == "-q" ]; then
QUIET=1
elif [ -z "$REPO_DB_FILE" ]; then
REPO_DB_FILE=$(readlink -f "$arg") REPO_DB_FILE=$(readlink -f "$arg")
if ! test_repo_db_file; then if ! test_repo_db_file; then
error "$(gettext "Repository file '%s' is not a proper pacman database.")\n" "$REPO_DB_FILE" error "$(gettext "Repository file '%s' is not a proper pacman database.")\n" "$REPO_DB_FILE"