Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 1 | #! /bin/sh |
rofl0r | 8f19ed9 | 2018-04-01 20:54:56 +0100 | [diff] [blame] | 2 | # |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 3 | # Copyright 2018 Gavin D. Howard |
rofl0r | 8f19ed9 | 2018-04-01 20:54:56 +0100 | [diff] [blame] | 4 | # |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 5 | # 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. |
rofl0r | 8f19ed9 | 2018-04-01 20:54:56 +0100 | [diff] [blame] | 15 | # |
| 16 | |
| 17 | usage() { |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 18 | printf "usage: %s install_dir executable [symlinks...]\n" "$0" 1>&2 |
| 19 | exit 1 |
rofl0r | 8f19ed9 | 2018-04-01 20:54:56 +0100 | [diff] [blame] | 20 | } |
| 21 | |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 22 | script=$(realpath "$0") |
| 23 | scriptdir=$(dirname "$script") |
rofl0r | 8f19ed9 | 2018-04-01 20:54:56 +0100 | [diff] [blame] | 24 | |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 25 | INSTALL="$scriptdir/safe-install.sh" |
| 26 | |
| 27 | test "$#" -gt 1 || usage |
| 28 | |
| 29 | installdir="$1" |
| 30 | shift |
| 31 | |
| 32 | exe="$1" |
| 33 | shift |
| 34 | |
Gavin Howard | c494b57 | 2018-09-27 13:34:45 -0600 | [diff] [blame] | 35 | while [ ! -f "$exe" ]; do |
| 36 | exe="$1" |
| 37 | shift |
| 38 | done |
| 39 | |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 40 | "$INSTALL" -Dm 755 "$exe" "$installdir/$exe" |
| 41 | |
| 42 | while [ $# -gt 0 ]; do |
| 43 | |
| 44 | link="$1" |
| 45 | shift |
| 46 | |
| 47 | base=$(basename "$link") |
| 48 | |
Gavin Howard | 67cb55d | 2018-09-26 20:59:34 -0600 | [diff] [blame] | 49 | rm -f "$installdir/$base" |
Gavin Howard | 1349eba | 2018-10-10 18:43:55 -0600 | [diff] [blame^] | 50 | ln -s "./$exe" "$installdir/$base" |
Gavin Howard | 4ffe5a9 | 2018-09-26 20:58:31 -0600 | [diff] [blame] | 51 | |
rofl0r | 8f19ed9 | 2018-04-01 20:54:56 +0100 | [diff] [blame] | 52 | done |