1#!/usr/bin/env bash 2 3install_liburing() { 4 local GIT_REPO_LIBURING=https://github.com/axboe/liburing.git 5 local liburing_dir=/usr/local/src/liburing 6 7 if [[ $(ldconfig -p) == *liburing.so* ]]; then 8 echo "liburing is already installed. skipping" 9 else 10 if [[ -d $liburing_dir ]]; then 11 echo "liburing source already present, not cloning" 12 else 13 mkdir -p $liburing_dir 14 git clone "${GIT_REPO_LIBURING}" "$liburing_dir" 15 fi 16 # Use commit we know we can compile against. See #1673 as a reference. 17 # FIXME: Switch to liburing-2.0 when it's finally released 18 git -C "$liburing_dir" checkout 5d027b315d78415a31dcc9111f6bd8924ba5b4e6 19 (cd "$liburing_dir" && ./configure --libdir=/usr/lib64 && make install) 20 fi 21} 22 23install_shfmt() { 24 # Fetch version that has been tested 25 local shfmt_version=3.1.0 26 local shfmt=shfmt-$shfmt_version 27 local shfmt_dir=${SHFMT_DIR:-/opt/shfmt} 28 local shfmt_dir_out=${SHFMT_DIR_OUT:-/usr/bin} 29 local shfmt_url 30 local os 31 32 if hash "$shfmt" && [[ $("$shfmt" --version) == "v$shfmt_version" ]]; then 33 echo "$shfmt already installed" 34 return 0 35 fi 2> /dev/null 36 37 os=$(uname -s) 38 39 case "$os" in 40 Linux) shfmt_url=https://github.com/mvdan/sh/releases/download/v$shfmt_version/shfmt_v${shfmt_version}_linux_amd64 ;; 41 FreeBSD) shfmt_url=https://github.com/mvdan/sh/releases/download/v$shfmt_version/shfmt_v${shfmt_version}_freebsd_amd64 ;; 42 *) 43 echo "Not supported OS (${os:-Unknown}), skipping" 44 return 0 45 ;; 46 esac 47 48 mkdir -p "$shfmt_dir" 49 mkdir -p "$shfmt_dir_out" 50 51 echo "Fetching ${shfmt_url##*/}"... 52 local err 53 if err=$(curl -f -Lo"$shfmt_dir/$shfmt" "$shfmt_url" 2>&1); then 54 chmod +x "$shfmt_dir/$shfmt" 55 ln -sf "$shfmt_dir/$shfmt" "$shfmt_dir_out" 56 else 57 cat <<- CURL_ERR 58 59 * Fetching $shfmt_url failed, $shfmt will not be available for format check. 60 * Error: 61 62 $err 63 64 CURL_ERR 65 return 0 66 fi 67 echo "$shfmt installed" 68} 69 70install_spdk_bash_completion() { 71 [[ -e /usr/share/bash-completion/bash_completion ]] || return 0 72 73 local compat_dir=/etc/bash_completion.d 74 mkdir -p "$compat_dir" 75 76 if [[ ! -e $compat_dir/spdk ]]; then 77 ln -vs "$scriptsdir/bash-completion/spdk" "$compat_dir" 78 fi 79} 80 81if [[ $INSTALL_DEV_TOOLS == true ]]; then 82 install_shfmt 83 install_spdk_bash_completion 84fi 85 86if [[ $INSTALL_LIBURING == true ]]; then 87 install_liburing 88fi 89