Ubuntu Pastebin

Paste from smoser at Tue, 12 Dec 2017 20:19:06 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh
# https://gist.github.com/smoser/1d441e6c8514c9c6edc9df2a9903e803

package=${1:-resolvconf}
version=${2}
last=""
mirror="http://us.archive.ubuntu.com/ubuntu/"
pocket="${POCKET:-bionic-proposed}"
component="main"
arch=amd64

case "$pocket" in
    trusty*) ext=".bz2";;
    *) ext=".xz";;
esac
url="${mirror}dists/$pocket/$component/binary-$arch/Packages$ext"

error() { echo "$(date -R)" "$@" 1>&2; }
fail() { echo "$@" 1>&2; exit 1; }

find_pkg() {
    awk '{
        if ($1 == "Package:") cpkg=$2;
        else if ($1 == "Version:") cver=$2;
        else if ($1 == "Source:") csrc=$2;
        else if ($1 == "") {
            if (pkg == csrc || pkg == cpkg) {
                printf("%s\n", cver)
                exit(0);
            }
            csrc=""; cpkg=""; cver="";
        }
    }' "pkg=$1" "$2"
}


case "${url##*/}" in
    *.gz) decomp="zcat";;
    *.bz2) decomp="bzcat";;
    *.xz) decomp="xzcat";;
    *) decomp="cat";;
esac

naplen=4m
lastmod=""
lastpkg=""
while :; do
    headers=$(curl --fail --silent --head "$url") ||
        fail "failed to download headers $url"
    curmod=$(echo "$headers" | sed 's,
,,' |
        awk -F: '$1 == "Last-Modified" { print $0 }')
    curmod=${curmod#*: }
    [ -n "$curmod" ] || fail "no Last-Modified in headers: $headers"
    if [ "$curmod" = "$lastmod" ]; then
        error "sleeping $naplen, not updated ($lastmod)"
    else
        compf="${url##*/}"
        uncompf=${compf%.*}
        curl --fail --silent "$url" > "${url##*/}" ||
            fail "failed to download $url"
        $decomp "$compf" > "$uncompf.tmp" && mv "$uncompf.tmp" "$uncompf" ||
            fail "failed decompress $uncompf"
        if found_ver=$(find_pkg "$package" "$uncompf") &&
                [ -n "$found_ver" ]; then
            if [ -z "$version" ]; then
                echo "found $package/$found_ver in ${url#$mirror}"
                exit 0
            elif dpkg --compare-versions "${found_ver}" ge "${version}"; then
                echo "found $package/$found_ver (>=$version) in ${url#$mirror}"
                exit 0
            else
                echo "found $package/$found_ver (<$version) in ${url#$mirror}"
            fi
        else
            echo "No $package in $url"
        fi
    fi
    lastmod="$curmod"
    echo "sleeping $naplen"
    sleep $naplen
done

# vi: ts=4 expandtab
Download as text