added cli options functions

This commit is contained in:
Nathaniel Landau
2015-01-04 00:50:21 -05:00
parent 8f558f6ccd
commit 5ff40a206c
6 changed files with 175 additions and 100 deletions

57
lib/parseOpts.sh Executable file
View File

@@ -0,0 +1,57 @@
#!/usr/bin/env bash
# Parse commandline options
#
# Works in along with the 'Command Line Options' and 'Set Switches' functions
# of many of my scripts
#
# All of this taken whole-cloth from: https://github.com/kvz/bash3boilerplate
#####################################################################
# Translate usage string -> getopts arguments, and set $arg_<flag> defaults
while read line; do
opt="$(echo "${line}" |awk '{print $1}' |sed -e 's#^-##')"
if ! echo "${line}" |egrep '\[.*\]' >/dev/null 2>&1; then
init="0" # it's a flag. init with 0
else
opt="${opt}:" # add : if opt has arg
init="" # it has an arg. init with ""
fi
opts="${opts}${opt}"
varname="arg_${opt:0:1}"
if ! echo "${line}" |egrep '\. Default=' >/dev/null 2>&1; then
eval "${varname}=\"${init}\""
else
match="$(echo "${line}" |sed 's#^.*Default=\(\)#\1#g')"
eval "${varname}=\"${match}\""
fi
done <<< "${usage}"
# Reset in case getopts has been used previously in the shell.
OPTIND=1
# Overwrite $arg_<flag> defaults with the actual CLI options
while getopts "${opts}" opt; do
line="$(echo "${usage}" |grep "\-${opt}")"
[ "${opt}" = "?" ] && help "Invalid use of script: ${@} "
varname="arg_${opt:0:1}"
default="${!varname}"
value="${OPTARG}"
if [ -z "${OPTARG}" ] && [ "${default}" = "0" ]; then
value="1"
fi
eval "${varname}=\"${value}\""
#debug "cli arg ${varname} = ($default) -> ${!varname}"
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift

View File

