summaryrefslogtreecommitdiff
blob: eb5dbd8a74c9d3c5472c007677bbaca64368f1d8 (plain)
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
#!/bin/bash

GENPATCHES_URL="git://git.gentoo.org/proj/linux-patches.git"
KERNEL_BASE_URL="https://www.kernel.org/pub/linux/kernel/v3.x"
KERENL_INCR_URL="${KERNEL_BASE_URL}/incr"


usage() {
    echo "Usage: $0 n [m]."
    echo
    echo "When called from within a branch N of the linux-patches repo,"
    echo "get-patch will download patch-N.n-(n+1).xz from kernel.org"
    echo "and rename it to 100n_linux-N-(n+1).patch for inclusion in"
    echo "the genpatches patchset."
    echo
    echo "If a range 'n m' is given, then that range of patches will"
    echo "be downloaded.  get-patch expects n < m."
    echo
    exit 1
}

error_branch() {
    echo "Could not detect your branch.  get-patch expects you to be"
    echo "in a branch of $LINUX_PATCHES_URL"
    echo
    exit 4
}

error_download() {
    echo "Couldn't download $1, bailing out!"
    echo
    rm -f $2
    exit 5
}

warning_exists() {
    echo "Warning, $1 alreay exists, not downloading."
    echo "If you want to download it again, remove the current file."
    echo
}

alert_downloaded() {
    echo "Downloaded: $1"
    echo
}

[[ "$1" == "-h" || "$1" == "--help" ]] && usage 0
[[ -z "$1" ]] && usage 1
[[ ! -z "$3" ]] && usage 2
[[ ! -z "$2" && $1 -ge $2 ]] && usage 3

version=$(git rev-parse --abbrev-ref HEAD)

[[ -z "$version" ]] && error_branch

[[ -z "$2" ]] && limit=$(expr $1 + 1) || limit=$2

for i in $(seq $1 $(expr $limit - 1)) ; do
    if [[ $i -eq 0 ]]; then
        front=100
        GET="${KERNEL_BASE_URL}/patch-${version}.1.xz"
    else
        if [[ $i -lt 10 ]] ; then
            front=100
        else
            front=10
        fi
        GET="${KERENL_INCR_URL}/patch-${version}.$i-$(expr $i + 1).xz"
    fi
    SAVE="${front}${i}_linux-${version}.$(expr $i + 1).patch"
    [[ -f "${SAVE}" ]] &&  warning_exists "${SAVE}" && continue
    wget "${GET}" -O "${SAVE}.xz" >/dev/null 2>&1
    [[ $? -ne 0 ]] && error_download "${GET}" "${SAVE}.xz" || alert_downloaded "${SAVE}"
    xz -d "${SAVE}.xz"
done