3 # sd-tool: Helper Tool for systemd
4 # Copyright (c)2023,2024 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.
16 # Detect our "share" folder ...
18 for d in "${BIN_D}" "${BIN_D}"/..; do
19 for s in share share/sd-tool; do
20 if [[ -r "${d}/${s}/sd-tool-common.inc.sh" ]]; then
25 [[ -n "${SHARE_D}" ]] && break
28 if [[ -z "${SHARE_D}" || ! -d "${SHARE_D}" ]]; then
29 echo "Oops, failed to detect \"share\" folder of $0! Aborting!" >&2
33 # shellcheck source=../share/sd-tool-common.inc.sh
34 if ! . "${SHARE_D}/sd-tool-common.inc.sh"; then
35 echo "Oops, failed to read \"${SHARE_D}/sd-tool-common.inc.sh\"! Aborting!" >&2
39 # Try to handle a subcommand.
40 # NOTE: this function does NOT return!
41 handle_subcommand_and_quit() {
43 cmd_file="${SHARE_D}/sdt-cmd-${cmd}.inc.sh"
45 if [[ -r "${cmd_file}" ]]; then
46 # shellcheck source=../share/sd-tool-common.inc.sh
47 if ! . "${cmd_file}"; then
48 printf "Oops, failed to read \"%s\"! Aborting!\n" "${cmd_file}" >&2
55 if [[ -n "${cmd}" ]]; then
56 printf "Unknown subcommand \"%s\"! Available commands are:\n\n" "${cmd}" >&2
58 printf "No subcommand given! Available commands are:\n\n" >&2
85 printf "Unknown option \"%s\"!\n" "$1" >&2
90 handle_subcommand_and_quit "$@"