|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# SPDX-License-Identifier: GPL-2.0 |
| 4 | + |
| 5 | +# Dependencies: |
| 6 | +# rebuilderd-tools |
| 7 | +# parallel |
| 8 | + |
| 9 | +progname="greposcope" |
| 10 | +tmp_dir="${TMPDIR:-/tmp}/${progname}-${UID}" |
| 11 | +rebuilderd_host="https://reproducible.archlinux.org" |
| 12 | + |
| 13 | +help() { |
| 14 | + cat <<EOF |
| 15 | +Usage: ${progname} [OPTIONS] pattern |
| 16 | +
|
| 17 | +Searches for 'pattern' in the diffoscope output of every unreproducible packages reported at ${rebuilderd_host}. |
| 18 | +This is useful to identify packages that are unreproducible because of a specific issue. |
| 19 | +
|
| 20 | +OPTIONS |
| 21 | + -h, --help Show this message |
| 22 | + -i, --ignore-case Ignore case distinctions in patterns and input data |
| 23 | +
|
| 24 | +Examples: |
| 25 | + $ ${progname} "gzip compressed data" |
| 26 | + $ ${progname} -i zipinfo |
| 27 | +EOF |
| 28 | +} |
| 29 | + |
| 30 | +while ((${#})); do |
| 31 | + case "${1}" in |
| 32 | + -h|--help) |
| 33 | + help |
| 34 | + exit 0 |
| 35 | + ;; |
| 36 | + -i|--ignore-case) |
| 37 | + extra_grep_opt="--ignore-case" |
| 38 | + ;; |
| 39 | + --) |
| 40 | + shift |
| 41 | + break |
| 42 | + ;; |
| 43 | + -*) |
| 44 | + echo -e >&2 "Invalid argument -- '${1}'\nTry '${progname} --help' for more information" |
| 45 | + exit 1 |
| 46 | + ;; |
| 47 | + *) |
| 48 | + pattern="${1}" |
| 49 | + ;; |
| 50 | + esac |
| 51 | + shift |
| 52 | +done |
| 53 | + |
| 54 | +if [ -z "${pattern}" ]; then |
| 55 | + echo -e >&2 "No pattern provided\nTry '${progname} --help' for more information" |
| 56 | + exit 1 |
| 57 | +fi |
| 58 | + |
| 59 | +mkdir -p "${tmp_dir}" |
| 60 | + |
| 61 | +echo -e "Fetching the list of unreproducible packages...\n" |
| 62 | +mapfile -t pkg_list < <(rebuildctl -H "${rebuilderd_host}" pkgs ls --status BAD | awk '{print $3}') |
| 63 | + |
| 64 | +if [ ${#pkg_list[@]} -eq 0 ]; then |
| 65 | + echo "No unreproducible packages found" |
| 66 | + exit 0 |
| 67 | +fi |
| 68 | + |
| 69 | +# Substract packages that already have their diffoscope output downloaded from the list |
| 70 | +updated_pkg_list=() |
| 71 | +for pkg in "${pkg_list[@]}"; do |
| 72 | + if [ ! -f "${tmp_dir}/${pkg}.diffoscope" ]; then |
| 73 | + updated_pkg_list+=("${pkg}") |
| 74 | + fi |
| 75 | +done |
| 76 | + |
| 77 | +pkg_list=("${updated_pkg_list[@]}") |
| 78 | + |
| 79 | +if [ ${#pkg_list[@]} -eq 0 ]; then |
| 80 | + echo "All diffoscope outputs already downloaded" |
| 81 | +else |
| 82 | + echo -e "Downloading diffoscope outputs of ${#pkg_list[@]} unreproducible packages...\nThis may take some time...\n" |
| 83 | + parallel --bar -j "$(nproc)" \ |
| 84 | + rebuildctl -H "${rebuilderd_host}" pkgs diffoscope --name {} "&>" "${tmp_dir}/{}.diffoscope" ::: "${pkg_list[@]}" |
| 85 | +fi |
| 86 | + |
| 87 | +echo -e "\nSearching for \"${pattern}\" in diffoscope outputs...\n" |
| 88 | +parallel --silent -j "$(nproc)" \ |
| 89 | + "grep --color=always --with-filename --line-number ${extra_grep_opt} '${pattern}' {}" ::: "${tmp_dir}"/*.diffoscope || true |
0 commit comments