[CRIU] [PATCH 6/6] scripts/build/extract-deb-pkg: fix/improve

Kir Kolyshkin kolyshkin at gmail.com
Sun Oct 1 23:43:27 MSK 2017


Numerous improvement to extract-deb-pkg, in no particular order:

 * Use bash
 * More strict error checking (set -u -o pipefail)
 * Print error message if target dir exists
 * Check number of arguments, provide usage info
 * Separate mirror to a variable for easier changing
 * Use mirrors.kernel.org
 * Use https and check cert with curl
 * Make curl silent
 * Use zgrep instead of gunzip | grep
 * Error out with a message in case more than 1 package was found
 * Do not create a target directory before we need it
 * Fix shellcheck warnings (way too many to mention)
 * ...
 * PROFIT!!!111

Signed-off-by: Kir Kolyshkin <kolyshkin at gmail.com>
---
 scripts/build/extract-deb-pkg | 44 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 35 insertions(+), 9 deletions(-)

diff --git a/scripts/build/extract-deb-pkg b/scripts/build/extract-deb-pkg
index 922f9c19..f2c9e923 100755
--- a/scripts/build/extract-deb-pkg
+++ b/scripts/build/extract-deb-pkg
@@ -1,10 +1,36 @@
-#'http://mirror.yandex.ru/debian/pool/main/q/qemu/qemu-user-static_2.5%2Bdfsg-5_amd64.deb'
+#!/bin/bash
+
 set -e
-test -d $1 && exit
-mkdir $1
-cd $1
-pkg=`curl http://mirror.yandex.ru/ubuntu/dists/xenial/universe/binary-amd64/Packages.gz | zcat | grep "Filename.*$1" | awk '{ print $2 }'`
-wget "http://mirror.yandex.ru/ubuntu/$pkg"
-pkg=`basename $pkg`
-ar vx $pkg
-tar -xJvf data.tar.xz
+set -u
+set -o pipefail
+MIRROR="https://mirrors.kernel.org/ubuntu"
+PKGS="$MIRROR/dists/xenial/universe/binary-amd64/Packages.gz"
+
+if [ $# -ne 1 ]; then
+	echo "Usage: $0 package-name" 1>&2
+	exit 1
+fi
+
+if [ -d "$1" ]; then
+	echo "Directory $1 already exists -- exiting"
+	exit 0
+fi
+
+if ! pkg=$(curl -sSL "$PKGS" | zgrep "Filename.*$1" | awk '{ print $2 }'); then
+	echo "ERROR: no packages matching $1" 1>&2
+	exit 1
+fi
+
+if [ "$(wc -w <<< "$pkg")" -gt 1 ]; then
+	echo "$pkg" 1>&2
+	echo "ERROR: more than one match for $1" 1>&2
+	exit 1
+fi
+
+mkdir "$1"
+cd "$1"
+
+wget "$MIRROR/$pkg"
+pkg=$(basename "$pkg")
+ar vx "$pkg"
+tar xJvf data.tar.xz
-- 
2.14.1



More information about the CRIU mailing list