blob: 4446cb7dbb2abcccf59e0b8c692d6afb266c40ef [file] [log] [blame]
Gavin Howard4ffe5a92018-09-26 20:58:31 -06001#! /bin/sh
rofl0r8f19ed92018-04-01 20:54:56 +01002#
Gavin Howard7345cb92019-04-08 14:13:43 -06003# Copyright (c) 2018-2019 Gavin D. Howard and contributors.
rofl0r8f19ed92018-04-01 20:54:56 +01004#
Gavin Howard7345cb92019-04-08 14:13:43 -06005# All rights reserved.
Gavin Howard4ffe5a92018-09-26 20:58:31 -06006#
Gavin Howard7345cb92019-04-08 14:13:43 -06007# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions are met:
9#
10# * Redistributions of source code must retain the above copyright notice, this
11# list of conditions and the following disclaimer.
12#
13# * Redistributions in binary form must reproduce the above copyright notice,
14# this list of conditions and the following disclaimer in the documentation
15# and/or other materials provided with the distribution.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27# POSSIBILITY OF SUCH DAMAGE.
rofl0r8f19ed92018-04-01 20:54:56 +010028#
29
30usage() {
Gavin Howarddbbe3252019-02-18 11:07:22 -070031 printf "usage: %s install_dir exec_suffix\n" "$0" 1>&2
Gavin Howard4ffe5a92018-09-26 20:58:31 -060032 exit 1
rofl0r8f19ed92018-04-01 20:54:56 +010033}
34
Gavin Howarddbbe3252019-02-18 11:07:22 -070035script="$0"
Gavin Howard4ffe5a92018-09-26 20:58:31 -060036scriptdir=$(dirname "$script")
rofl0r8f19ed92018-04-01 20:54:56 +010037
Gavin Howard6e70f552019-04-01 14:09:39 -060038. "$scriptdir/functions.sh"
Gavin Howard50080252019-02-20 15:27:43 -070039
Gavin Howard4ffe5a92018-09-26 20:58:31 -060040INSTALL="$scriptdir/safe-install.sh"
41
Gavin Howarddbbe3252019-02-18 11:07:22 -070042test "$#" -ge 2 || usage
Gavin Howard4ffe5a92018-09-26 20:58:31 -060043
44installdir="$1"
45shift
46
Gavin Howard5d057152019-01-29 10:31:40 -070047exec_suffix="$1"
48shift
49
Gavin Howarddbbe3252019-02-18 11:07:22 -070050bindir="$scriptdir/bin"
Gavin Howardc494b572018-09-27 13:34:45 -060051
Gavin Howarddbbe3252019-02-18 11:07:22 -070052for exe in $bindir/*; do
Gavin Howard4ffe5a92018-09-26 20:58:31 -060053
Gavin Howard2bc50a92018-10-12 16:59:44 -060054 base=$(basename "$exe")
Gavin Howard4ffe5a92018-09-26 20:58:31 -060055
Gavin Howard2bc50a92018-10-12 16:59:44 -060056 if [ -L "$exe" ]; then
Gavin Howarde26c6f92019-02-18 12:50:23 -070057 link=$(readlink "$exe")
Gavin Howard5d057152019-01-29 10:31:40 -070058 "$INSTALL" -Dlm 755 "$link$exec_suffix" "$installdir/$base$exec_suffix"
Gavin Howard2bc50a92018-10-12 16:59:44 -060059 else
Gavin Howard5d057152019-01-29 10:31:40 -070060 "$INSTALL" -Dm 755 "$exe" "$installdir/$base$exec_suffix"
Gavin Howard2bc50a92018-10-12 16:59:44 -060061 fi
Gavin Howard4ffe5a92018-09-26 20:58:31 -060062
rofl0r8f19ed92018-04-01 20:54:56 +010063done