diff --git a/firestarter b/firestarter index ba85039..0e47c9c 100755 --- a/firestarter +++ b/firestarter @@ -75,6 +75,10 @@ gettarget() { [ -r "$1" ] || return 1 # Every odd line is a condition # Every even one is a target + if [ -d "$1" ]; then + warn "Target is a directory: $1" 2 + return 50 + fi local firstline while read -r checkline; do if [ -z "$firstline" ]; then @@ -96,6 +100,35 @@ gettarget() { done < "$1" 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() { # Special things that can't use simple configuration files [ -n "$_optdryrun" ] && return 0 @@ -187,7 +220,7 @@ step_execute() { fi # Skip our logs directory [ "$_optlogdir" == "$file" ] && continue - fs_exec "$file" + fsexec "$file" done } step_postexecute() { @@ -282,31 +315,6 @@ Copyright (c) 2019 rehashedsalt@cock.li Licensed under the MIT license 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() { # Really main firestarter function local action="${_args[0]}" @@ -320,10 +328,12 @@ firestart() { step_logout ;; start) - error "NYI" 128 + for file in "${_args[@]:1}"; do + fsexec "$_optconfigdir"/"$file" + done ;; status) - error "NYI" 128 + fsstatus ;; *) error "Unknown action: $action" 51