Implement target execution
WEW
This commit is contained in:
parent
86cca17f45
commit
688c3827f7
66
firestarter
66
firestarter
@ -75,6 +75,10 @@ gettarget() {
|
|||||||
[ -r "$1" ] || return 1
|
[ -r "$1" ] || return 1
|
||||||
# Every odd line is a condition
|
# Every odd line is a condition
|
||||||
# Every even one is a target
|
# Every even one is a target
|
||||||
|
if [ -d "$1" ]; then
|
||||||
|
warn "Target is a directory: $1" 2
|
||||||
|
return 50
|
||||||
|
fi
|
||||||
local firstline
|
local firstline
|
||||||
while read -r checkline; do
|
while read -r checkline; do
|
||||||
if [ -z "$firstline" ]; then
|
if [ -z "$firstline" ]; then
|
||||||
@ -96,6 +100,35 @@ gettarget() {
|
|||||||
done < "$1"
|
done < "$1"
|
||||||
return 2
|
return 2
|
||||||
}
|
}
|
||||||
|
fsexec() {
|
||||||
|
# Execute an fsdefaults file
|
||||||
|
[ -z "$1" ] && return 1
|
||||||
|
local file="$1"
|
||||||
|
local filename="$(basename -- "$file")"
|
||||||
|
local logfile="$_optlogdir/$filename.log"
|
||||||
|
if gettarget "$file"; then
|
||||||
|
# It's a defaults file with a selected target
|
||||||
|
target="$_return"
|
||||||
|
log "Found target for $filename: \"$target\""
|
||||||
|
[ -n "$_optdryrun" ] && return
|
||||||
|
if [ -f "$logfile" ]; then
|
||||||
|
[ -f "$logfile.old" ] && rm "$logfile.old"
|
||||||
|
mv "$logfile" "$logfile.old"
|
||||||
|
fi
|
||||||
|
bash -c "$target" > "$logfile" 2>&1 &
|
||||||
|
elif [ $? = 50 ] && [ -x "$file" ]; then
|
||||||
|
# It's a shell script or executable symlink
|
||||||
|
log "Executing file: \"$filename\""
|
||||||
|
[ -n "$_optdryrun" ] && return
|
||||||
|
"$file" > "$logfile" 2>&1 &
|
||||||
|
else
|
||||||
|
warn "Could not execute target: \"$filename\""
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
fsstatus() {
|
||||||
|
# List statistics about firestarter
|
||||||
|
warn "NYI"
|
||||||
|
}
|
||||||
step_preexecute() {
|
step_preexecute() {
|
||||||
# Special things that can't use simple configuration files
|
# Special things that can't use simple configuration files
|
||||||
[ -n "$_optdryrun" ] && return 0
|
[ -n "$_optdryrun" ] && return 0
|
||||||
@ -187,7 +220,7 @@ step_execute() {
|
|||||||
fi
|
fi
|
||||||
# Skip our logs directory
|
# Skip our logs directory
|
||||||
[ "$_optlogdir" == "$file" ] && continue
|
[ "$_optlogdir" == "$file" ] && continue
|
||||||
fs_exec "$file"
|
fsexec "$file"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
step_postexecute() {
|
step_postexecute() {
|
||||||
@ -282,31 +315,6 @@ Copyright (c) 2019 rehashedsalt@cock.li
|
|||||||
Licensed under the MIT license
|
Licensed under the MIT license
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
fs_exec() {
|
|
||||||
# Execute an fsdefaults file
|
|
||||||
[ -z "$1" ] && return 1
|
|
||||||
local file="$1"
|
|
||||||
local filename="$(basename -- "$file")"
|
|
||||||
local logfile="$_optlogdir/$filename.log"
|
|
||||||
if gettarget "$file"; then
|
|
||||||
# It's a defaults file with a selected target
|
|
||||||
target="$_return"
|
|
||||||
log "Found target for $filename: \"$target\""
|
|
||||||
[ -n "$_optdryrun" ] && return
|
|
||||||
if [ -f "$logfile" ]; then
|
|
||||||
[ -f "$logfile.old" ] && rm "$logfile.old"
|
|
||||||
mv "$logfile" "$logfile.old"
|
|
||||||
fi
|
|
||||||
bash -c "$target" > "$logfile" 2>&1 &
|
|
||||||
elif [ $? = 50 ] && [ -x "$file" ]; then
|
|
||||||
# It's a shell script or executable symlink
|
|
||||||
log "Executing file: \"$filename\""
|
|
||||||
[ -n "$_optdryrun" ] && return
|
|
||||||
"$file" > "$logfile" 2>&1 &
|
|
||||||
else
|
|
||||||
warn "Could not execute file: \"$filename\""
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
firestart() {
|
firestart() {
|
||||||
# Really main firestarter function
|
# Really main firestarter function
|
||||||
local action="${_args[0]}"
|
local action="${_args[0]}"
|
||||||
@ -320,10 +328,12 @@ firestart() {
|
|||||||
step_logout
|
step_logout
|
||||||
;;
|
;;
|
||||||
start)
|
start)
|
||||||
error "NYI" 128
|
for file in "${_args[@]:1}"; do
|
||||||
|
fsexec "$_optconfigdir"/"$file"
|
||||||
|
done
|
||||||
;;
|
;;
|
||||||
status)
|
status)
|
||||||
error "NYI" 128
|
fsstatus
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
error "Unknown action: $action" 51
|
error "Unknown action: $action" 51
|
||||||
|
Loading…
x
Reference in New Issue
Block a user