run-script 431 B

123456789101112131415161718192021222324
  1. #!/bin/sh
  2. # Copyright Broadcom, Inc. All Rights Reserved.
  3. # SPDX-License-Identifier: APACHE-2.0
  4. set -u
  5. if [ $# -eq 0 ]; then
  6. >&2 echo "No arguments provided"
  7. exit 1
  8. fi
  9. script=$1
  10. exit_code="${2:-96}"
  11. fail_if_not_present="${3:-n}"
  12. if test -f "$script"; then
  13. sh $script
  14. if [ $? -ne 0 ]; then
  15. exit $((exit_code))
  16. fi
  17. elif [ "$fail_if_not_present" = "y" ]; then
  18. >&2 echo "script not found: $script"
  19. exit 127
  20. fi