generated from the-common/project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: 林博仁(Buo-ren, Lin) <[email protected]>
- Loading branch information
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/usr/bin/env bash | ||
# _script_description_ | ||
# | ||
# Copyright _copyright_effective_year_ _copyright_holder_name_ <_copyright_holder_contact_> | ||
# SPDX-License-Identifier: CC-BY-SA-4.0 | ||
|
||
init(){ | ||
printf \ | ||
'Info: Operation completed without errors.\n' | ||
} | ||
|
||
printf \ | ||
'Info: Configuring the defensive interpreter behaviors...\n' | ||
set_opts=( | ||
# Terminate script execution when an unhandled error occurs | ||
-o errexit | ||
-o errtrace | ||
|
||
# Terminate script execution when an unset parameter variable is | ||
# referenced | ||
-o nounset | ||
) | ||
if ! set "${set_opts[@]}"; then | ||
printf \ | ||
'Error: Unable to configure the defensive interpreter behaviors.\n' \ | ||
1>&2 | ||
exit 1 | ||
fi | ||
|
||
printf \ | ||
'Info: Checking the existence of the required commands...\n' | ||
required_commands=( | ||
realpath | ||
) | ||
flag_required_command_check_failed=false | ||
for command in "${required_commands[@]}"; do | ||
if ! command -v "${command}" >/dev/null; then | ||
flag_required_command_check_failed=true | ||
printf \ | ||
'Error: This program requires the "%s" command to be available in your command search PATHs.\n' \ | ||
"${command}" \ | ||
1>&2 | ||
fi | ||
done | ||
if test "${flag_required_command_check_failed}" == true; then | ||
printf \ | ||
'Error: Required command check failed, please check your installation.\n' \ | ||
1>&2 | ||
exit 1 | ||
fi | ||
|
||
if test -v BASH_SOURCE; then | ||
printf \ | ||
'Info: Configuring the convenience variables...\n' | ||
# Convenience variables | ||
# shellcheck disable=SC2034 | ||
{ | ||
printf \ | ||
'Info: Determining the absolute path of the program...\n' | ||
if ! script="$( | ||
realpath \ | ||
--strip \ | ||
"${BASH_SOURCE[0]}" | ||
)"; then | ||
printf \ | ||
'Error: Unable to determine the absolute path of the program.\n' \ | ||
1>&2 | ||
exit 1 | ||
fi | ||
script_dir="${script%/*}" | ||
script_filename="${script##*/}" | ||
script_name="${script_filename%%.*}" | ||
} | ||
fi | ||
|
||
trap_err(){ | ||
printf \ | ||
'Error: The program has encountered an unhandled error and is prematurely aborted.\n' \ | ||
1>&2 | ||
} | ||
|
||
printf \ | ||
'Info: Setting the ERR trap...\n' | ||
if ! trap trap_err ERR; then | ||
printf \ | ||
'Error: Unable to set the ERR trap.\n' \ | ||
1>&2 | ||
exit 1 | ||
fi | ||
|
||
init |