11f958cfaSStefan Eßer#! /bin/sh 21f958cfaSStefan Eßer# 33960d892SStefan Eßer# SPDX-License-Identifier: BSD-2-Clause 41f958cfaSStefan Eßer# 5682da5a0SStefan Eßer# Copyright (c) 2018-2025 Gavin D. Howard and contributors. 61f958cfaSStefan Eßer# 71f958cfaSStefan Eßer# Redistribution and use in source and binary forms, with or without 81f958cfaSStefan Eßer# modification, are permitted provided that the following conditions are met: 91f958cfaSStefan Eßer# 101f958cfaSStefan Eßer# * Redistributions of source code must retain the above copyright notice, this 111f958cfaSStefan Eßer# list of conditions and the following disclaimer. 121f958cfaSStefan Eßer# 131f958cfaSStefan Eßer# * Redistributions in binary form must reproduce the above copyright notice, 141f958cfaSStefan Eßer# this list of conditions and the following disclaimer in the documentation 151f958cfaSStefan Eßer# and/or other materials provided with the distribution. 161f958cfaSStefan Eßer# 171f958cfaSStefan Eßer# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 181f958cfaSStefan Eßer# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191f958cfaSStefan Eßer# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201f958cfaSStefan Eßer# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 211f958cfaSStefan Eßer# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 221f958cfaSStefan Eßer# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 231f958cfaSStefan Eßer# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 241f958cfaSStefan Eßer# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 251f958cfaSStefan Eßer# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 261f958cfaSStefan Eßer# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 271f958cfaSStefan Eßer# POSSIBILITY OF SUCH DAMAGE. 281f958cfaSStefan Eßer# 291f958cfaSStefan Eßer 302f57ecaeSStefan Eßer# Print usage and exit with an error. 311f958cfaSStefan Eßerusage() { 3223aff124SStefan Eßer printf "usage: %s install_dir exec_suffix [bindir]\n" "$0" 1>&2 331f958cfaSStefan Eßer exit 1 341f958cfaSStefan Eßer} 351f958cfaSStefan Eßer 361f958cfaSStefan Eßerscript="$0" 371f958cfaSStefan Eßerscriptdir=$(dirname "$script") 381f958cfaSStefan Eßer 391f958cfaSStefan Eßer. "$scriptdir/functions.sh" 401f958cfaSStefan Eßer 411f958cfaSStefan EßerINSTALL="$scriptdir/safe-install.sh" 421f958cfaSStefan Eßer 432f57ecaeSStefan Eßer# Process command-line arguments. 441f958cfaSStefan Eßertest "$#" -ge 2 || usage 451f958cfaSStefan Eßer 461f958cfaSStefan Eßerinstalldir="$1" 471f958cfaSStefan Eßershift 481f958cfaSStefan Eßer 491f958cfaSStefan Eßerexec_suffix="$1" 501f958cfaSStefan Eßershift 511f958cfaSStefan Eßer 5223aff124SStefan Eßerif [ "$#" -gt 0 ]; then 5323aff124SStefan Eßer bindir="$1" 5423aff124SStefan Eßer shift 5523aff124SStefan Eßerelse 562f57ecaeSStefan Eßer bindir="$scriptdir/../bin" 5723aff124SStefan Eßerfi 581f958cfaSStefan Eßer 592f57ecaeSStefan Eßer# Install or symlink, depending on the type of file. If it's a file, install it. 602f57ecaeSStefan Eßer# If it's a symlink, create an equivalent in the install directory. 611f958cfaSStefan Eßerfor exe in $bindir/*; do 621f958cfaSStefan Eßer 6361e1a12bSStefan Eßer # Skip any directories in case the bin/ directory is also used as the 6461e1a12bSStefan Eßer # prefix. 6561e1a12bSStefan Eßer if [ -d "$exe" ]; then 6661e1a12bSStefan Eßer continue 6761e1a12bSStefan Eßer fi 6861e1a12bSStefan Eßer 691f958cfaSStefan Eßer base=$(basename "$exe") 701f958cfaSStefan Eßer 711f958cfaSStefan Eßer if [ -L "$exe" ]; then 721f958cfaSStefan Eßer link=$(readlink "$exe") 731f958cfaSStefan Eßer "$INSTALL" -Dlm 755 "$link$exec_suffix" "$installdir/$base$exec_suffix" 741f958cfaSStefan Eßer else 751f958cfaSStefan Eßer "$INSTALL" -Dm 755 "$exe" "$installdir/$base$exec_suffix" 761f958cfaSStefan Eßer fi 771f958cfaSStefan Eßer 781f958cfaSStefan Eßerdone 79