A library of common reusable bash functions, with 0 non-native dependencies, to assist in the management of macOS computers.
While all the functionality can be replicated within macOS itself, there are two advantages to using the library:
- Less code to touch if the method to do something in macOS changes.
- Less remembering (or searching for) obscure macOS utilities, flags, and filters.
- Source one of the stub files below, depending on how your script to be run.
- Source each of the function files that contain the functions you want to use.
- Internal dependencies are taken care of automatically.
- See individual function files for arguments & additional notes.
- If using
jamf.sh
orroot.sh
, initialize the user with one of theuser::init
functions.
File | For | Effects |
---|---|---|
core.sh |
Scripts run as shell user | User functions automatically run on $USER |
root.sh |
Scripts run as root, affecting a different user | Must call user::init <username> or user::init::console to set user. |
jamf.sh |
Scripts run via Jamf Pro | * User functions automaticaly run on username supplied by Jamf as $3. * $jamfUser automatically set to $3 * $jamfHost automatically set to $2<br>* $jamfRootautomatically set to $1`* All arguments shifted, $4 becomes $1 |
All functions based on user information in this library run on a specific reference user, based on the chosen sub file (see above) and the user::init
function used.
If your script is running as root, you can silently install the library using the 1-liner below:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/jonesiscoding/mac-libs/HEAD/bin/install.sh)" || exit 1
The installer will check this repo for the most recent release, then if needed, download & extract to /usr/local/sbin/lib/mac-libs/
.