forked from legionus/libshell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshell-run
45 lines (39 loc) · 1.11 KB
/
shell-run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/sh -efu
### This file is covered by the GNU General Public License,
### which should be included with libshell as the file LICENSE.
### All copyright information are listed in the COPYING.
if [ -z "${__included_shell_run-}" ]; then
__included_shell_run=1
. shell-args
. shell-source
### Execute command if file is executable.
### Usage: run_if_executable /file arg1 arg2
### or: run_if_executable file arg1 arg2
run_if_executable()
{
local v f
f="$1"; shift
! __shell_source_find v "$f" || [ ! -x "$v" ] || "$v" "$@"
}
### Run scripts from directory.
### Usage: run_scripts <dir> [args]
RUN_SCRIPTS_EXCLUDE='*.rpm* *.swp *,v *~ *.\#'
SCRIPT_ERROR_FATAL=${SCRIPT_ERROR_FATAL:-false}
run_scripts()
{
[ "$#" -ge 1 ] ||
fatal "Usage: run_scripts <dir> [args]"
local p f d rc=0
d="$(opt_check_dir "dir" "$1")"; shift
for f in $(find -L "$d" -mindepth 1 -maxdepth 1 -type f | sort); do
for p in $RUN_SCRIPTS_EXCLUDE; do
[ -n "${f##$p}" ] ||
continue 2
done
run_if_executable "$f" "$@" || rc=1
[ "$SCRIPT_ERROR_FATAL" = true ] &&
[ $rc -gt 0 ] && return $rc
done
return $rc
}
fi #__included_shell_run