Skip to content

Commit

Permalink
Initial File upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohan460 committed May 14, 2018
1 parent 5fb3b17 commit 4a3e4d7
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 0 deletions.
17 changes: 17 additions & 0 deletions com.JAMF.InitialConfig.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.JAMF.InitialConfig</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>/Library/InitialConfiguration/enrollmentScript.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
92 changes: 92 additions & 0 deletions enrollmentScript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash
#
# Author: Johan McGwire - Yohan @ Macadmins Slack - Johan@McGwire.tech
#
# Description: This script is used to reapeatdly call a policy trigger until removed and unloaded.

# Establishing the logging variables
LOGFOLDER="/var/log"
LOGFILE="${LOGFOLDER}/Initial_Configuration_Policy_Call.log"

if [ ! -d "$LOGFOLDER" ];
then
/bin/mkdir "$LOGFOLDER"
fi

if [ ! -f "$LOGFILE" ];
then
/usr/bin/touch ${LOGFILE}
fi

# Establishing the logging functionality
function logme()
{
# Check to see if function has been called correctly
if [ -z "$1" ]; then
/bin/echo "$(date '+%F %T') - logme function call error: no text passed to function! Please recheck code!"
/bin/echo "$(date '+%F %T') - logme function call error: no text passed to function! Please recheck code!" >> ${LOGFILE}
exit 1
fi

# Log the passed details
/bin/echo "$(date '+%F %T') - $1"
/bin/echo "$(date '+%F %T') - $1" >> ${LOGFILE}
}

# Initializing log
logme "======== Starting Configiration Policy Script ========"

# Checking for the currently logged in user
while [ $(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }') == '_mbsetupuser' ]; do

# Logging the user lookup
logme "User Check failed, waiting 10 seconds"

# Waiting
sleep 10
done

logme "Logged in user: $(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')"
logme "Running as: $(whoami)"

# Checking for an internet connection
returnCode=1
while [[ "${returnCode}" -ne "0" ]]; do

# Loading google.com
echo -e "GET http://google.com HTTP/1.0\n\n" | nc google.com 80 > /dev/null 2>&1
returnCode=$?

# Waiting
if [[ "${returnCode}" -ne "0" ]]; then

# Logging the user lookup
logme "User Check failed, waiting 10 seconds"

# Waiting
sleep 10

fi
done

logme "Internet connection verified"

# Sleeping to ensure correct policy call
sleep 5

# Running the policy
logme "Calling the jamf policy with an InitialConfig trigger"
/usr/local/bin/jamf policy -trigger InitialConfig
returnCode=$?

if [[ "${returnCode}" == "0" ]]; then
logme "Policy call successful"
else
logme "FAILED policy call"
fi

# Initializing log
logme "======== Finished Configiration Policy Script ========"

# Exiting and returning the policy call code (never actually reaches this point due to stoping after the reload)
exit $returnCode

0 comments on commit 4a3e4d7

Please sign in to comment.