ssm/ssm-gen
fbt d5c0a30b96 some new stuff
Signed-off-by: fbt <fbt@fleshless.org>
2017-03-12 04:30:36 +03:00

51 lines
924 B
Bash
Executable File

#!/usr/bin/env bash
err() { printf '%s\n' "$*" >&2; }
workdir="/run/user/$UID/ssm/services"
[[ -d "$workdir" ]] || {
mkdir -p "$workdir" || exit 7
}
while (( $# )); do
case "$1" in
-o|--oneshot) flag_oneshot=1;;
-e|--edit) flag_edit=1;;
-s|--start) flag_start=1;;
-n|--name) service_name=$2; shift;;
-w|--workdir) workdir=$2; shift;;
--) shift; break;;
*) break;;
esac
shift
done
[[ "$1" ]] || {
err "Need at least one argument!"
exit 5
}
cmd=$1; shift
[[ "$service_name" ]] || service_name=$cmd
[[ "$cmd" == '/'* ]] || cmd=$(which "$cmd")
args=$@
{
printf '#!/usr/bin/env ssm\n\n'
(( flag_oneshot )) && printf 'service_oneshot=1\n'
printf 'service_command="%s"\n' "$cmd"
[[ "$args" ]] && printf 'service_args=( %s )\n' "${service_args[*]}"
} > "$workdir/$service_name"
(( edit )) && "$EDITOR" "$workdir/$service_name" || exit 3
(( flag_start )) && ssm "$workdir/$service_name" start