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 (cd "$liburing_dir" && ./configure --libdir=/usr/lib64 && make install) 17 fi 18} 19 20install_shfmt() { 21 # Fetch version that has been tested 22 local shfmt_version=3.1.0 23 local shfmt=shfmt-$shfmt_version 24 local shfmt_dir=${SHFMT_DIR:-/opt/shfmt} 25 local shfmt_dir_out=${SHFMT_DIR_OUT:-/usr/bin} 26 local shfmt_url 27 local os 28 29 if hash "$shfmt" && [[ $("$shfmt" --version) == "v$shfmt_version" ]]; then 30 echo "$shfmt already installed" 31 return 0 32 fi 2> /dev/null 33 34 os=$(uname -s) 35 36 case "$os" in 37 Linux) shfmt_url=https://github.com/mvdan/sh/releases/download/v$shfmt_version/shfmt_v${shfmt_version}_linux_amd64 ;; 38 FreeBSD) shfmt_url=https://github.com/mvdan/sh/releases/download/v$shfmt_version/shfmt_v${shfmt_version}_freebsd_amd64 ;; 39 *) 40 echo "Not supported OS (${os:-Unknown}), skipping" 41 return 0 42 ;; 43 esac 44 45 mkdir -p "$shfmt_dir" 46 mkdir -p "$shfmt_dir_out" 47 48 echo "Fetching ${shfmt_url##*/}"... 49 local err 50 if err=$(curl -f -Lo"$shfmt_dir/$shfmt" "$shfmt_url" 2>&1); then 51 chmod +x "$shfmt_dir/$shfmt" 52 ln -sf "$shfmt_dir/$shfmt" "$shfmt_dir_out" 53 else 54 cat <<- CURL_ERR 55 56 * Fetching $shfmt_url failed, $shfmt will not be available for format check. 57 * Error: 58 59 $err 60 61 CURL_ERR 62 return 0 63 fi 64 echo "$shfmt installed" 65} 66 67install_spdk_bash_completion() { 68 [[ -e /usr/share/bash-completion/bash_completion ]] || return 0 69 70 local compat_dir=/etc/bash_completion.d 71 mkdir -p "$compat_dir" 72 73 if [[ ! -e $compat_dir/spdk ]]; then 74 ln -vs "$scriptsdir/bash-completion/spdk" "$compat_dir" 75 fi 76} 77 78if [[ $INSTALL_DEV_TOOLS == true ]]; then 79 install_shfmt 80 install_spdk_bash_completion 81fi 82 83if [[ $INSTALL_LIBURING == true ]]; then 84 install_liburing 85fi 86