1#!/usr/bin/env bash 2# Please run this script as root. 3 4set -e 5 6function usage() { 7 echo "" 8 echo "This script is intended to automate the installation of package dependencies to build SPDK." 9 echo "Please run this script as root user or with sudo -E." 10 echo "" 11 echo "$0" 12 echo " -h --help" 13 echo " -a --all" 14 echo " -d --developer-tools Install tools for developers (code styling, code coverage, etc.)" 15 echo " -p --pmem Additional dependencies for reduce and pmdk" 16 echo " -f --fuse Additional dependencies for FUSE and NVMe-CUSE" 17 echo " -r --rdma Additional dependencies for RDMA transport in NVMe over Fabrics" 18 echo " -b --docs Additional dependencies for building docs" 19 echo " -u --uring Additional dependencies for io_uring" 20 echo "" 21 exit 0 22} 23 24function install_all_dependencies() { 25 INSTALL_DEV_TOOLS=true 26 INSTALL_PMEM=true 27 INSTALL_FUSE=true 28 INSTALL_RDMA=true 29 INSTALL_DOCS=true 30} 31 32function install_liburing() { 33 local GIT_REPO_LIBURING=https://github.com/axboe/liburing.git 34 local liburing_dir=/usr/local/src/liburing 35 36 if [[ -e /usr/lib64/liburing.so ]]; then 37 echo "liburing is already installed. skipping" 38 else 39 if [[ -d $liburing_dir ]]; then 40 echo "liburing source already present, not cloning" 41 else 42 mkdir $liburing_dir 43 git clone "${GIT_REPO_LIBURING}" "$liburing_dir" 44 fi 45 (cd "$liburing_dir" && ./configure --libdir=/usr/lib64 && make install) 46 fi 47} 48 49function install_shfmt() { 50 # Fetch version that has been tested 51 local shfmt_version=3.1.0 52 local shfmt=shfmt-$shfmt_version 53 local shfmt_dir=${SHFMT_DIR:-/opt/shfmt} 54 local shfmt_dir_out=${SHFMT_DIR_OUT:-/usr/bin} 55 local shfmt_url 56 local os 57 58 if hash "$shfmt" && [[ $("$shfmt" --version) == "v$shfmt_version" ]]; then 59 echo "$shfmt already installed" 60 return 0 61 fi 2> /dev/null 62 63 os=$(uname -s) 64 65 case "$os" in 66 Linux) shfmt_url=https://github.com/mvdan/sh/releases/download/v$shfmt_version/shfmt_v${shfmt_version}_linux_amd64 ;; 67 FreeBSD) shfmt_url=https://github.com/mvdan/sh/releases/download/v$shfmt_version/shfmt_v${shfmt_version}_freebsd_amd64 ;; 68 *) 69 echo "Not supported OS (${os:-Unknown}), skipping" 70 return 0 71 ;; 72 esac 73 74 mkdir -p "$shfmt_dir" 75 mkdir -p "$shfmt_dir_out" 76 77 echo "Fetching ${shfmt_url##*/}"... 78 local err 79 if err=$(curl -f -Lo"$shfmt_dir/$shfmt" "$shfmt_url" 2>&1); then 80 chmod +x "$shfmt_dir/$shfmt" 81 ln -sf "$shfmt_dir/$shfmt" "$shfmt_dir_out" 82 else 83 cat <<- CURL_ERR 84 85 * Fetching $shfmt_url failed, $shfmt will not be available for format check. 86 * Error: 87 88 $err 89 90 CURL_ERR 91 return 0 92 fi 93 echo "$shfmt installed" 94} 95 96INSTALL_CRYPTO=false 97INSTALL_DEV_TOOLS=false 98INSTALL_PMEM=false 99INSTALL_FUSE=false 100INSTALL_RDMA=false 101INSTALL_DOCS=false 102INSTALL_LIBURING=false 103 104while getopts 'abdfhipru-:' optchar; do 105 case "$optchar" in 106 -) 107 case "$OPTARG" in 108 help) usage ;; 109 all) install_all_dependencies ;; 110 developer-tools) INSTALL_DEV_TOOLS=true ;; 111 pmem) INSTALL_PMEM=true ;; 112 fuse) INSTALL_FUSE=true ;; 113 rdma) INSTALL_RDMA=true ;; 114 docs) INSTALL_DOCS=true ;; 115 uring) INSTALL_LIBURING=true ;; 116 *) 117 echo "Invalid argument '$OPTARG'" 118 usage 119 ;; 120 esac 121 ;; 122 h) usage ;; 123 a) install_all_dependencies ;; 124 d) INSTALL_DEV_TOOLS=true ;; 125 p) INSTALL_PMEM=true ;; 126 f) INSTALL_FUSE=true ;; 127 r) INSTALL_RDMA=true ;; 128 b) INSTALL_DOCS=true ;; 129 u) INSTALL_LIBURING=true ;; 130 *) 131 echo "Invalid argument '$OPTARG'" 132 usage 133 ;; 134 esac 135done 136 137trap 'set +e; trap - ERR; echo "Error!"; exit 1;' ERR 138 139scriptsdir=$(readlink -f $(dirname $0)) 140rootdir=$(readlink -f $scriptsdir/..) 141 142OS=$(uname -s) 143 144if [[ -e /etc/os-release ]]; then 145 source /etc/os-release 146fi 147 148ID=${ID:-$OS} ID=${ID,,} 149 150#Link suse related OS to sles 151if [[ ${ID,,} == *"suse"* ]]; then 152 ID="sles" 153fi 154 155if [[ -e $scriptsdir/pkgdep/$ID.sh ]]; then 156 source "$scriptsdir/pkgdep/$ID.sh" 157else 158 printf 'Not supported platform detected (%s), aborting\n' "$ID" >&2 159fi 160