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