# /etc/functions-system # # a collection of functions and variables for scripts source /etc/functions-colors # removable backup disk is a SATA drive, listed in the smartctl database DRIVEMODEL="WD7500AAKS" SMARTPARAMS="-a -d ata -o on -S on -n standby" Is_Backup_Drive_Available () { BACKUPDISK="" BACKUP_AVAIL="`lsscsi | grep $DRIVEMODEL | awk '{print$7}'`" if [ -n "$BACKUP_AVAIL" ]; then BACKUPDISK=$BACKUP_AVAIL fi } Script_Home () # this function determines a script's home directory from which it was launched { me=$0 # check if we are in the script directory if [ "x${me:0:2}" = "x./" ]; then me="$(pwd)${me:1}" fi # echo "Script name: $me" # echo "Script's home directory: $(dirname $me)" } Wait_For_Response () { if [ "$1" = "" ] ; then printf "${BOLDRED}Warning:${COLOR_RESET}\nNo question text was passed to the ${BOLDWHITE}/etc/system-functions/Wait_For_Response${COLOR_RESET} function. Exiting.\n" exit 1 fi allowedchars="YyNn" response= while ! [[ "${response:0:1}" =~ "[$allowedchars]" ]] ; do read -er -p "$1 (y/n): " response done } Proceed_From_Response () { if [ "$response" = "n" -o "$response" = "N" ] ; then echo echo -e "${BOLDYELLOW}Exiting.${COLOR_RESET}" echo exit 0 else echo echo "Continuing." echo fi } Interactive_Shell () { # -z $PS1 test works only with bash shells (#!/bin/bash vs. #!/bin/sh) # the following is more portable case $- in *i*) : # running in non-interactive mode INTERACTIVE="false" ;; *) : # manually running this script in interactive mode INTERACTIVE="true" ;; esac } Test_Directory () { if [ -z $1 ] ; then echo "No parameter was passed to the Test_Directory function. Exiting." exit 1 fi ls $1 &>/dev/null if [ "$?" != "0" ] ; then echo echo -e "The ${BOLDGREEN}$1${COLOR_RESET} directory does not exist. Exiting." echo exit 1 else echo "Okay." echo fi }