Gavin Howard | 3b756a3 | 2018-10-12 17:40:21 -0600 | [diff] [blame^] | 1 | #! /bin/sh |
| 2 | # |
| 3 | # Copyright 2018 Gavin D. Howard |
| 4 | # |
| 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. |
| 15 | # |
| 16 | |
| 17 | usage() { |
| 18 | printf "usage: %s bin_dir link\n" "$0" 1>&2 |
| 19 | exit 1 |
| 20 | } |
| 21 | |
| 22 | test "$#" -gt 1 || usage |
| 23 | |
| 24 | bindir="$1" |
| 25 | shift |
| 26 | |
| 27 | link="$1" |
| 28 | shift |
| 29 | |
| 30 | cd "$bindir" |
| 31 | |
| 32 | for exe in ./*; do |
| 33 | |
| 34 | if [ ! -L "$exe" ]; then |
| 35 | |
| 36 | base=$(basename "$exe") |
| 37 | |
| 38 | if [ "${base##*.}" != "$base" ]; then |
| 39 | base=${base%.*} |
| 40 | name=${$exe/$base/$link} |
| 41 | else |
| 42 | name="$link" |
| 43 | fi |
| 44 | |
| 45 | |
| 46 | ln -s "$exe" "./$name" |
| 47 | |
| 48 | exit 0 |
| 49 | fi |
| 50 | |
| 51 | done |