head	1.6;
access;
symbols
	VER_0_3:1.6
	VER_0_2:1.5;
locks; strict;
comment	@# @;


1.6
date	95.03.24.11.43.35;	author coulter;	state Exp;
branches;
next	1.5;

1.5
date	95.03.10.02.42.22;	author coulter;	state Exp;
branches;
next	1.4;

1.4
date	95.02.19.16.06.41;	author coulter;	state Exp;
branches;
next	1.3;

1.3
date	95.02.19.10.09.34;	author coulter;	state Exp;
branches;
next	1.2;

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

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


desc
@script to search disk for links to update
@


1.6
log
@Checkin version for 0.3 distribution.
@
text
@#! /bin/ksh
USAGE='USAGE: check_links [ -d config_prefix ] [ ROOT_DIR ]
   Check for links below ROOT_DIR which should be replaced and replace
   them.
   Uses ISOFS_UTIL_DIR and ${ISOFS_UTIL_DIR}/${CONFIG_PREFIX}config to set 
   MOUNT_PATH and MAP_TO_PATH
'
# (C) Copyright 1995 by Michael Coulter.  All rights reserved.

# Process parameters

   CONFIG_PREFIX=""
   if [ $# -ge 2 -a "$1" = "-d" ]
   then
      shift  # done with -d
      CONFIG_PREFIX="$1"; shift
   fi
   if [ $# -gt 1 ]
   then
      echo "$USAGE" >&2
      echo "Too many arguments." >&2
      exit 1
   fi
   ROOT_DIR="/"
   if [ $# -eq 1 ]
   then
      ROOT_DIR="$1"; shift
   fi

# Set variables

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

# Of the link files, find those which point to a file below $MOUNT_PATH and
# for which the equivalent link exists below $MAP_TO_PATH

HERE="$PWD"

# Do it

   echo "Checking links below $ROOT_DIR"

   ${FIND_LINKS} "$ROOT_DIR" | while read FILE REST
   do
      check_one_link "$FILE" "$MOUNT_PATH" "$MAP_TO_PATH"
   done
@


1.5
log
@Checkin files modified to make version 0.2
@
text
@d8 1
@


1.4
log
@Checkpoint version 0.1
@
text
@d2 1
a2 1
USAGE='USAGE: check_links [ ROOT_DIR ]
d5 1
a5 1
   Uses ISOFS_UTIL_DIR and ${ISOFS_UTIL_DIR}/config to set 
a8 7
# Set variables

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

d11 6
d28 7
@


1.3
log
@Checkpoint file.  About to introduce check_one_link.
@
text
@d41 1
a41 28
      LINK="$(ls -l "$FILE" 2> /dev/null | cut -c56-500 | sed -e 's/^.* //')"
      ##echo "check: LINK is $LINK"
      if [ "$LINK" != "${LINK#$MOUNT_PATH}" ]
      then
	 # link points at CD.  It should not be a link file there.
	 DEST="$(follow_link "$LINK")"
	 ##echo "check: DEST is $DEST"
	 if [ "$DEST" = "${DEST#$MOUNT_PATH}" ]
	 then
	    # The destination of the link is not on the CD.  Replace the
	    # link
	       echo "check_links: Replace link at $FILE with $DEST"
	       replace_link "$FILE" "$DEST"
	       exit 0
	 fi
	 ROOTED="${DEST#${MOUNT_PATH}}"
	 if [ "$MAP_TO_PATH" = "/" ]
	 then
	    EQUIV="$ROOTED"
	 else
	    EQUIV="${MAP_TO_PATH}$ROOTED"
	 fi
	 if [ "$EQUIV" != "$FILE" ]
	 then
	    echo "check_links: Replace link at $FILE with $EQUIV"
	    replace_link "$FILE" "$EQUIV"
	 fi
      fi # LINK is link under MOUNT_PATH
@


1.2
log
@Checkpoint file.
@
text
@d37 1
a37 1
   ##echo "Checking links below $ROOT_DIR"
d48 9
d59 1
a59 1
	    EQUIV="${DEST#${MOUNT_PATH}}"
d61 1
a61 1
	    EQUIV="${MAP_TO_PATH}${DEST#${MOUNT_PATH}}"
d63 1
a63 2
	 ##echo "check: at 1 EQUIV is $EQUIV"
	 if [ -L "$LINK" ]
d65 3
a67 22
	    if [ -L "$EQUIV" ]
	    then
	       EQUIV="$(follow_link "$EQUIV")"
	    fi
	    if [ "$EQUIV" = "${EQUIV#$MOUNT_PATH}" -a -e "$EQUIV" ]
	    then
	       ##echo "check: Replace link at $FILE with $EQUIV"
	       replace_link "$FILE" "$EQUIV"
	    fi
	 else
	    if [ "$MAP_TO_PATH" = "/" ]
	    then
	       EQUIV="${LINK#${MOUNT_PATH}}"
	    else
	       EQUIV="${MAP_TO_PATH}/${LINK#${MOUNT_PATH}}"
	    fi
	    if [ -e "$EQUIV" -a ! -L "$EQUIV" ]
	    then
	       ##echo "check: Replace $FILE with link to eqiv $EQUIV"
	       replace_link "$FILE" "$EQUIV"
	    fi
	 fi # else EQUIV is not link
@


1.1
log
@Checkpoint version before fixing /usr/bin install
@
text
@d2 6
d12 1
d16 14
a33 1
MOUNT_PATH=/system_cd
d35 9
a43 7
find_links | while read FILE REST
do
   LINK="$(ls -l "$FILE" 2> /dev/null | cut -c56-500 | sed -e 's/^.* //')"
   if [ "$LINK" != "${LINK#$MOUNT_PATH}" ]
   then
      # link points at CD.  It should not be a link file there.
      if [ -L "$LINK" ] 
d45 5
a49 3
         DEST="$(follow_link "$LINK")"
         if [ "$MAP_TO_PATH" = "" ]
         then
d52 29
a80 21
	    EQUIV="${MAP_TO_PATH}/${DEST#${MOUNT_PATH}}"
         fi
         if [ -L "$EQUIV" ]
         then
            EQUIV="$(follow_link "$EQUIV")"
         fi
         if [ "$EQUIV" = "${EQUIV#$MOUNT_PATH}" -a -e "$EQUIV" ]
         then
	    echo "check: Replace link at $FILE with $EQUIV"
            replace_link "$FILE" "$EQUIV"
         fi
      else
         EQUIV="${LINK#$MOUNT_PATH}"
         if [ -e "$EQUIV" -a ! -L "$EQUIV" ]
         then
            echo "check: Replace $FILE with link to eqiv $EQUIV"
            replace_link "$FILE" "$EQUIV"
         fi
      fi
   fi
done
@
