5 kx #!/bin/sh
5 kx # run-parts: Runs all the scripts found in a directory.
5 kx
5 kx # keep going when something fails
5 kx set +e
5 kx
5 kx if [ $# -lt 1 ]; then
5 kx echo "Usage: run-parts <directory>"
5 kx exit 1
5 kx fi
5 kx
5 kx if [ ! -d $1 ]; then
5 kx echo "Not a directory: $1"
5 kx echo "Usage: run-parts <directory>"
5 kx exit 1
5 kx fi
5 kx
5 kx # There are several types of files that we would like to
5 kx # ignore automatically, as they are likely to be backups
5 kx # of other scripts:
5 kx IGNORE_SUFFIXES="~ ^ , .bak .new .rpmsave .rpmorig .rpmnew .swp"
5 kx
5 kx # Main loop:
5 kx for SCRIPT in $1/* ; do
5 kx # If this is not a regular file, skip it:
5 kx if [ ! -f $SCRIPT ]; then
5 kx continue
5 kx fi
5 kx # Determine if this file should be skipped by suffix:
5 kx SKIP=false
5 kx for SUFFIX in $IGNORE_SUFFIXES ; do
5 kx if [ ! "$(basename $SCRIPT $SUFFIX)" = "$(basename $SCRIPT)" ]; then
5 kx SKIP=true
5 kx break
5 kx fi
5 kx done
5 kx if [ "$SKIP" = "true" ]; then
5 kx continue
5 kx fi
5 kx # If we've made it this far, then run the script if it's executable:
5 kx if [ -x $SCRIPT ]; then
5 kx $SCRIPT || echo "$SCRIPT failed."
5 kx fi
5 kx done
5 kx
5 kx exit 0