Skip to content

Instantly share code, notes, and snippets.

@homebysix
Last active March 18, 2019 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save homebysix/501a3bc5144b77aecc0c to your computer and use it in GitHub Desktop.
Save homebysix/501a3bc5144b77aecc0c to your computer and use it in GitHub Desktop.
Casper extension attribute that collects the version of Git installed.
#!/bin/sh
###
#
# Name: git_version.sh
# Description: Casper extension attribute that displays the version of Git.
# Excludes /usr/bin/git in order to prevent Xcode install prompt.
# Author: Elliot Jordan <elliot@elliotjordan.com>
# Created: 2014-12-19
# Last Modified: 2014-12-22
# Version: 1.1.1
#
###
CURRENT_USER=$(/usr/bin/stat -f%Su /dev/console)
CURRENT_PATH=$(/usr/bin/su "$CURRENT_USER" -c "/usr/bin/env | /usr/bin/grep PATH= | /usr/bin/colrm 1 5 | sed 's/\/usr\/bin://g'")
RESULT=""
old=$IFS
IFS=:
for p in $CURRENT_PATH; do
GIT_VERSION="$($p/git --version 2> /dev/null)"
if [[ $? == 0 ]]; then
RESULT+="$p $GIT_VERSION\n"
fi
done
IFS=$old
/usr/bin/printf "<result>$RESULT</result>\n"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment