Posted on 06-04-2015 01:33 PM
I've been dipping my toes into AutoPkg lately. I've been building Java, Silverlight, and a few others that all come with handy version extensions. I noticed that the Office one returns a string of "true","false", or "Not Installed". This makes it super easy to target a group (Office out of date = true) and never have to touch it again. That'd be really handy for all those other extensions. Unfortunately, they all return the version number. That's really handy, but I'd love to modify it to be more like the Office one. That way I don't have to go update the "Out_Of_Date_Java" group's criteria every time a new version comes out.
Here's what I have for my ExtensionTemplate for Java:
<computer_extension_attribute>
<name>Java Out Of Date</name>
<description />
<data_type>String</data_type>
<input_type>
<type>script</type>
<platform>Mac</platform>
<script>#!/bin/bash
from distutils.version import StrictVersion
import subprocess
import os.path
import shlex
import sys
CURRENT_VERSION = StrictVersion('%VERSION%')
JAVA_VERSION=$(defaults read /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Info.plist CFBundleVersion)
if JAVA_VERSION < CURRENT_VERSION:
result = true
else if: JAVA_VERSION = '':
result = 'Not Installed'
else:
result = false
print '<result>%s</result>' % str(result)
exit 0</script>
</input_type>
<inventory_display>Extension Attributes</inventory_display>
<recon_display>Extension Attributes</recon_display>
</computer_extension_attribute>
I have no idea if this makes any real sense though. I'm so out of date with scripting that I'm not confident in my abilities. I believe that says that if the java version is less than the current version built by AutoPkg, it returns true. If the java version is blank, it returns "Not Installed". In any other situation, it should return false. I don't believe this actually works. If it does, it is taking its sweet time to return anything from any machine.
Is there a better way to get auto-updating extension attributes to return the "true", "False", and "Not Installed" values for various?
Solved! Go to Solution.
Posted on 06-04-2015 02:01 PM
I'm confused. You seem to have a mix of two types of scripting languages going on there. The script contents indicates its a bash script (#!/bin/bash) but it has import commands as the first several lines which would indicate a python script. Plus there are other syntax elements that aren't going to work in bash. Yet, the JAVA_VERSION variable is using the bash $(some command)
variable syntax. You need to have it use one or the other.
Its possible sometimes to use some perl one liners in bash scripts, but I've not seen bash scripts use python constructs in it and have it work correctly.
Posted on 06-04-2015 02:01 PM
I'm confused. You seem to have a mix of two types of scripting languages going on there. The script contents indicates its a bash script (#!/bin/bash) but it has import commands as the first several lines which would indicate a python script. Plus there are other syntax elements that aren't going to work in bash. Yet, the JAVA_VERSION variable is using the bash $(some command)
variable syntax. You need to have it use one or the other.
Its possible sometimes to use some perl one liners in bash scripts, but I've not seen bash scripts use python constructs in it and have it work correctly.
Posted on 06-04-2015 06:47 PM
@mm2270 That's because I am an idiot when it comes to scripting. I'm so out of practice that I didn't even notice the mishmash of languages.