From bebc677a33247b2df831640da2dae4358c03b5ce Mon Sep 17 00:00:00 2001 From: zhuangqh Date: Fri, 1 Jun 2018 22:43:29 +0800 Subject: [PATCH 1/2] enhance: correct hard coding in several shell script Signed-off-by: zhuangqh --- hack/make.sh | 32 ++++++++++++++++++-------------- hack/package/rpm/build.sh | 9 ++++++--- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/hack/make.sh b/hack/make.sh index d0458619e..698ed0f98 100755 --- a/hack/make.sh +++ b/hack/make.sh @@ -9,9 +9,13 @@ DIR="$( cd "$( dirname "$0" )/.." && pwd )" cd "$DIR/" CONTAINERD_VERSION= +REQUIRED_CONTAINERD_VERSION="1.0.3" RUNC_VERSION= +REQUIRED_RUNC_VERSION="1.0.0-rc4-1" NSENTER_VERSION= +REQUIRED_NSENTER_VERSION="2.24.1" DUMB_INIT_VERSION= +REQUIRED_DUMB_INIT_VERSION="1.2.1" SOURCEDIR=/go/src/github.com/alibaba/pouch @@ -37,7 +41,7 @@ fi function get_containerd_version { if which containerd &>/dev/null; then - CONTAINERD_VERSION=$(containerd -v|cut -d " " -f 3) + CONTAINERD_VERSION=$(containerd -v|cut -d " " -f 3|cut -c 2-) fi } @@ -58,7 +62,7 @@ function get_nsenter_version function get_dumb_init_version { if which dumb-init &>/dev/null; then - DUMB_INIT_VERSION=$(dumb-init -V 2>&1 | cut -d " " -f 2) + DUMB_INIT_VERSION=$(dumb-init -V 2>&1 | cut -d " " -f 2|cut -c 2-) fi } @@ -66,13 +70,13 @@ function install_containerd { echo "Try installing containerd" get_containerd_version - if [[ "$CONTAINERD_VERSION" == "v1.0.3" ]]; then + if [[ "$CONTAINERD_VERSION" == "$REQUIRED_CONTAINERD_VERSION" ]]; then echo "Containerd already installed." else echo "Download and install containerd." wget --quiet \ - https://github.com/containerd/containerd/releases/download/v1.0.3/containerd-1.0.3.linux-amd64.tar.gz -P "$TMP" - tar xf "$TMP/containerd-1.0.3.linux-amd64.tar.gz" -C "$TMP" && + "https://github.com/containerd/containerd/releases/download/v${REQUIRED_CONTAINERD_VERSION}/containerd-${REQUIRED_CONTAINERD_VERSION}.linux-amd64.tar.gz" -P "$TMP" + tar xf "$TMP/containerd-${REQUIRED_CONTAINERD_VERSION}.linux-amd64.tar.gz" -C "$TMP" && cp -f "$TMP"/bin/* /usr/local/bin/ fi; } @@ -81,12 +85,12 @@ function install_runc { echo "Try installing runc" get_runc_version - if [[ "$RUNC_VERSION" == "1.0.0-rc4-1" ]]; then + if [[ "$RUNC_VERSION" == "$REQUIRED_RUNC_VERSION" ]]; then echo "Runc already installed." else echo "Download and install runc." wget --quiet \ - https://github.com/alibaba/runc/releases/download/v1.0.0-rc4-1/runc.amd64 -P /usr/local/bin + "https://github.com/alibaba/runc/releases/download/v${REQUIRED_RUNC_VERSION}/runc.amd64" -P /usr/local/bin chmod +x /usr/local/bin/runc.amd64 mv /usr/local/bin/runc.amd64 /usr/local/bin/runc fi; @@ -137,7 +141,7 @@ function install_nsenter echo "Try installing nsenter" get_nsenter_version if grep -qi "ubuntu" /etc/issue ; then - if [[ "$NSENTER_VERSION" == "2.24.1" ]]; then + if [[ "$NSENTER_VERSION" == "$REQUIRED_NSENTER_VERSION" ]]; then echo "Nsenter already installed." else echo "Download and install nsenter." @@ -156,9 +160,9 @@ function install_nsenter autopoint \ libtool wget --quiet \ - https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-linux-2.24.1.tar.gz -P "$TMP" - tar xf "$TMP/util-linux-2.24.1.tar.gz" -C "$TMP" && - cd "$TMP/util-linux-2.24.1" + "https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-linux-${REQUIRED_NSENTER_VERSION}.tar.gz" -P "$TMP" + tar xf "$TMP/util-linux-${REQUIRED_NSENTER_VERSION}.tar.gz" -C "$TMP" && + cd "$TMP/util-linux-${REQUIRED_NSENTER_VERSION}" ./autogen.sh autoreconf -vfi ./configure && make @@ -175,13 +179,13 @@ function install_dumb_init { echo "Try installing dumb-init" get_dumb_init_version - if [[ "$DUMB_INIT_VERSION" == "v1.2.1" ]]; then + if [[ "$DUMB_INIT_VERSION" == "$REQUIRED_DUMB_INIT_VERSION" ]]; then echo "Dumb-init already installed." else echo "Download and install dumb-init." wget --quiet -O /tmp/dumb-init \ - https://github.com/Yelp/dumb-init/releases/download/v1.2.1/dumb-init_1.2.1_amd64 - mv tmp/dumb-init /usr/bin/ + "https://github.com/Yelp/dumb-init/releases/download/v${REQUIRED_DUMB_INIT_VERSION}/dumb-init_${REQUIRED_DUMB_INIT_VERSION}_amd64" + mv /tmp/dumb-init /usr/bin/ chmod +x /usr/bin/dumb-init fi } diff --git a/hack/package/rpm/build.sh b/hack/package/rpm/build.sh index aae9cafad..aa69d3573 100755 --- a/hack/package/rpm/build.sh +++ b/hack/package/rpm/build.sh @@ -19,8 +19,11 @@ BINDIR=$POUCHDIR/bin LXC_DIR=$TMP/lxc [ -d "$LXC_DIR" ] || mkdir -p "$LXC_DIR" +# Dependency # lxcfs stable branch LXC_BRANCH="stable-2.0" +CONTAINERD_VERSION="1.0.3" +RUNC_VERSION="1.0.0-rc4-1" # ARCHITECTURE, The architecture name. Usually matches 'uname -m'. ARCHITECTURE=$(uname -m) @@ -47,12 +50,12 @@ function build_pouch() { # install containerd echo "Downloading containerd." - wget --quiet https://github.com/containerd/containerd/releases/download/v1.0.3/containerd-1.0.3.linux-amd64.tar.gz -P "$TMP" - tar xf "$TMP/containerd-1.0.3.linux-amd64.tar.gz -C $TMP && cp -f $TMP/bin/* $BINDIR/" + wget --quiet "https://github.com/containerd/containerd/releases/download/v${CONTAINERD_VERSION}/containerd-${CONTAINERD_VERSION}.linux-amd64.tar.gz" -P "$TMP" + tar xf "$TMP/containerd-${CONTAINERD_VERSION}.linux-amd64.tar.gz" -C "$TMP" && cp -f "$TMP"/bin/* "$BINDIR/" # install runc echo "Downloading runc." - wget --quiet https://github.com/alibaba/runc/releases/download/v1.0.0-rc4-1/runc.amd64 -P "$BINDIR/" + wget --quiet "https://github.com/alibaba/runc/releases/download/v${RUNC_VERSION}/runc.amd64" -P "$BINDIR/" chmod +x "$BINDIR/runc.amd64" mv "$BINDIR/runc.amd64" "$BINDIR/runc" From 53a97252e32f0246bed73b22d80c30e825fb1f0b Mon Sep 17 00:00:00 2001 From: zhuangqh Date: Mon, 4 Jun 2018 13:45:43 +0800 Subject: [PATCH 2/2] refactor: correct hard coding in several shell script Signed-off-by: zhuangqh --- hack/make.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hack/make.sh b/hack/make.sh index 698ed0f98..a2dcebdea 100755 --- a/hack/make.sh +++ b/hack/make.sh @@ -8,6 +8,10 @@ TMP=$(mktemp -d /tmp/pouch.XXXXXX) DIR="$( cd "$( dirname "$0" )/.." && pwd )" cd "$DIR/" +# +# Get the version of dependencies from corresponding commands and compare them with the required version. +# If they don't meet the requirement, this script will install them. +# CONTAINERD_VERSION= REQUIRED_CONTAINERD_VERSION="1.0.3" RUNC_VERSION=