run-parts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/bin/sh
  2. # run-parts: Runs all the scripts found in a directory.
  3. # from Slackware, by Patrick J. Volkerding with ideas borrowed
  4. # from the Red Hat and Debian versions of this utility.
  5. # keep going when something fails
  6. set +e
  7. if [ $# -lt 1 ]; then
  8. echo "Usage: run-parts <directory>"
  9. exit 1
  10. fi
  11. if [ ! -d $1 ]; then
  12. echo "Not a directory: $1"
  13. echo "Usage: run-parts <directory>"
  14. exit 1
  15. fi
  16. # There are several types of files that we would like to
  17. # ignore automatically, as they are likely to be backups
  18. # of other scripts:
  19. IGNORE_SUFFIXES="~ ^ , .bak .new .rpmsave .rpmorig .rpmnew .swp"
  20. # Main loop:
  21. for SCRIPT in $1/* ; do
  22. # If this is not a regular file, skip it:
  23. if [ ! -f $SCRIPT ]; then
  24. continue
  25. fi
  26. # Determine if this file should be skipped by suffix:
  27. SKIP=false
  28. for SUFFIX in $IGNORE_SUFFIXES ; do
  29. if [ ! "$(basename $SCRIPT $SUFFIX)" = "$(basename $SCRIPT)" ]; then
  30. SKIP=true
  31. break
  32. fi
  33. done
  34. if [ "$SKIP" = "true" ]; then
  35. continue
  36. fi
  37. # If we've made it this far, then run the script if it's executable:
  38. if [ -x $SCRIPT ]; then
  39. $SCRIPT || echo "$SCRIPT failed."
  40. fi
  41. done
  42. exit 0