From 20708f35310f50c3e4c51c4a60a615b9e5c978cf Mon Sep 17 00:00:00 2001 From: Michal Berger Date: Sat, 25 Jul 2020 22:44:52 +0200 Subject: [PATCH] scripts/pkgdep: Move distro independent parts to a common place This will avoid adding similar components into multiple scripts instead of just one. Change-Id: I83cff1ad883f3a7054d0f21ec20210c81cb6b9c1 Signed-off-by: Michal Berger Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/3525 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Tomasz Zawadzki --- scripts/pkgdep.sh | 65 +--------------------------- scripts/pkgdep/arch.sh | 4 -- scripts/pkgdep/clear-linux-os.sh | 1 - scripts/pkgdep/common.sh | 73 ++++++++++++++++++++++++++++++++ scripts/pkgdep/debian.sh | 4 -- scripts/pkgdep/rhel.sh | 4 -- scripts/pkgdep/sles.sh | 4 -- 7 files changed, 74 insertions(+), 81 deletions(-) create mode 100755 scripts/pkgdep/common.sh diff --git a/scripts/pkgdep.sh b/scripts/pkgdep.sh index 7d748c4372..3045b6a24e 100755 --- a/scripts/pkgdep.sh +++ b/scripts/pkgdep.sh @@ -30,70 +30,6 @@ function install_all_dependencies() { INSTALL_LIBURING=true } -function install_liburing() { - local GIT_REPO_LIBURING=https://github.com/axboe/liburing.git - local liburing_dir=/usr/local/src/liburing - - if [[ -e /usr/lib64/liburing.so ]]; then - echo "liburing is already installed. skipping" - else - if [[ -d $liburing_dir ]]; then - echo "liburing source already present, not cloning" - else - mkdir $liburing_dir - git clone "${GIT_REPO_LIBURING}" "$liburing_dir" - fi - (cd "$liburing_dir" && ./configure --libdir=/usr/lib64 && make install) - fi -} - -function install_shfmt() { - # Fetch version that has been tested - local shfmt_version=3.1.0 - local shfmt=shfmt-$shfmt_version - local shfmt_dir=${SHFMT_DIR:-/opt/shfmt} - local shfmt_dir_out=${SHFMT_DIR_OUT:-/usr/bin} - local shfmt_url - local os - - if hash "$shfmt" && [[ $("$shfmt" --version) == "v$shfmt_version" ]]; then - echo "$shfmt already installed" - return 0 - fi 2> /dev/null - - os=$(uname -s) - - case "$os" in - Linux) shfmt_url=https://github.com/mvdan/sh/releases/download/v$shfmt_version/shfmt_v${shfmt_version}_linux_amd64 ;; - FreeBSD) shfmt_url=https://github.com/mvdan/sh/releases/download/v$shfmt_version/shfmt_v${shfmt_version}_freebsd_amd64 ;; - *) - echo "Not supported OS (${os:-Unknown}), skipping" - return 0 - ;; - esac - - mkdir -p "$shfmt_dir" - mkdir -p "$shfmt_dir_out" - - echo "Fetching ${shfmt_url##*/}"... - local err - if err=$(curl -f -Lo"$shfmt_dir/$shfmt" "$shfmt_url" 2>&1); then - chmod +x "$shfmt_dir/$shfmt" - ln -sf "$shfmt_dir/$shfmt" "$shfmt_dir_out" - else - cat <<- CURL_ERR - - * Fetching $shfmt_url failed, $shfmt will not be available for format check. - * Error: - - $err - - CURL_ERR - return 0 - fi - echo "$shfmt installed" -} - INSTALL_CRYPTO=false INSTALL_DEV_TOOLS=false INSTALL_PMEM=false @@ -155,6 +91,7 @@ fi if [[ -e $scriptsdir/pkgdep/$ID.sh ]]; then source "$scriptsdir/pkgdep/$ID.sh" + source "$scriptsdir/pkgdep/common.sh" else printf 'Not supported platform detected (%s), aborting\n' "$ID" >&2 fi diff --git a/scripts/pkgdep/arch.sh b/scripts/pkgdep/arch.sh index 53e5d8d7d2..a43dbd96a2 100755 --- a/scripts/pkgdep/arch.sh +++ b/scripts/pkgdep/arch.sh @@ -32,7 +32,6 @@ if [[ $INSTALL_DEV_TOOLS == "true" ]]; then makepkg -si --needed --noconfirm; cd .. && rm -rf lcov-git; popd" - install_shfmt fi if [[ $INSTALL_PMEM == "true" ]]; then # Additional dependencies for building pmem based backends @@ -72,6 +71,3 @@ if [[ $INSTALL_DOCS == "true" ]]; then cd .. && rm -rf mscgen; popd" fi -if [[ $INSTALL_LIBURING == "true" ]]; then - install_liburing -fi diff --git a/scripts/pkgdep/clear-linux-os.sh b/scripts/pkgdep/clear-linux-os.sh index a79a67e79f..da155f2d9d 100755 --- a/scripts/pkgdep/clear-linux-os.sh +++ b/scripts/pkgdep/clear-linux-os.sh @@ -13,7 +13,6 @@ pip3 install pexpect pip3 install configshell_fb if [[ $INSTALL_DEV_TOOLS == "true" ]]; then swupd bundle-add -y git os-testsuite-0day - install_shfmt fi if [[ $INSTALL_PMEM == "true" ]]; then # Additional dependencies for building pmem based backends diff --git a/scripts/pkgdep/common.sh b/scripts/pkgdep/common.sh new file mode 100755 index 0000000000..b13773b0f4 --- /dev/null +++ b/scripts/pkgdep/common.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash + +install_liburing() { + local GIT_REPO_LIBURING=https://github.com/axboe/liburing.git + local liburing_dir=/usr/local/src/liburing + + if [[ -e /usr/lib64/liburing.so ]]; then + echo "liburing is already installed. skipping" + else + if [[ -d $liburing_dir ]]; then + echo "liburing source already present, not cloning" + else + mkdir $liburing_dir + git clone "${GIT_REPO_LIBURING}" "$liburing_dir" + fi + (cd "$liburing_dir" && ./configure --libdir=/usr/lib64 && make install) + fi +} + +install_shfmt() { + # Fetch version that has been tested + local shfmt_version=3.1.0 + local shfmt=shfmt-$shfmt_version + local shfmt_dir=${SHFMT_DIR:-/opt/shfmt} + local shfmt_dir_out=${SHFMT_DIR_OUT:-/usr/bin} + local shfmt_url + local os + + if hash "$shfmt" && [[ $("$shfmt" --version) == "v$shfmt_version" ]]; then + echo "$shfmt already installed" + return 0 + fi 2> /dev/null + + os=$(uname -s) + + case "$os" in + Linux) shfmt_url=https://github.com/mvdan/sh/releases/download/v$shfmt_version/shfmt_v${shfmt_version}_linux_amd64 ;; + FreeBSD) shfmt_url=https://github.com/mvdan/sh/releases/download/v$shfmt_version/shfmt_v${shfmt_version}_freebsd_amd64 ;; + *) + echo "Not supported OS (${os:-Unknown}), skipping" + return 0 + ;; + esac + + mkdir -p "$shfmt_dir" + mkdir -p "$shfmt_dir_out" + + echo "Fetching ${shfmt_url##*/}"... + local err + if err=$(curl -f -Lo"$shfmt_dir/$shfmt" "$shfmt_url" 2>&1); then + chmod +x "$shfmt_dir/$shfmt" + ln -sf "$shfmt_dir/$shfmt" "$shfmt_dir_out" + else + cat <<- CURL_ERR + + * Fetching $shfmt_url failed, $shfmt will not be available for format check. + * Error: + + $err + + CURL_ERR + return 0 + fi + echo "$shfmt installed" +} + +if [[ $INSTALL_DEV_TOOLS == true ]]; then + install_shfmt +fi + +if [[ $INSTALL_LIBURING == true ]]; then + install_liburing +fi diff --git a/scripts/pkgdep/debian.sh b/scripts/pkgdep/debian.sh index 2513a01605..10f61b8397 100755 --- a/scripts/pkgdep/debian.sh +++ b/scripts/pkgdep/debian.sh @@ -28,7 +28,6 @@ if [[ $INSTALL_DEV_TOOLS == "true" ]]; then apt-get install -y pycodestyle || true # Additional dependecies for nvmf performance test script apt-get install -y python3-paramiko - install_shfmt fi if [[ $INSTALL_PMEM == "true" ]]; then # Additional dependencies for building pmem based backends @@ -53,6 +52,3 @@ if [[ $INSTALL_DOCS == "true" ]]; then # Additional dependencies for building docs apt-get install -y doxygen mscgen graphviz fi -if [[ $INSTALL_LIBURING == "true" ]]; then - install_liburing -fi diff --git a/scripts/pkgdep/rhel.sh b/scripts/pkgdep/rhel.sh index 03e167814f..7c03c97d87 100755 --- a/scripts/pkgdep/rhel.sh +++ b/scripts/pkgdep/rhel.sh @@ -49,7 +49,6 @@ if [[ $INSTALL_DEV_TOOLS == "true" ]]; then yum install -y python-pycodestyle lcov ShellCheck fi yum install -y git astyle sg3_utils pciutils - install_shfmt fi if [[ $INSTALL_PMEM == "true" ]]; then # Additional dependencies for building pmem based backends @@ -68,6 +67,3 @@ if [[ $INSTALL_DOCS == "true" ]]; then yum install -y mscgen || echo "Warning: couldn't install mscgen via yum. Please install mscgen manually." yum install -y doxygen graphviz fi -if [[ $INSTALL_LIBURING == "true" ]]; then - install_liburing -fi diff --git a/scripts/pkgdep/sles.sh b/scripts/pkgdep/sles.sh index dacf6d1b58..0c743d254a 100755 --- a/scripts/pkgdep/sles.sh +++ b/scripts/pkgdep/sles.sh @@ -11,7 +11,6 @@ if [[ $INSTALL_DEV_TOOLS == "true" ]]; then # Tools for developers zypper install -y git-core lcov python-pycodestyle sg3_utils \ pciutils ShellCheck - install_shfmt fi if [[ $INSTALL_PMEM == "true" ]]; then # Additional dependencies for building pmem based backends @@ -29,6 +28,3 @@ if [[ $INSTALL_DOCS == "true" ]]; then # Additional dependencies for building docs zypper install -y doxygen mscgen graphviz fi -if [[ $INSTALL_LIBURING == "true" ]]; then - install_liburing -fi