commit:     d87b1ff6119cb184872b3e736a6d9a9a1334bb7f
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Thu Sep 11 00:46:47 2014 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Thu Sep 11 00:52:53 2014 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=proj/linux-patches.git;a=commit;h=d87b1ff6

scripts: initial commit of get-patch

---
 scripts/get-patch | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)

diff --git a/scripts/get-patch b/scripts/get-patch
new file mode 100755
index 0000000..5d56874
--- /dev/null
+++ b/scripts/get-patch
@@ -0,0 +1,75 @@
+#!/bin/bash
+
+GENPATCHES_URL="git://git.overlays.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

Reply via email to