@@ -27,10 +27,10 @@ function scriptPath() {
# Outputs each line in a variable named $result # Outputs each line in a variable named $result
# ------------------------------------------------------ # ------------------------------------------------------
function readFile() { function readFile() {
unset $result unset ${result}
while read result while read result
do do
echo $result echo ${result}
done < "$1" done < "$1"
} }
@@ -93,8 +93,8 @@ function pushover() {
# Send to Pushover # Send to Pushover
PUSHOVERURL="https://api.pushover.net/1/messages.json" PUSHOVERURL="https://api.pushover.net/1/messages.json"
API_KEY="$PUSHOVER_API_KEY" API_KEY="${PUSHOVER_API_KEY}"
USER_KEY="$PUSHOVER_USER_KEY" USER_KEY="${PUSHOVER_USER_KEY}"
DEVICE="" DEVICE=""
TITLE="${1}" TITLE="${1}"
MESSAGE="${2}" MESSAGE="${2}"
@@ -299,3 +299,21 @@ function unmountDrive() {
diskutil unmount "$1" diskutil unmount "$1"
fi fi
} }
# help
# ------------------------------------------------------
# Prints help for a script when invoked from the command
# line. Typically via '-h'. If additional flags or help
# text is available in the script they will be printed
# in the '$usage' variable.
# ------------------------------------------------------
function help () {
echo "" 1>&2
e_bold " ${@}" 1>&2
if [ -n "${usage}" ]; then # print usage information if available
echo " ${usage}" 1>&2
fi
echo "" 1>&2
exit 1
}

View File

@@ -9,12 +9,12 @@
# First we locate this script and populate the $SCRIPTPATH variable # First we locate this script and populate the $SCRIPTPATH variable
# Doing so allows us to source additional files from this utils file. # Doing so allows us to source additional files from this utils file.
SOURCE="${BASH_SOURCE[0]}" SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink while [ -h "${SOURCE}" ]; do # resolve ${SOURCE} until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" DIR="$( cd -P "$( dirname "${SOURCE}" )" && pwd )"
SOURCE="$(readlink "$SOURCE")" SOURCE="$(readlink "${SOURCE}")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located [[ ${SOURCE} != /* ]] && SOURCE="${DIR}/${SOURCE}" # if ${SOURCE} was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done done
SOURCEPATH="$( cd -P "$( dirname "$SOURCE" )" && pwd )" SOURCEPATH="$( cd -P "$( dirname "${SOURCE}" )" && pwd )"
# Write the list of utility files to be sourced # Write the list of utility files to be sourced
FILES=" FILES="
@@ -26,10 +26,10 @@ FILES="
# Source the Utility Files # Source the Utility Files
for file in $FILES for file in $FILES
do do
if [ -f "$SOURCEPATH/$file" ]; then if [ -f "${SOURCE}PATH/${file}" ]; then
source "$SOURCEPATH/$file" source "${SOURCE}PATH/${file}"
else else
e_error "$file does not exist. Exiting" e_error "${file} does not exist. Exiting"
Exit 1 Exit 1
fi fi
done done

View File

@@ -46,7 +46,7 @@ RECIPES=(
moom moom
nvalt nvalt
omnifocus omnifocus
onepassword 1password
plex-home-theater plex-home-theater
qlcolorcode qlcolorcode
qlmarkdown qlmarkdown

View File

@@ -297,19 +297,19 @@ if is_confirmed; then
/usr/libexec/PlistBuddy -c "Set DesktopViewSettings:IconViewSettings:labelOnBottom false" ~/Library/Preferences/com.apple.finder.plist /usr/libexec/PlistBuddy -c "Set DesktopViewSettings:IconViewSettings:labelOnBottom false" ~/Library/Preferences/com.apple.finder.plist
e_success "Enable snap-to-grid for icons on the desktop and in other icon views" e_success "Enable snap-to-grid for icons on the desktop and in other icon views"
/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist /usr/libexec/PlistBuddy -c "Set DesktopViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
/usr/libexec/PlistBuddy -c "Set :FK_StandardViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist /usr/libexec/PlistBuddy -c "Set FK_StandardViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist /usr/libexec/PlistBuddy -c "Set StandardViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
e_success "Increase grid spacing for icons on the desktop and in other icon views" e_success "Increase grid spacing for icons on the desktop and in other icon views"
/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:gridSpacing 100" ~/Library/Preferences/com.apple.finder.plist /usr/libexec/PlistBuddy -c "Set DesktopViewSettings:IconViewSettings:gridSpacing 100" ~/Library/Preferences/com.apple.finder.plist
/usr/libexec/PlistBuddy -c "Set :FK_StandardViewSettings:IconViewSettings:gridSpacing 100" ~/Library/Preferences/com.apple.finder.plist /usr/libexec/PlistBuddy -c "Set FK_StandardViewSettings:IconViewSettings:gridSpacing 100" ~/Library/Preferences/com.apple.finder.plist
/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:gridSpacing 100" ~/Library/Preferences/com.apple.finder.plist /usr/libexec/PlistBuddy -c "Set StandardViewSettings:IconViewSettings:gridSpacing 100" ~/Library/Preferences/com.apple.finder.plist
e_success "Increase the size of icons on the desktop and in other icon views" e_success "Increase the size of icons on the desktop and in other icon views"
/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:iconSize 40" ~/Library/Preferences/com.apple.finder.plist /usr/libexec/PlistBuddy -c "Set DesktopViewSettings:IconViewSettings:iconSize 40" ~/Library/Preferences/com.apple.finder.plist
/usr/libexec/PlistBuddy -c "Set :FK_StandardViewSettings:IconViewSettings:iconSize 40" ~/Library/Preferences/com.apple.finder.plist /usr/libexec/PlistBuddy -c "Set FK_StandardViewSettings:IconViewSettings:iconSize 40" ~/Library/Preferences/com.apple.finder.plist
/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:iconSize 40" ~/Library/Preferences/com.apple.finder.plist /usr/libexec/PlistBuddy -c "Set StandardViewSettings:IconViewSettings:iconSize 40" ~/Library/Preferences/com.apple.finder.plist
e_success "Use column view in all Finder windows by default" e_success "Use column view in all Finder windows by default"
defaults write com.apple.finder FXPreferredViewStyle -string "clmv" defaults write com.apple.finder FXPreferredViewStyle -string "clmv"
@@ -464,7 +464,7 @@ if is_confirmed; then
e_success "Make Safaris search banners default to Contains instead of Starts With" e_success "Make Safaris search banners default to Contains instead of Starts With"
defaults write com.apple.Safari FindOnPageMatchesWordStartsOnly -bool false defaults write com.apple.Safari FindOnPageMatchesWordStartsOnly -bool false
Remove useless icons from Safaris bookmarks bar e_success "Remove useless icons from Safaris bookmarks bar"
defaults write com.apple.Safari ProxiesInBookmarksBar "()" defaults write com.apple.Safari ProxiesInBookmarksBar "()"
e_success "Enable the Develop menu and the Web Inspector in Safari" e_success "Enable the Develop menu and the Web Inspector in Safari"
@@ -689,7 +689,7 @@ fi
############################################################################### ###############################################################################
e_header "Running SSD Specific OSX Tweaks" e_header "Running SSD Specific OSX Tweaks"
seek_confirmation "Confirm that you have an SSD Hard Drive and want to " seek_confirmation "Confirm that you have an SSD Hard Drive and want to disable sudden motion sensor."
if is_confirmed; then if is_confirmed; then
# e_success "Remove the sleep image file to save disk space" # e_success "Remove the sleep image file to save disk space"

View File

@@ -43,13 +43,13 @@ fi
# This script calls for a configuration file. # This script calls for a configuration file.
# This is its location # This is its location
CONFIG="../etc/$SCRIPTNAME.cfg" CONFIG="../etc/${SCRIPTNAME}.cfg"
# HELP # HELP
# When -h is passed to the script, this will display inline help # When -h is passed to the script, this will display inline help
function HELP () { function HELP () {
e_bold "\nHelp for $SCRIPTNAME" e_bold "\nHelp for ${SCRIPTNAME}"
echo -e "This script will give you the option of using rsync" echo -e "This script will give you the option of using rsync"
echo -e "or Unison. Rsync is for one-way syncing, Unison is for" echo -e "or Unison. Rsync is for one-way syncing, Unison is for"
echo -e "two-way syncing.\n" echo -e "two-way syncing.\n"
@@ -96,29 +96,29 @@ done
# Create new copy of the script if template is being executed # Create new copy of the script if template is being executed
function newCopy() { function newCopy() {
scriptPath scriptPath
if [ "$SCRIPTNAME" = "SyncTemplate.sh" ]; then if [ "${SCRIPTNAME}" = "SyncTemplate.sh" ]; then
e_bold "name your new script:" e_bold "name your new script:"
read newname read newname
cp "$SCRIPTPATH"/"$SCRIPTNAME" "$SCRIPTPATH"/"$newname" cp "${SCRIPTPATH}"/"${SCRIPTNAME}" "${SCRIPTPATH}"/"${newname}"
e_success "$newname created." e_success "${newname} created."
exit 0 exit 0
fi fi
} }
function configFile() { function configFile() {
# Here we source the Config file or create a new one if none exists. # Here we source the Config file or create a new one if none exists.
if is_file "$CONFIG"; then if is_file "${CONFIG}"; then
source "$CONFIG" source "${CONFIG}"
else else
seek_confirmation "Config file does not exist. Would you like to create one?" seek_confirmation "Config file does not exist. Would you like to create one?"
if is_not_confirmed; then if is_not_confirmed; then
die "No config file. Exiting" die "No config file. Exiting"
else else
touch "$CONFIG" touch "${CONFIG}"
cat >"$CONFIG" <<EOL cat >"${CONFIG}" <<EOL
# ################################################## # ##################################################
# CONFIG FILE FOR $SCRIPTNAME # CONFIG FILE FOR ${SCRIPTNAME}
# CREATED ON $NOW # CREATED ON ${NOW}
# #
# Created by version "$VERSION" of "SyncTemplate.sh" # Created by version "$VERSION" of "SyncTemplate.sh"
# ################################################## # ##################################################
@@ -207,7 +207,7 @@ PUSHOVERNOTIFY="false"
CANONICALHOST="" CANONICALHOST=""
EOL EOL
e_success "Config file created. Edit the values before running this script again." e_success "Config file created. Edit the values before running this script again."
e_arrow "The file is located at: $CONFIG" e_arrow "The file is located at: ${CONFIG}"
echo "Exiting." echo "Exiting."
exit 0 exit 0
fi fi
@@ -219,9 +219,9 @@ fi
# Confirm we can run this script. If a canonical host is set in # Confirm we can run this script. If a canonical host is set in
# the config file we check it here. # the config file we check it here.
function hostCheck() { function hostCheck() {
if [ "$THISHOST" = "$CANONICALHOST" ]; then if [ "${THISHOST}" = "${CANONICALHOST}" ]; then
echo "$NOW - Script was not run since we were on the wrong host" >> "$LOGFILE" echo "${NOW} - Script was not run since we were on the wrong host" >> "${LOGFILE}"
die "We are currently on $THISHOST and can not proceed. Be sure to run this script on the non-canonical host." die "We are currently on ${THISHOST} and can not proceed. Be sure to run this script on the non-canonical host."
fi fi
} }
@@ -229,8 +229,8 @@ function hostCheck() {
# Confirm we have either Unison or Rsync specified # Confirm we have either Unison or Rsync specified
# in the config file. Exit if not # in the config file. Exit if not
function MethodCheck() { function MethodCheck() {
if [ "$METHOD" != "rsync" ] && [ "$METHOD" != "unison" ]; then if [ "${METHOD}" != "rsync" ] && [ "${METHOD}" != "unison" ]; then
echo "$NOW - Script aborted without a method specified in the config file." >> "$LOGFILE" echo "${NOW} - Script aborted without a method specified in the config file." >> "${LOGFILE}"
die "We can not continue. Please specify a sync method in the config file." die "We can not continue. Please specify a sync method in the config file."
fi fi
} }
@@ -239,27 +239,27 @@ function mainScript() {
# Time the script by logging the start time # Time the script by logging the start time
STARTTIME=$(date +"%s") STARTTIME=$(date +"%s")
# Log Script Start to $LOGFILE # Log Script Start to ${LOGFILE}
echo -e "-----------------------------------------------------" >> "$LOGFILE" echo -e "-----------------------------------------------------" >> "${LOGFILE}"
echo -e "$NOW - $SCRIPTNAME Begun" >> "$LOGFILE" echo -e "${NOW} - ${SCRIPTNAME} Begun" >> "${LOGFILE}"
echo -e "-----------------------------------------------------\n" >> "$LOGFILE" echo -e "-----------------------------------------------------\n" >> "${LOGFILE}"
if [ "$NEEDMOUNT" = "true" ] || [ "$NEEDMOUNT" = "TRUE" ]; then if [ "${NEEDMOUNT}" = "true" ] || [ "${NEEDMOUNT}" = "TRUE" ]; then
# Mount AFP volume # Mount AFP volume
if is_not_dir "$REMOTEVOLUME"; then if is_not_dir "${REMOTEVOLUME}"; then
e_arrow "Mounting drive" e_arrow "Mounting drive"
mkdir "$REMOTEVOLUME" mkdir "${REMOTEVOLUME}"
if [ "$MOUTPW" = "true" ]; then # if password prompt needed if [ "${MOUTPW}" = "true" ]; then # if password prompt needed
mount_afp -i "$MOUNTPOINT" "$REMOTEVOLUME" mount_afp -i "${MOUNTPOINT}" "${REMOTEVOLUME}"
else else
mount_afp "$MOUNTPOINT" "$REMOTEVOLUME" mount_afp "${MOUNTPOINT}" "${REMOTEVOLUME}"
fi fi
sleep 10 sleep 10
echo "$NOW - $REMOTEVOLUME Mounted" >> "$LOGFILE" echo "${NOW} - ${REMOTEVOLUME} Mounted" >> "${LOGFILE}"
e_success "$REMOTEVOLUME Mounted" e_success "${REMOTEVOLUME} Mounted"
else else
e_success "$REMOTEVOLUME already mounted" e_success "${REMOTEVOLUME} already mounted"
fi fi
fi fi
@@ -267,38 +267,38 @@ function mainScript() {
# If they don't exist we can't continue # If they don't exist we can't continue
# test for target # test for target
if is_dir "$TARGETDIRECTORY"; then if is_dir "${TARGETDIRECTORY}"; then
e_success "$TARGETDIRECTORY exists" e_success "${TARGETDIRECTORY} exists"
else else
if [ "$NEEDMOUNT" = "true" ] || [ "$NEEDMOUNT" = "TRUE" ]; then if [ "${NEEDMOUNT}" = "true" ] || [ "${NEEDMOUNT}" = "TRUE" ]; then
unmountDrive "$REMOTEVOLUME" unmountDrive "${REMOTEVOLUME}"
if is_dir "$REMOTEVOLUME"; then if is_dir "${REMOTEVOLUME}"; then
rm -r "$REMOTEVOLUME" rm -r "${REMOTEVOLUME}"
fi fi
fi fi
echo -e "$NOW - Script aborted since target dir: $TARGETDIRECTORY was not found. Exited.\n" >> "$LOGFILE" echo -e "${NOW} - Script aborted since target dir: ${TARGETDIRECTORY} was not found. Exited.\n" >> "${LOGFILE}"
die "target directory: $TARGETDIRECTORY does not exist. Exiting." die "target directory: ${TARGETDIRECTORY} does not exist. Exiting."
fi fi
# Test for source directory # Test for source directory
if is_dir "$SOURCEDIRECTORY"; then if is_dir "${SOURCEDIRECTORY}"; then
e_success "$SOURCEDIRECTORY exists" e_success "${SOURCEDIRECTORY} exists"
else else
if [ "$NEEDMOUNT" = "true" ] || [ "$NEEDMOUNT" = "TRUE" ]; then if [ "${NEEDMOUNT}" = "true" ] || [ "${NEEDMOUNT}" = "TRUE" ]; then
unmountDrive "$REMOTEVOLUME" unmountDrive "${REMOTEVOLUME}"
if is_dir "$REMOTEVOLUME"; then if is_dir "${REMOTEVOLUME}"; then
rm -r "$REMOTEVOLUME" rm -r "${REMOTEVOLUME}"
fi fi
fi fi
echo -e "$NOW - Script aborted since source dir: $SOURCEDIRECTORY was not found. Exited.\n" >> "$LOGFILE" echo -e "${NOW} - Script aborted since source dir: ${SOURCEDIRECTORY} was not found. Exited.\n" >> "${LOGFILE}"
die "source directory: $SOURCEDIRECTORY does not exist. Exiting." die "source directory: ${SOURCEDIRECTORY} does not exist. Exiting."
fi fi
# Time to sync # Time to sync
if [ "$METHOD" = "rsync" ]; then if [ "${METHOD}" = "rsync" ]; then
/usr/bin/rsync -vahh"$DRYRUN""$COMPRESS" --progress --force --delete --exclude-from="$EXCLUDE" "$SOURCEDIRECTORY" "$TARGETDIRECTORY" --log-file="$LOGFILE" /usr/bin/rsync -vahh"$DRYRUN""$COMPRESS" --progress --force --delete --exclude-from="$EXCLUDE" "${SOURCEDIRECTORY}" "${TARGETDIRECTORY}" --log-file="${LOGFILE}"
fi fi
if [ "$METHOD" = "unison" ]; then if [ "${METHOD}" = "unison" ]; then
# Check if Unison is installed. It is not a standard package # Check if Unison is installed. It is not a standard package
if type_not_exists 'unison'; then if type_not_exists 'unison'; then
@@ -308,10 +308,10 @@ function mainScript() {
brewMaintenance brewMaintenance
brew install unison brew install unison
else else
if [ "$NEEDMOUNT" = "true" ] || [ "$NEEDMOUNT" = "TRUE" ]; then if [ "${NEEDMOUNT}" = "true" ] || [ "${NEEDMOUNT}" = "TRUE" ]; then
unmountDrive "$REMOTEVOLUME" unmountDrive "${REMOTEVOLUME}"
if is_dir "$REMOTEVOLUME"; then if is_dir "${REMOTEVOLUME}"; then
rm -r "$REMOTEVOLUME" rm -r "${REMOTEVOLUME}"
fi fi
fi fi
die "Can not continue without Unison." die "Can not continue without Unison."
@@ -319,54 +319,54 @@ function mainScript() {
fi fi
# Run Unison # Run Unison
if [ "$PROFILEROOTS" = "true" ]; then if [ "${PROFILEROOTS}" = "true" ]; then
# Throw error if we don't have enough information # Throw error if we don't have enough information
if [ "$USEPROFILE" = "false" ] || [ "$UNISONPROFILE" = "" ]; then if [ "${USEPROFILE}" = "false" ] || [ "${UNISONPROFILE}" = "" ]; then
echo "$NOW - We were missing the Unison Profile. Could not sync." >> "$LOGFILE" echo "${NOW} - We were missing the Unison Profile. Could not sync." >> "${LOGFILE}"
die "We were missing the Unison Profile. Could not sync." die "We were missing the Unison Profile. Could not sync."
fi fi
# Run unison with the profile # Run unison with the profile
echo "$NOW - Beginning Unison with command: unison $UNISONPROFILE" >> "$LOGFILE" echo "${NOW} - Beginning Unison with command: unison ${UNISONPROFILE}" >> "${LOGFILE}"
unison "$UNISONPROFILE" unison "${UNISONPROFILE}"
else else
if [ "$USEPROFILE" = "true" ]; then if [ "${USEPROFILE}" = "true" ]; then
# Throw error if we can't find the profile # Throw error if we can't find the profile
if [ "$UNISONPROFILE" = "" ]; then if [ "${UNISONPROFILE}" = "" ]; then
echo "$NOW - We were missing the Unison Profile. Could not sync." >> "$LOGFILE" echo "${NOW} - We were missing the Unison Profile. Could not sync." >> "${LOGFILE}"
die "We were missing the Unison Profile. Could not sync." die "We were missing the Unison Profile. Could not sync."
fi fi
# Run unison with a profile # Run unison with a profile
echo "$NOW - Beginning Unison with command: unison $UNISONPROFILE $SOURCEDIRECTORY $TARGETDIRECTORY" >> "$LOGFILE" echo "${NOW} - Beginning Unison with command: unison ${UNISONPROFILE} ${SOURCEDIRECTORY} ${TARGETDIRECTORY}" >> "${LOGFILE}"
unison "$UNISONPROFILE" "$SOURCEDIRECTORY" "$TARGETDIRECTORY" unison "${UNISONPROFILE}" "${SOURCEDIRECTORY}" "${TARGETDIRECTORY}"
else else
# Run Unison without a profile # Run Unison without a profile
echo "$NOW - Beginning Unison with command: unison $SOURCEDIRECTORY $TARGETDIRECTORY" >> "$LOGFILE" echo "${NOW} - Beginning Unison with command: unison ${SOURCEDIRECTORY} ${TARGETDIRECTORY}" >> "${LOGFILE}"
unison "$SOURCEDIRECTORY" "$TARGETDIRECTORY" unison "${SOURCEDIRECTORY}" "${TARGETDIRECTORY}"
fi fi
fi fi
fi fi
# Unmount the drive (if mounted) # Unmount the drive (if mounted)
if [ "$NEEDMOUNT" = "true" ] || [ "$NEEDMOUNT" = "TRUE" ]; then if [ "${NEEDMOUNT}" = "true" ] || [ "${NEEDMOUNT}" = "TRUE" ]; then
unmountDrive "$REMOTEVOLUME" unmountDrive "${REMOTEVOLUME}"
echo "$NOW - $REMOTEVOLUME Unmounted" >> "$LOGFILE" echo "${NOW} - ${REMOTEVOLUME} Unmounted" >> "${LOGFILE}"
e_success "$REMOTEVOLUME UnMounted" e_success "${REMOTEVOLUME} UnMounted"
fi fi
# Time the script by logging the end time # Time the script by logging the end time
ENDTIME=$(date +"%s") ENDTIME=$(date +"%s")
TOTALTIME=$(($ENDTIME-$STARTTIME-20)) TOTALTIME=$((${ENDTIME}-${STARTTIME}-20))
# notify with pushover if requested # notify with pushover if requested
if [ "$PUSHOVERNOTIFY" = "true" ]; then if [ "${PUSHOVERNOTIFY}" = "true" ]; then
pushover "$SCRIPTNAME Completed" "$SCRIPTNAME was run in $(convertsecs $TOTALTIME)" pushover "${SCRIPTNAME} Completed" "${SCRIPTNAME} was run in $(convertsecs $TOTALTIME)"
fi fi
echo -e "\n-----------------------------------------------------" >> "$LOGFILE" echo -e "\n-----------------------------------------------------" >> "${LOGFILE}"
echo "$NOW - $SCRIPTNAME completed in $(convertsecs $TOTALTIME)" >> "$LOGFILE" echo "${NOW} - ${SCRIPTNAME} completed in $(convertsecs $TOTALTIME)" >> "${LOGFILE}"
echo -e "-----------------------------------------------------\n" >> "$LOGFILE" echo -e "-----------------------------------------------------\n" >> "${LOGFILE}"
e_success "$NOW - $SCRIPTNAME completed in $(convertsecs $TOTALTIME)" e_success "${NOW} - ${SCRIPTNAME} completed in $(convertsecs $TOTALTIME)"
} }
newCopy newCopy