head	1.2;
access;
symbols
	VER_0_3:1.2
	VER_0_2:1.1;
locks; strict;
comment	@# @;


1.2
date	95.03.24.11.43.35;	author coulter;	state Exp;
branches;
next	1.1;

1.1
date	95.02.18.08.36.38;	author coulter;	state Exp;
branches;
next	;


desc
@duplicate a directory.
@


1.2
log
@Checkin version for 0.3 distribution.
@
text
@#! /bin/ksh
USAGE='USAGE: duplicate_dir DIR_PATH MOUNT_PATH MAP_TO
	For every file in directory DIR_PATH, create a symbolic link to
	it by the same name in the current directory.  If the link is
	below MOUNT_PATH, replace it with a linke with MOUNT_PATH
	replace by MAP_TO
'  
# (C) Copyright 1995 by Michael Coulter.  All rights reserved.

# define std functions

   ISOFS_UTIL_DIR="${ISOFS_UTIL_DIR:-/usr/src/linux/fs/isofs/Utils}"
   . "$ISOFS_UTIL_DIR/ksh_fns"


# Process parameters

   if [ $# -ne 3 ]
   then
      echo "$USAGE" >&2
      echo "3 arguments required.  $# given." >&2
      exit 1
   fi
   if [ ! -d "$1" ]
   then
      echo "$1 is not a directory"
   fi
   DIR_ARG="$1"; shift
   if [ ! -d "$1" ]
   then
      echo "$1 is not a directory"
   fi
   MOUNT_PATH="$1"; shift
   if [ ! -d "$1" ]
   then
      echo "$1 is not a directory"
   fi
   MAP_TO="$1"; shift

# Set DIR_PATH to hard path

   set -P # print absolut hw path
   HERE="$PWD"
   check_cmd 2 cd "$DIR_ARG"
   DIR_PATH="$PWD"
   check_cmd 3 cd "$HERE"

# Do it

   PREFIX="${MAP_TO%/}/"
   (cd "$DIR_PATH"; ls -a -1) | while read FILE
   do
      if [ "$FILE" != '.' -a "$FILE" != '..' ]
      then
	 DEST_FILE="$(follow_link "${DIR_PATH}/${FILE}")"
	 if [ "$DEST_FILE" != "${DEST_FILE#${MOUNT_PATH}}" ]
	 then
	    # Use equivalent path
	    DEST_FILE="${DEST_FILE#${MOUNT_PATH}/}"
	    DEST_FILE="${PREFIX}$DEST_FILE"
	 fi
	 ## echo "HERE is $HERE"
	 ## echo "DEST_FILE is $DEST_FILE"
	 ## echo "FILE is $FILE"
	 ## echo "PWD is $PWD"
	 if [ "$DEST_FILE" = "$HERE/$FILE" ]
	 then
	    ln -s "$DIR_PATH/$FILE" "$FILE"
	 else
	    # Use relative path if possible
	    ## echo "HERE is $HERE"
	    ## echo "DEST_FILE is $DEST_FILE"
	    DEST_FILE="${DEST_FILE#${HERE}/}"
	    ## echo ln -s "$DEST_FILE" "${FILE}"
	    ln -s "$DEST_FILE" "${FILE}"
	 fi
      fi
   done
@


1.1
log
@Checkpoint version before fixing /usr/bin install
@
text
@d8 1
@
