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.
14 # Detect our "share" folder ...
16 for d in "${BIN_D}" "${BIN_D}"/..; do
17 for s in share share/sd-tool; do
18 if [[ -r "${d}/${s}/sd-tool-common.inc.sh" ]]; then
23 [[ -n "${SHARE_D}" ]] && break
26 if [[ -z "${SHARE_D}" || ! -d "${SHARE_D}" ]]; then
27 echo "Oops, failed to detect \"share\" folder of $0! Aborting!" >&2
31 # shellcheck source=../share/sd-tool-common.inc.sh
32 if ! . "${SHARE_D}/sd-tool-common.inc.sh"; then
33 echo "Oops, failed to read \"${SHARE_D}/sd-tool-common.inc.sh\"! Aborting!" >&2
37 # Try to handle a subcommand.
38 # NOTE: this function does NOT return!
39 handle_subcommand_and_quit() {
41 cmd_file="${SHARE_D}/sdt-cmd-${cmd}.inc.sh"
43 if [[ -r "${cmd_file}" ]]; then
44 # shellcheck source=../share/sd-tool-common.inc.sh
45 if ! . "${cmd_file}"; then
46 printf "Oops, failed to read \"%s\"! Aborting!\n" "${cmd_file}" >&2
53 if [[ -n "${cmd}" ]]; then
54 printf "Unknown subcommand \"%s\"! Available commands are:\n\n" "${cmd}" >&2
56 printf "No subcommand given! Available commands are:\n\n" >&2
83 printf "Unknown option \"%s\"!\n" "$1" >&2
88 handle_subcommand_and_quit "$@"