home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- #
- # Go through a hierarchy of folders and icons and create links called
- # .dir.tiff that point to some image in each folder.
- #
- # Expects the hierarchy Section/Folder/image.tiff.
- #
-
- PROG="`basename $0`"
- USAGE="${PROG} folder [folders...]"
- VERSION="Sun Dec 4 16:10:56 EST 1994"
-
- #
- # Print help if no arguments
- test $# = 0 && {
- cat << EOF
-
- USAGE: ${USAGE}
-
- ${PROG} is a utility that creates .dir.tiff and .opendir.tiff
- links in a two-level image archive set up like the
- NeXT-icon@gun.com multimedia mailing list archives. Command
- line arguments consist of a top-level folder names that
- contains lower level folders each containing at least one
- TIFF image.
-
- The hierarchy should be set up as follows:
-
- Section/section.dir.tiff
- Section/section.opendir.tiff
- Section/Folder1/image1.tiff
- Section/Folder1/image2.tiff
- Section/Folder2/anotherimage.dir.tiff
- Section/Folder3/onemoreimage.tiff
-
- ${PROG} will create .dir and .opendir.tiff links in the
- first Section level and each lower Folder level, but will
- not proceed into third or lower levels, regardless of
- whether they level exists.
-
- ${PROG} attempts to create .dir.tiff and .opendir.tiff
- links using the following criteria:
-
- If .opendir.tiff does not exist, do the following:
-
- if a TIFF image with the same name as it's folder
- exists with a .opendir.tiff extension, then link
- .opendir.tiff to it.
-
- If .dir.tiff does not exist, do the following:
-
- If a TIFF image with the same name as it's folder
- exists, with a .dir.tiff extension, then link
- .dir.tiff to it.
-
- If a TIFF image with the same name as it's folder
- exists without a .dir.tiff extension, then link
- .dir.tiff to it.
-
- If any TIFF images exist in the folder, link
- .dir.tiff to the first one in the directory.
-
- BUGS
- ${PROG} must be run from a UNIX prompt, and cannot be run
- from the Workspace.
-
- Should have a front end.
-
- By Timothy Reed <treed@bmt.gun.com>, $VERSION
- Thanks to Howard Ship <hship@sinistar.cac.stratus.com> for telling me
- present the next-icon@gun.com archives this way.
-
- For information on subscribing to the list, send a message with the word
- 'subscribe' or 'help' to NeXT-icon-request@gun.com.
-
- EOF
-
- }
-
- #
- # For each folder specified on the command line.
- for SECTION in $* ; do
- #
- # Check if $SECTION is a folder, and continue to the next one if not.
- test ! -d ${SECTION} && {
- echo "${PROG}: No such folder ${SECTION}. Continuing to next folder."
- continue
- }
- #
- # Run this in a subshell, since we're entering each SECTION one at a time
- (
- cd ${SECTION}
- #
- # Take care of .opendir.tiff first, since it is a less-critical and
- # difficult to locate file.
- test ! -f .opendir.tiff && {
- if test -f ${SECTION}.opendir.tiff ; then
- echo "${PROG}: Linking ${SECTION}.opendir.tiff to .opendir.tiff"
- ln -s ${SECTION}.opendir.tiff .opendir.tiff
- fi
- }
- test ! -f .dir.tiff && {
- if test -f ${SECTION}.dir.tiff ; then
- # Get the file named ${SECTION}.dir.tiff first.
- FIRST_FILE=${SECTION}.dir.tiff
- elif test -f ${SECTION}.tiff ; then
- # If SECTION.dir.tiff doesn't exist, get the file named ${SECTION}.tiff.
- FIRST_FILE=${SECTION}.tiff
- else
- # Now try to get the first tiff file in the directory.
- FIRST_FILE="`echo *.tiff 2>/dev/null | awk '{print $1}' 2>/dev/null`"
- fi
- test "${FIRST_FILE}" != '*.tiff' && {
- echo "Linking ${FIRST_FILE} to .dir.tiff"
- ln -s ${FIRST_FILE} .dir.tiff
- }
-
- # If tiff doesn't appear as the first word, skip to the next one.
- test -z "${FIRST_FILE}" && {
- echo "${PROG}: No images in ${SECTION}/${DIR}."
- continue
- }
- }
- for DIR in * ; do
- #
- # If this is not a directory, skip on to the next one.
- test ! -d ${DIR} && {
- # echo "$DIR is not a directory."
- continue
- }
- #
- # Run this in a subshell, since we're entering each subdirectory one at
- # a time.
- (
- # Skip to the next one if this directory already contains a .dir.tiff.
- # We don't care so much about .opendir.tiff files.
- test -f ${DIR}/.dir.tiff && {
- # echo "${SECTION}/${DIR} already contains a .dir.tiff"
- continue
- }
-
- # Enter the subdirectory.
- cd $DIR
-
- # Get the first tiff file in the directory.
- FIRST_FILE="`echo *.tiff 2>/dev/null | awk '{print $1}' 2>/dev/null`"
-
- # If tiff doesn't appear as the first word, skip to the next one.
- test -z "${FIRST_FILE}" && {
- echo "No tiffs in ${SECTION}/${DIR}."
- continue
- }
-
- # Create .opendir.tiff first, since we continue regardless of whether
- # this is successful.
- test ! -f .opendir.tiff && {
- for EXT in opendir.tiff ; do
- test -f ${DIR}.opendir.tiff && {
- echo "Linking ${SECTION}/${DIR}/${DIR}.${EXT} to .opendir.tiff"
- ln -s ${DIR}.${EXT} .opendir.tiff
- }
- done
- }
-
- # Check for directoryname.dir.tiff and directoryname.tiff.
- for EXT in dir.tiff tiff ; do
- test -f ${DIR}.${EXT} && {
- echo "Linking ${SECTION}/${DIR}/${DIR}.${EXT} to .dir.tiff"
- ln -s ${DIR}.${EXT} .dir.tiff
- continue
- }
- done
- test ! -f "${FIRST_FILE}" && {
- # echo "${FIRST_FILE} is not a file."
- continue
- }
- test ! -f .dir.tiff && {
- echo "Linking ${SECTION}/${DIR}/${FIRST_FILE} to .dir.tiff"
- ln -s ${FIRST_FILE} .dir.tiff
- }
- )
- done
- echo "Completed section ${SECTION}"
- )
- done
-