diff options
Diffstat (limited to 'src/abslibre-tools/libredbdiff')
-rwxr-xr-x | src/abslibre-tools/libredbdiff | 94 |
1 files changed, 46 insertions, 48 deletions
diff --git a/src/abslibre-tools/libredbdiff b/src/abslibre-tools/libredbdiff index b5e6331..07080b7 100755 --- a/src/abslibre-tools/libredbdiff +++ b/src/abslibre-tools/libredbdiff @@ -58,7 +58,7 @@ enablerepo() { createdir() { local dir=$1 - if ! [[ -d "$dir" ]] ; then + if ! [[ -d $dir ]]; then msg "Creating directory %q" "$dir" mkdir -- "$dir" || die "Failed to create directory %q. Exiting." "$dir" fi @@ -66,15 +66,15 @@ createdir() { # {{ A -lt B }} is like [ A -lt B ], but for pacman version numbers {{() { - [[ $# = 4 ]] || panic - [[ $4 = '}}' ]] || panic - local a=$1 - local op=$2 - local b=$3 - - local cmp - cmp="$(vercmp "$a" "$b")" || die "vercmp failed" - [ "$cmp" "$op" 0 ] + [[ $# == 4 ]] || panic + [[ $4 == '}}' ]] || panic + local a=$1 + local op=$2 + local b=$3 + + local cmp + cmp="$(vercmp "$a" "$b")" || die "vercmp failed" + [ "$cmp" "$op" 0 ] } # Globals: @@ -83,7 +83,7 @@ createdir() { # - ver_arch : a map of pkgname->prbl_pkgver # - provides : a map of pkgname->provides compare_pkgs() { - if [[ -n "${ver_arch[$pkgname]:-}" ]]; then + if [[ -n ${ver_arch[$pkgname]:-} ]]; then if {{ "${ver_prbl[$pkgname]}" -lt "${ver_arch[$pkgname]}" }}; then printf "$printf_format" \ '=' \ @@ -92,11 +92,11 @@ compare_pkgs() { "${ver_prbl[$pkgname]}" \ "${ver_arch[$pkgname]}" fi - elif [[ -n "${provides[$pkgname]:-}" ]]; then + elif [[ -n ${provides[$pkgname]:-} ]]; then local _provides provide read -r -a _provides <<<"${provides[$pkgname]}" for provide in "${_provides[@]}"; do - if [[ -n "${ver_arch[$provide]:-}" ]]; then + if [[ -n ${ver_arch[$provide]:-} ]]; then if {{ "${ver_prbl[$pkgname]}" -lt "${ver_arch[$provide]}" }}; then printf "$printf_format" \ 'p' \ @@ -123,9 +123,8 @@ compare_pkgs() { print_cmp() { local repo="$1" - < "$prbl_packages_tmp" \ - awk -F/ -v repo="$repo" '$1 == repo {print $2}' | - while read -r pkgname _pkgver _provides ; do + awk <"$prbl_packages_tmp" -F/ -v repo="$repo" '$1 == repo {print $2}' | + while read -r pkgname _pkgver _provides; do ver_prbl["$pkgname"]="$_pkgver" provides["$pkgname"]="$_provides" compare_pkgs @@ -143,17 +142,17 @@ usage() { repository name can be specified as argument to compare only packages in that repository." echo - prose "The default mode of operation requires root, and downloads or + prose 'The default mode of operation requires root, and downloads or updates all necessary files for comparison, but does not compare them. After that mode has been run, run the tool again without - root with the the \`-n\` flag to not download anything, but to - compare the already downloaded files." + root with the the `-n` flag to not download anything, but to + compare the already downloaded files.' echo - prose "In the compare mode (if the \`-n\` flag is given), by default it + 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 + 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." + in that repository, and no `[REPO]` line will be printed.' echo print 'Options:' flag '-n' "Don't update anything, just compare already downloaded files." @@ -177,7 +176,7 @@ usage() { echo print "The line-format for packages is:" printf "\t$printf_format" \ - status parabola_pkgname '[arch_pkgname]' parabola_pkgver arch_pkgver + status parabola_pkgname '[arch_pkgname]' parabola_pkgver arch_pkgver echo print "Where 'status' is one of the characters:" flag '=' "An Arch package with the same pkgname as a Parabola package @@ -199,10 +198,10 @@ main() { arg=$1 shift case "$arg" in - -n|--noupdate) + -n | --noupdate) mode=compare ;; - -h|--help) + -h | --help) usage exit $EXIT_SUCCESS ;; @@ -246,7 +245,7 @@ main() { load_conf libredbdiff.conf statedir repos || exit init_conf - if [[ $# = 1 ]]; then + 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 @@ -263,10 +262,10 @@ main_update() { msg "Generating %s %q" Parabola pacman.conf cp -T /usr/share/pacman/defaults/pacman.conf.x86_64 "$conffile_prbl" sed -r \ - -e "s|/etc/pacman\.d/mirrorlist$|$mirrorlist_prbl|" \ - -e "s|^#?DBPath\s*=.*|DBPath = $dbpath_prbl|" \ - -e "s|^#?Architecture\s*=.*|Architecture = x86_64|" \ - -i "$conffile_prbl" + -e "s|/etc/pacman\.d/mirrorlist$|$mirrorlist_prbl|" \ + -e "s|^#?DBPath\s*=.*|DBPath = $dbpath_prbl|" \ + -e "s|^#?Architecture\s*=.*|Architecture = x86_64|" \ + -i "$conffile_prbl" local repo for repo in multilib {libre,pcr,nonprism}{,-multilib}; do enablerepo "$repo" "$conffile_prbl" @@ -274,19 +273,19 @@ main_update() { msg "Generating %s %q" Arch pacman.conf wget -q \ - -O "$conffile_arch" \ - "https://git.archlinux.org/svntogit/packages.git/plain/pacman/repos/core-x86_64/pacman.conf" || + -O "$conffile_arch" \ + "https://git.archlinux.org/svntogit/packages.git/plain/pacman/repos/core-x86_64/pacman.conf" || die "Failed to download %q. Exiting." "$conffile_arch" sed -r \ - -e "s|/etc/pacman\.d/mirrorlist$|$mirrorlist_arch|" \ - -e "s|^#?DBPath\s*=.*|DBPath = $dbpath_arch|" \ - -e "s|^#?Architecture\s*=.*|Architecture = x86_64|" \ - -i "$conffile_arch" + -e "s|/etc/pacman\.d/mirrorlist$|$mirrorlist_arch|" \ + -e "s|^#?DBPath\s*=.*|DBPath = $dbpath_arch|" \ + -e "s|^#?Architecture\s*=.*|Architecture = x86_64|" \ + -i "$conffile_arch" enablerepo multilib "$conffile_arch" - printf 'Server = %s\n' "$mirror_prbl" > "$mirrorlist_prbl" + printf 'Server = %s\n' "$mirror_prbl" >"$mirrorlist_prbl" - printf 'Server = %s\n' "$mirror_arch" > "$mirrorlist_arch" + printf 'Server = %s\n' "$mirror_arch" >"$mirrorlist_arch" } createdir "$dbpath_prbl" @@ -304,15 +303,14 @@ main_update() { } msg "%s pacman databases are updated. %s is ready. Run %q -n to print results." \ - "$name" "$name" "$cmd" + "$name" "$name" "$cmd" } main_compare() { - if ! [[ -f "$conffile_prbl" && \ - -f "$conffile_arch" && \ - -f "$dbpath_prbl/sync/libre.db" && \ - -f "$dbpath_arch/sync/core.db" ]] - then + if ! [[ -f $conffile_prbl && + -f $conffile_arch && + -f "$dbpath_prbl/sync/libre.db" && + -f "$dbpath_arch/sync/core.db" ]]; then error "You must run %q with out arguments as root to initialize." "$cmd" usage >&2 exit $EXIT_INVALIDARGUMENT @@ -328,22 +326,22 @@ main_compare() { declare -gA provides ver_prbl ver_arch expac --config "$conffile_arch" -S '%n %v' \ - > "$arch_packages_tmp" || \ + >"$arch_packages_tmp" || die "expac command to get %s package data has failed. Exiting." Arch local pkgname pkgver while read -r pkgname pkgver; do ver_arch["$pkgname"]="$pkgver" - done < "$arch_packages_tmp" + done <"$arch_packages_tmp" expac --config "$conffile_prbl" -S '%r/%n %v %S' \ - > "$prbl_packages_tmp" || \ + >"$prbl_packages_tmp" || die "expac command to get %s package data has failed. Exiting." Parabola if [[ $# == 1 ]]; then print_cmp "$1" else - for repo in "${repos[@]}" ; do + for repo in "${repos[@]}"; do echo "[$repo]" print_cmp "$repo" done |