run-parts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #! /bin/sh -
  2. # Copyright (c) 2017-2018 Matias Fonzo.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. if test $# -eq 0
  16. then
  17. echo "An alternative to Debian run-parts(8)"
  18. echo ""
  19. echo "Usage: $0 <directory>"
  20. exit 0
  21. fi
  22. if test ! -d "$1"
  23. then
  24. echo "Error '$1' is not a valid directory." 1>&2
  25. echo "Usage: $0 <directory>" 1>&2
  26. exit 1
  27. fi
  28. SUFFIXES_TO_IGNORE="~ ^ , .bak .new"
  29. # Loop
  30. for script in "$1"/*
  31. do
  32. test -f "$script" || continue;
  33. for suffix in $SUFFIXES_TO_IGNORE
  34. do
  35. case $script in
  36. *${suffix})
  37. continue 2
  38. ;;
  39. esac
  40. done
  41. unset suffix
  42. if test -x "$script"
  43. then
  44. "$script" || echo "$script failed." 1>&2
  45. fi
  46. done