init version.
[bush.git] / support / fixlinks
bloba65000aec62c32a8dd4d80cf6ff3c6ba44c6cb98
1 #! /bin/sh
3 # fixlinks - make symlinks in the bush source tree so that there is
4 # exactly one version of any given source file.
6 # Copyright (C) 1996-2002 Free Software Foundation, Inc.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 SRCDIR=.
23 while [ $# -gt 0 ]; do
24 case "$1" in
25 -s) shift; SRCDIR=$1 ;;
26 -u) unfix=yes ;;
27 -h) hardlinks=yes ;;
28 -*) echo "$0: $1: bad option" 1>&2
29 echo "$0: usage: $0 [-hu] [-s srcdir] [linkmap]" 1>&2
30 exit 1;;
31 *) break ;;
32 esac
33 shift
34 done
36 if [ ! -d $SRCDIR/builtins ]; then
37 echo "$0: must be run with valid -s argument or from source directory" 1>&2
38 exit 1
41 if [ $# -eq 0 ]; then
42 linkfile=$SRCDIR/support/SYMLINKS
43 else
44 linkfile=$1
47 if [ ! -f "$linkfile" ]; then
48 echo "$0: symlink map file \`$linkfile' does not exist"
49 exit 1
52 rm_ltmp=false
53 LINKTEMP=`mktemp -t linktmp.XXXXXXXX 2>/dev/null`
54 if [ -z "$LINKTEMP" ]; then
55 : ${TMPDIR:=/tmp}
56 LINKTEMP=${TMPDIR}/linktmp.$$
57 rm_ltmp=true
60 $rm_ltmp && rm -f ${LINKTEMP}
61 # if the user specified hard links, then do that. otherwise, try to use
62 # symlinks if they're present
63 if [ -n "$hardlinks" ]; then
64 LN=ln
65 elif (ln -s /dev/null ${LINKTEMP}) >/dev/null 2>&1; then
66 LN="ln -s"
67 else
68 LN=ln
70 rm -f ${LINKTEMP}
72 while read name target
74 case "$name" in
75 \#*) continue;;
76 esac
78 rm -f $name
79 case "$unfix" in
80 yes) dirname=`expr "$name" ':' '^\(.*\)/[^/]*'`
81 [ -z "$dirname" ] && dirname=.
82 cp $dirname/$target $name
83 echo $target copied to $name ;;
84 *) $LN $target $name ; echo "$name -> $target" ;;
85 esac
87 done < $linkfile
89 exit 0