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