tero@627: ### Command execution tero@627: ## Execute command, possibly logging its execution. tero@627: # tero@627: # cmd $cmd... tero@627: # tero@627: # Fails if the command returns an error exit code. tero@627: function cmd { tero@627: log_cmd "$@" tero@627: tero@627: "$@" || die "Failed: $@" tero@627: } tero@627: tero@627: ## Execute command as a test, logging its execution at log_cmd tero@627: # tero@627: # cmd_test $cmd... && ... || ... tero@627: # tero@627: # Fails if the command returns an error exit code. tero@627: function cmd_test { tero@627: log_cmd "$@" tero@627: tero@627: "$@" tero@627: } tero@709: tero@627: ## Execute command, prefixing its output on stdout with given indent prefix. tero@627: # tero@627: # indent " " $cmd... tero@627: # tero@627: # Output is kept on stdout, exit status is that of the given command. tero@627: function cmd_indent () { tero@627: local indent="$1"; shift tero@627: tero@627: "$@" | sed "s/^/$indent/" tero@627: tero@627: return ${PIPESTATUS[0]} tero@627: } tero@709: tero@709: ## Execute a command as root, using sudo if required. tero@709: function cmd_sudo { tero@709: if [ $UID -eq 0 ]; then tero@709: cmd "$@" tero@709: else tero@709: cmd sudo "$@" tero@709: fi tero@709: }