Created
November 27, 2014 14:10
-
-
Save MagerValp/3d31d733b9bfd5fb7dec to your computer and use it in GitHub Desktop.
Force Absolute Manage agent to install packages without delay.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
Sorry for the late reply, I don't think GitHub sent me a notification when you posted.
The reason for checking the return code is that in some situations the agent just returns -1 and an error message that it can't connect to the message port.