~ubuntu-branches/ubuntu/trusty/bash/trusty-security

« back to all changes in this revision

Viewing changes to support/fixlinks

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-03-03 22:52:05 UTC
  • mfrom: (1.3.5) (2.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20140303225205-87ltrt5kspeq0g1b
Tags: 4.3-1ubuntu1
* Merge with Debian; remaining changes:
  - skel.bashrc:
    - Run lesspipe.
    - Enable ls aliases.
    - Set options in ll alias to -alF.
    - Define an alert alias.
    - Enabled colored grep aliases.
  - etc.bash.bashrc:
    - Add sudo hint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
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