summaryrefslogtreecommitdiff
path: root/src/abslibre-tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/abslibre-tools')
-rwxr-xr-xsrc/abslibre-tools/libredbdiff81
1 files changed, 55 insertions, 26 deletions
diff --git a/src/abslibre-tools/libredbdiff b/src/abslibre-tools/libredbdiff
index 5ef1029..8bcc6d9 100755
--- a/src/abslibre-tools/libredbdiff
+++ b/src/abslibre-tools/libredbdiff
@@ -150,18 +150,6 @@ initialize() {
fi
}
-repo_test() {
- for repo in "${repos[@]}" ; do
- if [[ "$repo" == "$1" ]] ; then
- found=1
- return 0
- fi
- done
- if [[ "$found" != 1 ]] ; then
- die "The specified Parabola repo \"%s\" cannot be compared. It's not in the list of repos in the configuration variable \"repos\"." "$1"
- fi
-}
-
compare_pkgs() {
local cmp
if [[ -n "${ver_arch[$pkgname]}" ]] ; then
@@ -212,7 +200,9 @@ print_cmp() {
}
usage() {
- print "Usage: %q [-n|-h]" "$cmd"
+ print "Usage: sudo %q" "$cmd"
+ print " or: %q -n [REPO]" "$cmd"
+ print " or: %q -h" "$cmd"
print 'Show packages that need to be updated from Arch repositories.'
echo
prose "Compares packages in Parabola repositories. Packages from
@@ -225,6 +215,12 @@ usage() {
flag to not download anything, but to compare already downloaded
files."
echo
+ prose "In the compare mode (if the \`-n\` flag is given), by default it
+ will iterate over each of the configured repositories, prefixing
+ each section with a line in the format \`[REPO]\`. However, if a
+ REPO is specified on the command line, it scan for packages only
+ in that repository, and no \`[REPO]\` line will be printed."
+ echo
print 'Options:'
flag '-n' "Don't update anything, just compare already downloaded files."
flag '-h' 'Show this message'
@@ -242,28 +238,57 @@ usage() {
}
main() {
- local UPDATE=1
- local arg
- local repo_arg
-
- for arg in "$@"; do
+ local args arg mode=update badargs=false
+ args="$(getopt -n "$cmd" -o nh -l noupdate,help -- "$@")" || badargs=true
+ eval "set -- $args"
+ while [[ $# -gt 0 ]]; do
+ arg=$1
+ shift
case "$arg" in
-n|--noupdate)
- UPDATE=0
+ mode=compare
;;
-h|--help)
usage
return 0
;;
- *)
- repo_test "$arg"
- repo_arg="$arg"
+ --)
break
;;
esac
done
+ if $badargs; then
+ usage >&2
+ return 2
+ fi
+
+ case $mode in
+ update)
+ if [[ $# -gt 0 ]]; then
+ print "%s: found non-flag arguments; a repo list may only be specified with the -n flag: %s" "$cmd" "$*" >&2
+ usage >&2
+ return 2
+ fi
+ main_update
+ ;;
+ compare)
+ if [[ $# -gt 1 ]]; then
+ print "%s: found too many non-flag arguments; only one repo may be specified: %s" "$cmd" "$*" >&2
+ usage >&2
+ return 2
+ fi
+ if [[ $# = 1 ]]; then
+ if ! in_array "$1" "${repos[@]}"; then
+ die "The specified Parabola repo \"%s\" cannot be compared. It's not in the list of repos in the configuration variable \"repos\"." "$1"
+ fi
+ fi
+ main_compare "$@"
+ ;;
+ esac
+}
- if (( UPDATE )) ; then
+main_update() {
+ if true; then
if [[ $EUID != 0 ]]; then
die "To initialize %s or update %s pacman databases, %s must be run as root (without arguments). Nothing done." \
"$name" \
@@ -305,7 +330,11 @@ main() {
msg "%s pacman databases are updated. %s is ready. Run %q -n to print results." \
"$name" "$name" "$cmd"
return 0
- else
+ fi
+}
+
+main_compare() {
+ if true; then
check_vars libredbdiff statedir repos || exit 1
filenotfound "$dbpath_prbl/sync/libre.db"
@@ -332,8 +361,8 @@ main() {
die "expac command to get Parabola package data has failed. Exiting."
chmod 777 "$prbl_packages_tmp"
- if [[ -n "$repo_arg" ]] ; then
- print_cmp "$repo_arg"
+ if [[ $# == 1 ]]; then
+ print_cmp "$1"
else
for repo in "${repos[@]}" ; do
echo "[$repo]"