diff options
Diffstat (limited to 'src/infrastructure/scripts/r.sh')
-rwxr-xr-x | src/infrastructure/scripts/r.sh | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/infrastructure/scripts/r.sh b/src/infrastructure/scripts/r.sh new file mode 100755 index 0000000..8e74576 --- /dev/null +++ b/src/infrastructure/scripts/r.sh @@ -0,0 +1,77 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + r COMMAND... + r -h + EOF +} + +help() { + cat <<-'EOF' + + + Options: + -h, --help show this message + + COMMAND the command to be executed + + + Execute the given command, with a proper login environment + loaded. + + + Examples: + + Run a backup via SSH: + + $ ssh euandre.org r backup -q cron + EOF +} + + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +while getopts 'h' flag; do + case "$flag" in + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + +if [ -z "${1:-}" ]; then + printf 'Missing COMMAND.\n\n' >&2 + usage >&2 + exit 2 +fi + + +set +eu +# shellcheck source=/dev/null +. /etc/rc +set -eu + +exec "$@" |