blob: 751f40c7319a8274cae27a9e531d26c25a875938 [file] [log] [blame]
Gavin Howard4ffe5a92018-09-26 20:58:31 -06001#! /bin/sh
rofl0r8f19ed92018-04-01 20:54:56 +01002#
Gavin Howard4ffe5a92018-09-26 20:58:31 -06003# Copyright 2018 Gavin D. Howard
rofl0r8f19ed92018-04-01 20:54:56 +01004#
Gavin Howard4ffe5a92018-09-26 20:58:31 -06005# Permission to use, copy, modify, and/or distribute this software for any
6# purpose with or without fee is hereby granted.
7#
8# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14# PERFORMANCE OF THIS SOFTWARE.
rofl0r8f19ed92018-04-01 20:54:56 +010015#
16
17usage() {
Gavin Howard4ffe5a92018-09-26 20:58:31 -060018 printf "usage: %s install_dir executable [symlinks...]\n" "$0" 1>&2
19 exit 1
rofl0r8f19ed92018-04-01 20:54:56 +010020}
21
Gavin Howard4ffe5a92018-09-26 20:58:31 -060022script=$(realpath "$0")
23scriptdir=$(dirname "$script")
rofl0r8f19ed92018-04-01 20:54:56 +010024
Gavin Howard4ffe5a92018-09-26 20:58:31 -060025INSTALL="$scriptdir/safe-install.sh"
26
27test "$#" -gt 1 || usage
28
29installdir="$1"
30shift
31
32exe="$1"
33shift
34
Gavin Howardc494b572018-09-27 13:34:45 -060035while [ ! -f "$exe" ]; do
36 exe="$1"
37 shift
38done
39
Gavin Howard4ffe5a92018-09-26 20:58:31 -060040"$INSTALL" -Dm 755 "$exe" "$installdir/$exe"
41
42while [ $# -gt 0 ]; do
43
44 link="$1"
45 shift
46
47 base=$(basename "$link")
48
Gavin Howard67cb55d2018-09-26 20:59:34 -060049 rm -f "$installdir/$base"
Gavin Howard1349eba2018-10-10 18:43:55 -060050 ln -s "./$exe" "$installdir/$base"
Gavin Howard4ffe5a92018-09-26 20:58:31 -060051
rofl0r8f19ed92018-04-01 20:54:56 +010052done