mirror of
https://github.com/natelandau/shell-scripting-templates.git
synced 2025-11-08 21:23:48 -05:00
Added checkDependencies function
This commit is contained in:
@@ -3,27 +3,14 @@
|
||||
# ##################################################
|
||||
# My Generic BASH script template
|
||||
#
|
||||
version="1.1.1" # Sets version variable for this script
|
||||
version="1.0.0" # Sets version variable for this script
|
||||
#
|
||||
scriptTemplateVersion="1.1.1" # Version of scriptTemplate.sh that this script is based on
|
||||
scriptTemplateVersion="1.2.0" # Version of scriptTemplate.sh that this script is based on
|
||||
# v.1.1.0 - Added 'debug' option
|
||||
# v.1.1.1 - Moved all shared variables to Utils
|
||||
# - Added $PASS variable when -p is passed
|
||||
#
|
||||
# A Bash script boilerplate. Allows for common functions, logging, tmp
|
||||
# file creation, CL option passing, and more.
|
||||
#
|
||||
# For logging levels use the following functions:
|
||||
# - header: Prints a script header
|
||||
# - input: Ask for user input
|
||||
# - success: Print script success
|
||||
# - info: Print information to the user
|
||||
# - notice: Notify the user of something
|
||||
# - warning: Warn the user of something
|
||||
# - error: Print a non-fatal error
|
||||
# - die: A fatal error. Will exit the script
|
||||
# - debug: Debug information
|
||||
# - verbose: Debug info only printed when 'verbose' flag is set to 'true'.
|
||||
# v.1.2.0 - Added 'checkDependencies' function to ensure needed
|
||||
# Bash packages are installed prior to execution
|
||||
#
|
||||
# HISTORY:
|
||||
#
|
||||
@@ -88,6 +75,14 @@ tmpDir="/tmp/${scriptName}.$RANDOM.$RANDOM.$RANDOM.$$"
|
||||
# -----------------------------------
|
||||
logFile="$HOME/Library/Logs/${scriptBasename}.log"
|
||||
|
||||
# Check for Dependencies
|
||||
# -----------------------------------
|
||||
# Arrays containing package dependencies needed to execute this script.
|
||||
# The script will fail if dependencies are not installed. For Mac users,
|
||||
# most dependencies can be installed automatically using the package
|
||||
# manager 'Homebrew'.
|
||||
# -----------------------------------
|
||||
bashDependencies=()
|
||||
|
||||
function mainScript() {
|
||||
############## Begin Script Here ###################
|
||||
@@ -166,8 +161,8 @@ unset options
|
||||
while [[ $1 = -?* ]]; do
|
||||
case $1 in
|
||||
-h|--help) usage >&2; safeExit ;;
|
||||
--version) echo "$(basename $0) $version"; safeExit ;;
|
||||
-u|--username) shift; username=$1 ;;
|
||||
--version) echo "$(basename $0) ${version}"; safeExit ;;
|
||||
-u|--username) shift; username=${1} ;;
|
||||
-p|--password) shift; echo "Enter Pass: "; stty -echo; read PASS; stty echo;
|
||||
echo ;;
|
||||
-v|--verbose) verbose=1 ;;
|
||||
@@ -216,6 +211,8 @@ fi
|
||||
# This way you can catch the error in case mysqldump fails in `mysqldump |gzip`, for example.
|
||||
set -o pipefail
|
||||
|
||||
checkDependencies # Invoke the checkDependenices function to test for Bash packages
|
||||
|
||||
mainScript # Run your script
|
||||
|
||||
safeExit # Exit cleanly
|
||||
Reference in New Issue
Block a user