1#! /bin/sh 2 3# lndir - create shadow link tree 4# 5# Time stamp <89/11/28 18:56:54 gildea> 6# By Stephen Gildea <gildea@bbn.com> based on 7# XConsortium: lndir.sh,v 1.1 88/10/20 17:37:16 jim Exp 8# 9# Modified slightly for ImageMagick by Bob Friesenhahn, 1999 10# 11# Used to create a copy of the a directory tree that has links for all 12# non- directories. If you are building the distribution on more than 13# one machine, you should use this script. 14# 15# If your main sources are located in /usr/local/src/X and you would like 16# your link tree to be in /usr/local/src/new-X, do the following: 17# 18# % mkdir /usr/local/src/new-X 19# % cd /usr/local/src/new-X 20# % lndir ../X 21# 22# Note: does not link files beginning with "." Is this a bug or a feature? 23# 24# Improvements over R3 version: 25# Allows the fromdir to be relative: usually you want to say "../dist" 26# The name is relative to the todir, not the current directory. 27# 28# Bugs in R3 version fixed: 29# Do "pwd" command *after* "cd $DIRTO". 30# Don't try to link directories, avoiding error message "<dir> exists". 31# Barf with Usage message if either DIRFROM *or* DIRTO is not a directory. 32 33USAGE="Usage: $0 fromdir [todir]" 34 35if [ $# -lt 1 -o $# -gt 2 ] 36then 37 echo "$USAGE" 38 exit 1 39fi 40 41DIRFROM=$1 42 43if [ $# -eq 2 ]; 44then 45 DIRTO=$2 46else 47 DIRTO=. 48fi 49 50if [ ! -d $DIRTO ] 51then 52 echo "$0: $DIRTO is not a directory" 53 echo "$USAGE" 54 exit 2 55fi 56 57cd $DIRTO 58 59if [ ! -d $DIRFROM ] 60then 61 echo "$0: $DIRFROM is not a directory" 62 echo "$USAGE" 63 exit 2 64fi 65 66pwd=`pwd` 67 68if [ `(cd $DIRFROM; pwd)` = $pwd ] 69then 70 echo "$pwd: FROM and TO are identical!" 71 exit 1 72fi 73 74for file in `ls $DIRFROM` 75do 76 if [ ! -d $DIRFROM/$file ] 77 then 78 test -r $file || ln -s $DIRFROM/$file . 79 else 80 #echo $file: 81 test -d $file || mkdir $file && chmod 777 $file 82 (cd $file 83 pwd=`pwd` 84 case "$DIRFROM" in 85 /*) ;; 86 *) DIRFROM=../$DIRFROM ;; 87 esac 88 if [ `(cd $DIRFROM/$file; pwd)` = $pwd ] 89 then 90 echo "$pwd: FROM and TO are identical!" 91 exit 1 92 fi 93 $0 $DIRFROM/$file 94 ) 95 fi 96done 97