File: lndir.sh

package info (click to toggle)
graphicsmagick 1.3.12-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 38,696 kB
  • ctags: 13,568
  • sloc: ansic: 216,145; sh: 22,217; cpp: 17,727; perl: 3,936; makefile: 3,642; tcl: 2,200; python: 1,296; pascal: 125
file content (97 lines) | stat: -rwxr-xr-x 2,071 bytes parent folder | download | duplicates (10)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#! /bin/sh

# lndir - create shadow link tree
#
# Time stamp <89/11/28 18:56:54 gildea>
# By Stephen Gildea <gildea@bbn.com> based on
#  XConsortium: lndir.sh,v 1.1 88/10/20 17:37:16 jim Exp
#
# Modified slightly for ImageMagick by Bob Friesenhahn, 1999
#
# Used to create a copy of the a directory tree that has links for all
# non- directories.  If you are building the distribution on more than
# one machine, you should use this script.
#
# If your master sources are located in /usr/local/src/X and you would like
# your link tree to be in /usr/local/src/new-X, do the following:
#
# 	%  mkdir /usr/local/src/new-X
#	%  cd /usr/local/src/new-X
# 	%  lndir ../X
#
# Note: does not link files beginning with "."  Is this a bug or a feature?
#
# Improvements over R3 version:
#   Allows the fromdir to be relative: usually you want to say "../dist"
#   The name is relative to the todir, not the current directory.
#
# Bugs in R3 version fixed:
#   Do "pwd" command *after* "cd $DIRTO".
#   Don't try to link directories, avoiding error message "<dir> exists".
#   Barf with Usage message if either DIRFROM *or* DIRTO is not a directory.

SHELL=/bin/sh
USAGE="Usage: $0 fromdir [todir]"

if [ $# -lt 1 -o $# -gt 2 ]
then
    echo "$USAGE"
    exit 1
fi

DIRFROM=$1

if [ $# -eq 2 ];
then
    DIRTO=$2
else
    DIRTO=.
fi

if [ ! -d $DIRTO ]
then
    echo "$0: $DIRTO is not a directory"
    echo "$USAGE"
    exit 2
fi

cd $DIRTO

if [ ! -d $DIRFROM ]
then
    echo "$0: $DIRFROM is not a directory"
    echo "$USAGE"
    exit 2
fi

pwd=`pwd`

if [ `(cd $DIRFROM; pwd)` = $pwd ]
then
    echo "$pwd: FROM and TO are identical!"
    exit 1
fi

for file in `ls $DIRFROM`
do
    if [ ! -d $DIRFROM/$file ]
    then
	test -r $file || ln -s $DIRFROM/$file .
    else
	#echo $file:
	test -d $file || mkdir $file && chmod 777 $file
	(cd $file
	pwd=`pwd`
	case "$DIRFROM" in
	    /*) ;;
	    *)  DIRFROM=../$DIRFROM ;;
	esac
	if [ `(cd $DIRFROM/$file; pwd)` = $pwd ]
	then
	    echo "$pwd: FROM and TO are identical!"
	    exit 1
	fi
	${SHELL} $0 $DIRFROM/$file
	)
    fi
done