list-rdeps: ignore packages not in both unstable and testing
Ximin Luo
4 years ago
0 | 0 | #!/bin/bash |
1 | ||
1 | 2 | set -e |
2 | set -o pipefail | |
3 | 3 | |
4 | 4 | abort() { local x=$1; shift; for i in "$@"; do echo >&2 "$0: abort: $i"; done; exit "$x"; } |
5 | 5 | |
7 | 7 | which aptitude >/dev/null || abort 1 "aptitude not found, install it" |
8 | 8 | |
9 | 9 | ARCHIVE="${ARCHIVE:-unstable}" |
10 | ARCHIVT="${ARCHIVT:-testing}" | |
11 | ||
12 | if ! grep "$ARCHIVE" -qR /etc/apt/sources.list /etc/apt/sources.list.d/ || \ | |
13 | ! grep "$ARCHIVT" -qR /etc/apt/sources.list /etc/apt/sources.list.d/; then | |
14 | cat <<-eof | |
15 | To make this script work, you will need Debian Testing *AND* Debian Unstable | |
16 | in your sources.list. If you want your system to prefer Debian Testing, be | |
17 | sure to also add these lines to your /etc/apt/apt.conf: | |
18 | ||
19 | APT::Default-Release "$ARCHIVT"; | |
20 | ||
21 | After these changes, make sure to re-run \`apt-get update\`. | |
22 | eof | |
23 | exit 1 | |
24 | fi | |
10 | 25 | |
11 | 26 | if [ $(($(date +%s) - $(stat -c %Y /var/cache/apt/pkgcache.bin))) -gt 7200 ]; then |
12 | 27 | read -p "APT cache is a bit old, update? [Y/n] " x |
14 | 29 | fi |
15 | 30 | |
16 | 31 | apt_versions() { |
17 | aptitude versions --disable-columns -F '%p %t' --group-by=none "~rnative $1" | grep "$ARCHIVE" | |
32 | aptitude versions --disable-columns -F '%p %t' --group-by=none "~rnative $1" || true | |
18 | 33 | } |
19 | 34 | |
20 | inst_cache=$(mktemp) | |
21 | # https://stackoverflow.com/a/14812383 inside "trap" avoids running handler twice | |
22 | trap 'excode=$?; rm -rf "'"$inst_cache"'"; trap - EXIT' EXIT HUP INT QUIT PIPE TERM | |
35 | if [ -n "$INST_CACHE" ]; then | |
36 | inst_cache="$INST_CACHE" | |
37 | else | |
38 | inst_cache=$(mktemp) | |
39 | # https://stackoverflow.com/a/14812383 inside "trap" avoids running handler twice | |
40 | trap 'excode=$?; rm -rf "'"$inst_cache"'"; trap - EXIT' EXIT HUP INT QUIT PIPE TERM | |
41 | fi | |
23 | 42 | |
24 | 43 | installability() { |
25 | 44 | local r=$(grep -F "$1=$2" "$inst_cache" | cut -f2) |
41 | 60 | pkg="${pkg#rust-}" |
42 | 61 | |
43 | 62 | echo "Versions of rust-${pkg} in $ARCHIVE:" |
44 | apt_versions "~e^rust-${pkg}$" | sort | while read binpkg ver archive; do | |
63 | apt_versions "~e^rust-${pkg}$" | grep "$ARCHIVE" | sort | while read binpkg ver archive; do | |
45 | 64 | local stat="$(installability "$binpkg" "$ver")" |
46 | 65 | printf "%s %-48s %-16s\n" "$stat" "$binpkg" "$ver" |
47 | 66 | done |
48 | 67 | echo |
49 | 68 | |
50 | echo "Versions of rdeps of rust-${pkg} in $ARCHIVE:" | |
51 | apt_versions "~D^librust-${pkg}~(\+~|-[0-9]~).*-dev$" | while read rdep ver archives; do | |
69 | echo "Versions of rdeps of rust-${pkg} in $ARCHIVE, that also exist in $ARCHIVT:" | |
70 | local versions="$(apt_versions "~D^librust-${pkg}~(\+~|-[0-9]~).*-dev$")" | |
71 | printf "%s\n" "$versions" | grep "$ARCHIVE" | while read rdep ver archive; do | |
72 | if ! printf "%s\n" "$versions" | grep "$ARCHIVT" | grep -qF "$rdep"; then | |
73 | # we're only interested in packages in both archives. | |
74 | # if a pkg-ver is not in either archive, this doesn't affect the migration process | |
75 | continue | |
76 | fi | |
52 | 77 | apt-cache show "${rdep}=${ver}" \ |
53 | 78 | | grep-dctrl -FDepends -e "librust-${pkg}(\+|-[0-9]).*-dev" -sPackage,Version,Depends - \ |
54 | 79 | | cut -d: -f2 | cut '-d ' -f2- \ |