1#! /bin/sh 2# 3# fixlinks - make symlinks in the bash source tree so that there is 4# exactly one version of any given source file. 5# 6# Copyright (C) 1996-2002 Free Software Foundation, Inc. 7# 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. 12# 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. 17# 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/>. 20# 21 22SRCDIR=. 23while [ $# -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 34done 35 36if [ ! -d $SRCDIR/builtins ]; then 37 echo "$0: must be run with valid -s argument or from source directory" 1>&2 38 exit 1 39fi 40 41if [ $# -eq 0 ]; then 42 linkfile=$SRCDIR/support/SYMLINKS 43else 44 linkfile=$1 45fi 46 47if [ ! -f "$linkfile" ]; then 48 echo "$0: symlink map file \`$linkfile' does not exist" 49 exit 1 50fi 51 52rm_ltmp=false 53LINKTEMP=`mktemp -t linktmp.XXXXXXXX 2>/dev/null` 54if [ -z "$LINKTEMP" ]; then 55 : ${TMPDIR:=/tmp} 56 LINKTEMP=${TMPDIR}/linktmp.$$ 57 rm_ltmp=true 58fi 59 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 63if [ -n "$hardlinks" ]; then 64 LN=ln 65elif (ln -s /dev/null ${LINKTEMP}) >/dev/null 2>&1; then 66 LN="ln -s" 67else 68 LN=ln 69fi 70rm -f ${LINKTEMP} 71 72while read name target 73do 74 case "$name" in 75 \#*) continue;; 76 esac 77 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 86 87done < $linkfile 88 89exit 0 90