mirror of
https://github.com/natelandau/shell-scripting-templates.git
synced 2025-11-08 13:13:47 -05:00
Move dependency check to global utils
This commit is contained in:
@@ -3,9 +3,9 @@
|
|||||||
# ##################################################
|
# ##################################################
|
||||||
# My Generic BASH script template
|
# My Generic BASH script template
|
||||||
#
|
#
|
||||||
version="1.0.0" # Sets version variable for this script
|
version="1.1.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
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# HISTORY:
|
# HISTORY:
|
||||||
@@ -76,50 +76,23 @@ tmpDir="/tmp/${scriptName}.$RANDOM.$RANDOM.$RANDOM.$$"
|
|||||||
# -----------------------------------
|
# -----------------------------------
|
||||||
logFile="$HOME/Library/Logs/${scriptBasename}.log"
|
logFile="$HOME/Library/Logs/${scriptBasename}.log"
|
||||||
|
|
||||||
function pauseScript() {
|
# Check for Dependencies
|
||||||
seek_confirmation "Ready to continue?"
|
# -----------------------------------
|
||||||
if is_confirmed; then
|
# Arrays containing package dependencies needed to execute this script.
|
||||||
info "Continuing"
|
# The script will fail if dependencies are not installed. For Mac users,
|
||||||
fi
|
# most dependencies can be installed automatically using the package
|
||||||
}
|
# manager 'Homebrew'.
|
||||||
|
# -----------------------------------
|
||||||
|
bashDependencies=(ffmpeg jq)
|
||||||
|
|
||||||
function mainScript() {
|
function mainScript() {
|
||||||
############## Begin Script Here ###################
|
############## Begin Script Here ###################
|
||||||
####################################################
|
####################################################
|
||||||
|
|
||||||
# Constants
|
# file extension mappings - ie - are we working with a video or music file....
|
||||||
dependencies=(ffmpeg jq)
|
|
||||||
videoTypes=(mp4 mov avi mkv wmv flv ogg m4p m4v 3gp divx h264)
|
videoTypes=(mp4 mov avi mkv wmv flv ogg m4p m4v 3gp divx h264)
|
||||||
audioTypes=(mp3 avi m4a aiff aac m4p wav wma flac)
|
audioTypes=(mp3 avi m4a aiff aac m4p wav wma flac)
|
||||||
|
|
||||||
# If a user specifies a single file type extension, respect it.
|
|
||||||
if [ -n "${MEDIATYPE}" ]; then
|
|
||||||
if [[ "${videoTypes[*]}" =~ "${MEDIATYPE}" ]]; then
|
|
||||||
videoTypes=($MEDIATYPE) # Reset the video type array to user-input, if specified
|
|
||||||
fi
|
|
||||||
if [[ "${audioTypes[*]}" =~ "${MEDIATYPE}" ]]; then
|
|
||||||
audioTypes=($MEDIATYPE) # Reset the audio type array to user-input, if specified
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
function checkDependencies() {
|
|
||||||
for i in "${dependencies[@]}"; do
|
|
||||||
if type_not_exists "${i}"; then
|
|
||||||
# Attempt to install necessary packages via Homebrew if invoked on a Mac
|
|
||||||
if [[ "${OSTYPE}" =~ ^darwin ]]; then
|
|
||||||
hasHomebrew # Installs Homebrew and all dependencies if needed.
|
|
||||||
if [[ "${i}" == "ffmpeg" ]]; then # install ffmpeg with all packages
|
|
||||||
brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-libcaca --with-libass --with-frei0r --with-libquvi --with-libvidstab --with-libvo-aacenc --with-libvorbis --with-libvpx --with-opencore-amr --with-openjpeg --with-openssl --with-opus --with-rtmpdump --with-schroedinger --with-speex --with-theora --with-tools --with-x265
|
|
||||||
else
|
|
||||||
brew install ${i} #install anything else needed
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
die "Can not proceed without '${i}'. Please install it before running this script."
|
|
||||||
fi # /OStype
|
|
||||||
fi # not type $i
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
function breakLoop() {
|
function breakLoop() {
|
||||||
# Break the for loop when a user specifies a file from the CLI.
|
# Break the for loop when a user specifies a file from the CLI.
|
||||||
# Basically, this ensures that we only run the loop once for a single file.
|
# Basically, this ensures that we only run the loop once for a single file.
|
||||||
@@ -147,6 +120,16 @@ function outputDir() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function identifyUserFile() {
|
function identifyUserFile() {
|
||||||
|
# If a user specifies a single file type extension, respect it.
|
||||||
|
if [ -n "${MEDIATYPE}" ]; then
|
||||||
|
if [[ "${videoTypes[*]}" =~ "${MEDIATYPE}" ]]; then
|
||||||
|
videoTypes=($MEDIATYPE) # Reset the video type array to user-input, if specified
|
||||||
|
fi
|
||||||
|
if [[ "${audioTypes[*]}" =~ "${MEDIATYPE}" ]]; then
|
||||||
|
audioTypes=($MEDIATYPE) # Reset the audio type array to user-input, if specified
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -n "${args}" ]]; then
|
if [[ -n "${args}" ]]; then
|
||||||
userFile="${args}"
|
userFile="${args}"
|
||||||
fi
|
fi
|
||||||
@@ -604,7 +587,6 @@ convertMusic() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Run the functions
|
# Run the functions
|
||||||
checkDependencies
|
|
||||||
identifyUserFile
|
identifyUserFile
|
||||||
userFormat
|
userFormat
|
||||||
outputDir
|
outputDir
|
||||||
@@ -797,6 +779,8 @@ fi
|
|||||||
# This way you can catch the error in case mysqldump fails in `mysqldump |gzip`, for example.
|
# This way you can catch the error in case mysqldump fails in `mysqldump |gzip`, for example.
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
|
checkDependencies # Invoke the checkDependenices function to test for Bash packages
|
||||||
|
|
||||||
mainScript # Run your script
|
mainScript # Run your script
|
||||||
|
|
||||||
safeExit # Exit cleanly
|
safeExit # Exit cleanly
|
||||||
|
|||||||
Reference in New Issue
Block a user