xref: /spdk/scripts/pkgdep/helpers.sh (revision bfb762800f66d81e539329e08d483e2c8010661f)
1#!/usr/bin/env bash
2#  SPDX-License-Identifier: BSD-3-Clause
3#  Copyright (C) 2024 Intel Corporation
4#  All rights reserved.
5#
6
7pkgdep_toolpath() {
8	# Usage: pkgdep_toolpath TOOL DIR
9	#
10	# Regenerates /etc/opt/spdk-pkgdep/paths to ensure that
11	# TOOL in DIR will be in PATH before other versions
12	# of the TOOL installed in the system.
13	local toolname="$1"
14	local toolpath="$2"
15	local toolpath_dir="/etc/opt/spdk-pkgdep/paths"
16	local toolpath_file="${toolpath_dir}/${toolname}.path"
17	local export_file="${toolpath_dir}/export.sh"
18	mkdir -p "$(dirname "${toolpath_file}")"
19	echo "${toolpath}" > "${toolpath_file}" || {
20		echo "cannot write toolpath ${toolpath} to ${toolpath_file}"
21		return 1
22	}
23	echo "# generated, source this file in shell" > "${export_file}"
24	for pathfile in "${toolpath_dir}"/*.path; do
25		echo "PATH=$(< ${pathfile}):\$PATH" >> "${export_file}"
26	done
27	echo "export PATH" >> "${export_file}"
28	echo "echo \$PATH" >> "${export_file}"
29	chmod a+x "${export_file}"
30}
31