Skip to content

Instantly share code, notes, and snippets.

@patgmac
Forked from MagerValp/kickstartam.sh
Created February 23, 2016 21:20
Show Gist options
  • Save patgmac/ee05eb707e979c84c9e9 to your computer and use it in GitHub Desktop.
Save patgmac/ee05eb707e979c84c9e9 to your computer and use it in GitHub Desktop.
Force Absolute Manage agent to install packages without delay.
#!/bin/bash
#
# Force Absolute Manage to install software at the login window.
declare -r AMSERVER="your.amserver.example"
declare -r AMDIR="/Library/Application Support/LANrev Agent"
declare -r AMAGENT="$AMDIR/LANrev Agent.app/Contents/MacOS/LANrev Agent"
declare -r LOGFILE="/var/log/kickstartam.log"
# Redirect stdout and stderr to a log file with date stamps.
exec > >(perl -MPOSIX -pe \
'$| = 1; print POSIX::strftime("%F %T", localtime), " amloginwindow: ";' \
>> "$LOGFILE") 2>&1
# Wait until a path exists.
function wait_for_path() {
local path="$1"
while [[ ! -e "$path" ]]; do
sleep 10
done
}
# Wait for ping reply from server.
function wait_for_ping() {
local server="$1"
echo "Waiting for $server to respond"
while ! ping -q -c 1 "$server" &>/dev/null; do
sleep 1
done
}
# Wait until the AM agent's status is idle.
function wait_amagent_idle() {
local status
local sdstate=""
local newstate
while true; do
amstatus=$( "$AMAGENT" --GetSDState 2>/dev/null )
returncode=$?
if [[ "$returncode" -eq 0 ]]; then
if [[ "$amstatus" -eq 0 ]]; then
break
else
newstate=$( "$AMAGENT" --GetSDStateString 2>/dev/null )
if [[ "$newstate" != "$sdstate" ]]; then
sdstate="$newstate"
echo "$sdstate"
fi
fi
fi
sleep 5
done
}
# Send inventory.
function am_send_inventory() {
wait_amagent_idle
echo "Sending inventory"
"$AMAGENT" --SendInventory 2>/dev/null
sleep 5
}
# Perform software distribution check.
function am_sdcheck() {
wait_amagent_idle
echo "Checking software distribution"
"$AMAGENT" --SDCheck 2>/dev/null
sleep 5
}
function main() {
local name
local datestamp
local i
name=$( scutil --get ComputerName 2>/dev/null || echo '<no name>' )
datestamp=$( date +'%F %T' )
echo "* Absolute Manage kickstart for $name ($datestamp)"
sleep 5
wait_for_path "$AMAGENT"
wait_for_ping "$AMSERVER"
for i in 1 2; do
am_send_inventory
am_sdcheck
done
datestamp=$( date +'%F %T' )
echo "* Kickstart done ($datestamp)"
}
main "$@"
<?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>Label</key>
<string>se.gu.it.kickstartam</string>
<key>ProgramArguments</key>
<array>
<string>/Library/Scripts/DAFGU/kickstartam.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment