| 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 2, or (at your option)
|
|---|
| 11 | # 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, write to the Free Software
|
|---|
| 20 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
|---|
| 21 |
|
|---|
| 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
|
|---|
| 35 |
|
|---|
| 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
|
|---|
| 39 | fi
|
|---|
| 40 |
|
|---|
| 41 | if [ $# -eq 0 ]; then
|
|---|
| 42 | linkfile=$SRCDIR/support/SYMLINKS
|
|---|
| 43 | else
|
|---|
| 44 | linkfile=$1
|
|---|
| 45 | fi
|
|---|
| 46 |
|
|---|
| 47 | if [ ! -f "$linkfile" ]; then
|
|---|
| 48 | echo "$0: symlink map file \`$linkfile' does not exist"
|
|---|
| 49 | exit 1
|
|---|
| 50 | fi
|
|---|
| 51 |
|
|---|
| 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
|
|---|
| 58 | fi
|
|---|
| 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
|
|---|
| 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
|
|---|
| 69 | fi
|
|---|
| 70 | rm -f ${LINKTEMP}
|
|---|
| 71 |
|
|---|
| 72 | while read name target
|
|---|
| 73 | do
|
|---|
| 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 |
|
|---|
| 87 | done < $linkfile
|
|---|
| 88 |
|
|---|
| 89 | exit 0
|
|---|