link-subdir 772 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#!/bin/sh
#
# Nico Schottelius <nico-linux //@// schottelius.org>
# Date: 13-Mär-2007
# Last Modified: -
# Description: Links files from /usr/packages/$pkg/$dir/* to /usr/local/$dir
#

if [ "$#" -ne 2 ]; then
   echo "$0: package (below /usr/packages/) subdir (like bin, lib or include)"
   exit 1
fi

basedir="$1"
subdir="$2"
destination=/usr/local
ddir="${destination}/${subdir}"

# test for existence, abort if conflicts are there
do_exit=0
for file in "${basedir}/${subdir}"/*; do
   basename=$(basename "$file")
   dest="${ddir}/${basename}"

   if [ -e "${dest}" ]; then
      echo "${dest} already exists, abort"
      do_exit=1
   fi
done

if [ "$do_exit" = 1 ]; then
   exit 1
fi

# link!
for file in "${basedir}/${subdir}"/*; do
   ln -s "$file" "$ddir"
done