3 # sd-tool: Helper Tool for systemd
4 # Copyright (c)2023 Alexander Barton (alex@barton.de)
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
12 # Detect our "share" folder ...
14 for d in . .. /usr/local /usr; do
15 for s in share share/sd-tool; do
16 if [[ -r "${d}/${s}/sd-tool-common.inc.sh" ]]; then
21 [[ -n "${SHARE_D}" ]] && break
24 if [[ -z "${SHARE_D}" || ! -d "${SHARE_D}" ]]; then
25 echo "Oops, failed to detect \"share\" folder of $0! Aborting!" >&2
29 # shellcheck source=../share/sd-tool-common.inc.sh
30 if ! . "${SHARE_D}/sd-tool-common.inc.sh"; then
31 echo "Oops, failed to read \"${SHARE_D}/sd-tool-common.inc.sh\"! Aborting!" >&2
35 # Try to handle a subcommand.
36 # NOTE: this function does NOT return!
37 handle_subcommand_and_quit() {
39 cmd_file="${SHARE_D}/sdt-cmd-${cmd}.inc.sh"
41 if [[ -r "${cmd_file}" ]]; then
42 # shellcheck source=../share/sd-tool-common.inc.sh
43 if ! . "${cmd_file}"; then
44 printf "Oops, failed to read \"%s\"! Aborting!\n" "${cmd_file}" >&2
51 if [[ -n "${cmd}" ]]; then
52 printf "Unknown subcommand \"%s\"! Available commands are:\n\n" "${cmd}" >&2
54 printf "No subcommand given! Available commands are:\n\n" >&2
81 printf "Unknown option \"%s\"!\n" "$1" >&2
86 handle_subcommand_and_quit "$@"