24 lines
1.1 KiB
Bash
Executable File
24 lines
1.1 KiB
Bash
Executable File
#!/bin/sh -e
|
|
[ -z "$1" ] && echo "Usage: $0 [service verb]" >&2 && exit 1
|
|
verb=$(printf %s "$1" | tr '[[:upper:]]' '[[:lower:]]')
|
|
capitalized="$(printf %s "$verb" | head -c1 | tr '[[:lower:]]' '[[:upper:]]')$(printf %s "$verb" | tail -c+2)"
|
|
echo '#!/sbin/openrc-run
|
|
name="'"$verb"'"
|
|
description="'"$capitalized"' another OpenRC service, for compatibility with systemctl'"'"'s syntax."
|
|
extra_commands="$(find $(dirname "$RC_SERVICE") -mindepth 1 -maxdepth 1 -type f -executable -not -name "$RC_SVCNAME" -not -name local -not -name function -not -name break -not -name continue -not -name eval -not -name exec -not -name exit -not -name export -not -name readonly -not -name return -not -name set -not -name shift -not -name times -not -name trap -not -name unset -not -name describe -not -name status -not -name zap | cut -d/ -f4- | grep '"'"'^[a-zA-Z_][a-zA-Z0-9_]*$'"'"')"
|
|
for command in $extra_commands; do
|
|
eval "description_$command=\"'"$capitalized"' the $command service.\"
|
|
$command () {
|
|
service $command '"$verb"'
|
|
}"
|
|
done
|
|
|
|
_block () {
|
|
eval "$1 () {
|
|
eend 1 \"Cannot \$RC_CMD \$RC_SVCNAME!\"
|
|
}"
|
|
}
|
|
_block start
|
|
_block stop
|
|
_block restart'
|