Interactive Functions
File pipelines
Usage
interactiveManager loopCallable [ --exec binary ] [ --delay delaySeconds ] [ fileToCheck ... ]
Run checks interactively until errors are all fixed. Not ready for prime time yet - written not tested.
Arguments
loopCallable- Callable. Required. Call this on each file and a zero result code means passed and non-zero means fails.--exec binary- Callable. Optional. Run binary with files as an argument for any failed files. Only works if you pass in item names.--delay delaySeconds- Integer. Optional. Delay in seconds between checks in interactive mode.fileToCheck ...- File. Optional. Shell file to validate. May also supply file names via stdin.
Return codes
0- Success1- Environment error2- Argument error
Interactive utilities
Usage
loopExecute loopCallable [ --delay delaySeconds ] [ --until exitCode ] [ --title title ] [ arguments ... ]
Run checks interactively until errors are all fixed.
Arguments
loopCallable- Callable. Required. Call this on each file and a zero result code means passed and non-zero means fails.--delay delaySeconds- Integer. Optional. Delay in seconds between checks in interactive mode.--until exitCode- Integer. Optional. Check until exit code matches this.--title title- String. Optional. Display this title instead of the command.arguments ...- Optional. Arguments. Arguments toloopCallable
Return codes
0- Success1- Environment error2- Argument error
Usage
interactiveCountdown [ --help ] [ --badge text ] [ --prefix prefix ] counter binary [ ... ]
Display a message and count down display
Arguments
--help- Flag. Optional. Display this help.--badge text- String. Display this text as bigTextAt--prefix prefix- String.counter- Integer. Required. Count down from.binary- Callable. Required. Run this with any additional arguments when the countdown is completed....- Arguments. Optional. Passed to binary.
Return codes
0- Success1- Environment error2- Argument error
Usage
confirmYesNo [ --default defaultValue ] [ --attempts attempts ] [ --timeout seconds ] [ --info ] [ --yes ] [ --no ] [ --help ] [ --handler handler ] [ message ... ]
Read user input and return 0 if the user says yes, or non-zero if they say no Example: Will time out after 10 seconds, regardless (user must make valid input in that time): Example: Example:
Arguments
--default defaultValue- Boolean. Optional. Value to return if no value given by user--attempts attempts- PositiveInteger. Optional. User can give us a bad response this many times before we return the default.--timeout seconds- PositiveInteger. Optional. Wait this long before choosing the default. If no default, default is --no.--info- Flag. Optional. AddType Y or Nas instructions to the user.--yes- Flag. Optional. Short for--default yes--no- Flag. Optional. Short for--default no--help- Flag. Optional. Display this help.--handler handler- Function. Optional. Use this error handler instead of the default error handler.message ...- String. Any additional arguments are considered part of the message.
Examples
confirmYesNo --timeout 10 "Stop the timer!"
Return codes
0- Yes1- No
Usage
confirmMenu --choice choiceCharacter [ --default default ] --result resultFile [ --attempts attemptCount ] [ --timeout timeoutSeconds ] [ --prompt promptString ] [ message ]
Ask the user for a menu of options
Arguments
--choice choiceCharacter- String. Required. Character to accept.--default default- String. Optional. Character to choose when there is a timeout or other failure.--result resultFile- File. Required. File to write the result to.--attempts attemptCount- PositiveInteger. Optional. Number of attempts to try and get valid unput from the user.--timeout timeoutSeconds- PositiveInteger. Optional. Number of seconds to wait for user input before stopping.--prompt promptString- String. Optional. String to suffix the prompt with (usually tells the user what to do)message- String. Optional. Display this message as the confirmation menu.
Return codes
interrupt- Attempts exceededtimeout- Timeout
Usage
pause [ --help ] [ -- ] [ message ... ]
Pause for user input
Arguments
--help- Flag. Optional. Display this help.--- Flag. Optional. Stops command processing to enable arbitrary text to be passed as additional arguments without special meaning.message ...- Display this message while pausing
Return codes
0- Success1- Environment error2- Argument error
Usage
notify [ --help ] [ --handler handler ] [ --verbose ] [ --title title ] [ --message message ] [ --fail failMessage ] [ --sound soundName ] [ --fail-title title ] [ --fail-sound soundName ]
Notify after running a binary. Uses the notify hook with some handy parameters which are inherited
between "success" and "failure":
If a value is not specified for failure, it will use the success value.
Arguments
--help- Flag. Optional. Display this help.--handler handler- Function. Optional. Use this error handler instead of the default error handler.--verbose- Flag. Optional. Be verbose.--title title- String. Optional. Sets the title for the notification.--message message- String. Optional. Display this message (alias is-m)--fail failMessage- String. Optional. Display this message in console and dialog upon failure.--sound soundName- String. Optional. Sets the sound played for the notification.--fail-title title- String. Optional. Sets the title for the notification if the binary fails.--fail-sound soundName- String. Optional. Sets the sound played for the notification if the binary fails.
Return codes
0- Success1- Environment error2- Argument error
Usage
interactiveOccasionally [ --delta deltaMilliseconds ] [ --mark ] [ --verbose ] name
Do something the first time and then only occasionally thereafter.
This manages a state file compared to the current time and triggers after delta seconds.
Think of it like something that only returns 0 like once every delta seconds but it's going to happen at minimum delta seconds, or the next time after that. And the first time as well.
Arguments
--delta deltaMilliseconds- PositiveInteger. Optional. Default is 60000.--mark- Flag. Optional. Write the marker which says the--verbose- Flag. Optional. Be chatty.name- EnvironmentVariable. Required. The global codename for this interaction.
Return codes
0- Do the thing1- Do not do the thing2- Argument error
Copy files
Usage
fileCopyWouldChange [ --map ] source destination
Check whether copying a file would change it This function does not modify the source or destination.
Arguments
--map- Flag. Optional. Map environment values into file before copying.source- File. Required. Source pathdestination- File. Required. Destination path
Return codes
0- Something would change1- Nothing would change
Usage
fileCopy [ --map ] [ --escalate ] source destination
Copy file from source to destination Supports mapping the file using the current environment, or escalated privileges.
Arguments
--map- Flag. Optional. Map environment values into file before copying.--escalate- Flag. Optional. The file is a privilege escalation and needs visual confirmation. Requires root privileges.source- File. Required. Source pathdestination- File. Required. Destination path
Return codes
0- Success1- Failed
Examples
Example:
args=(--map configure/sshd_config /etc/ssh/sshd_config)
if fileCopyWouldChange "${args[@]}"; then
catchEnvironment "$handler" fileCopy "${args[@]}" || return $?
catchEnvironment "$handler" service ssh restart || return $?
fi