#!/bin/bash # # This script finds all symbolic links in the current directory, and creates # a file named ".cvs-symlinks" listing them. # # Usage: csym-add [-r|] # # Check for recursive usage # [ "$1" = "-r" ] && \ exec find . -type d -exec $0 \{\} \; # Slow, simple & should work! # Check for directory parameter # if [ "$1" != "" ]; then [ -d "$1" ] || \ { echo echo "Usage: $0 [-r|]" echo echo "Note that the directory must already be in CVS." echo exit 1 } [ -d "$1/CVS" ] && cd "$1" && pwd || exit 0 fi # Make the script handle variations in the format of "ls -l" # LEN=$(ls -lad . | wc -c |awk '{print $1}') let LEN=$LEN-1 # Generate link list. # ls -Al | grep -e ^l | cut -b$LEN- > .cvs-symlinks-tmp || \ { echo 'csym-add: Failed to create .cvs-symlinks-tmp!' exit 1 } # Nothing to see here? # [ -e .cvs-symlinks -o -s .cvs-symlinks-tmp ] || \ { rm -f .cvs-symlinks-tmp exit 0 } # Add to CVS tree if necessary # [ $(grep -c -e ^/.cvs-symlinks/ CVS/Entries) != 1 ] && \ { touch .cvs-symlinks [ -f .cvs-symlinks ] || \ { echo 'csym-add: .cvs-symlinks is not a file!' exit 1 } cvs add .cvs-symlinks || \ { echo 'csym-add: Failed to add .cvs-symlinks to CVS tree!' exit 1 } } # Anything to do? # [ -f .cvs-symlinks ] || exit 0 # Update! # rm -f .cvs-symlinks && \ mv .cvs-symlinks-tmp .cvs-symlinks && \ cvs commit -m "updated" .cvs-symlinks && \ exit 0 # :-( # echo 'csym-add: Failed to update and commit .cvs-symlinks, oh dear!' exit 1