mirror of
https://github.com/munki/munki.git
synced 2026-05-01 09:49:31 -05:00
Removed code/client/conditions as those are examples
This commit is contained in:
@@ -1,2 +0,0 @@
|
||||
.DS_Store
|
||||
test*
|
||||
@@ -1,22 +0,0 @@
|
||||
#!/bin/sh
|
||||
# This is an example of a bash conditional script which outputs a key with an array of values
|
||||
# Please note how the array is created and used within the defaults statement for proper output
|
||||
|
||||
# Read the location of the ManagedInstallDir from ManagedInstall.plist
|
||||
managedinstalldir="$(defaults read /Library/Preferences/ManagedInstalls ManagedInstallDir)"
|
||||
# Make sure we're outputting our information to "ConditionalItems.plist" (plist is left off since defaults requires this)
|
||||
plist_loc="$managedinstalldir/ConditionalItems"
|
||||
|
||||
IFS=$'\n' # Set our field spearator to newline since each unique item is on its own line
|
||||
for hardware_port in `networksetup -listallhardwareports | awk -F ": " '/Hardware Port/{print $2}'`; do
|
||||
# build array of values from output of above command
|
||||
hardware_ports+=( $hardware_port )
|
||||
done
|
||||
|
||||
# Note the key "hardware_ports" which becomes the condition that you would use in a predicate statement
|
||||
defaults write "$plist_loc" "hardware_ports" -array "${hardware_ports[@]}"
|
||||
|
||||
# CRITICAL! Since 'defaults' outputs a binary plist, we need to ensure that munki can read it by converting it to xml
|
||||
plutil -convert xml1 "$plist_loc".plist
|
||||
|
||||
exit 0
|
||||
@@ -1,76 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
'''This is a basic example of a conditional script which outputs 2 key/value pairs:
|
||||
Examples:
|
||||
primary_interface_name: en0
|
||||
primary_ip_address: 192.168.1.128
|
||||
|
||||
NOTE: Information gathered is ONLY for the primary interface'''
|
||||
|
||||
from SystemConfiguration import * # from pyObjC
|
||||
import socket
|
||||
import collections
|
||||
import os
|
||||
import plistlib
|
||||
|
||||
from Foundation import CFPreferencesCopyAppValue
|
||||
|
||||
# Read the location of the ManagedInstallDir from ManagedInstall.plist
|
||||
BUNDLE_ID = 'ManagedInstalls'
|
||||
pref_name = 'ManagedInstallDir'
|
||||
managedinstalldir = CFPreferencesCopyAppValue(pref_name, BUNDLE_ID)
|
||||
# Make sure we're outputting our information to "ConditionalItems.plist"
|
||||
conditionalitemspath = os.path.join(managedinstalldir, 'ConditionalItems.plist')
|
||||
|
||||
NETWORK_INFO = {}
|
||||
def getIPAddress(service_uuid):
|
||||
ds = SCDynamicStoreCreate(None, 'GetIPv4Addresses', None, None)
|
||||
newpattern = SCDynamicStoreKeyCreateNetworkServiceEntity(None,
|
||||
kSCDynamicStoreDomainState,
|
||||
service_uuid,
|
||||
kSCEntNetIPv4)
|
||||
|
||||
newpatterns = CFArrayCreate(None, (newpattern, ), 1, kCFTypeArrayCallBacks)
|
||||
ipaddressDict = SCDynamicStoreCopyMultiple(ds, None, newpatterns)
|
||||
for ipaddress in ipaddressDict.values():
|
||||
ipv4address = ipaddress['Addresses'][0]
|
||||
return ipv4address
|
||||
|
||||
|
||||
def getNetworkInfo():
|
||||
ds = SCDynamicStoreCreate(None, 'GetIPv4Addresses', None, None)
|
||||
|
||||
pattern = SCDynamicStoreKeyCreateNetworkGlobalEntity(None,
|
||||
kSCDynamicStoreDomainState,
|
||||
kSCEntNetIPv4);
|
||||
patterns = CFArrayCreate(None, (pattern, ), 1, kCFTypeArrayCallBacks)
|
||||
valueDict = SCDynamicStoreCopyMultiple(ds, None, patterns)
|
||||
|
||||
ipv4info = collections.namedtuple('ipv4info', 'ifname ip router service')
|
||||
|
||||
for serviceDict in valueDict.values():
|
||||
ifname = serviceDict[u'PrimaryInterface']
|
||||
NETWORK_INFO['interface'] = serviceDict[u'PrimaryInterface']
|
||||
NETWORK_INFO['service_uuid'] = serviceDict[u'PrimaryService']
|
||||
NETWORK_INFO['router'] = serviceDict[u'Router']
|
||||
NETWORK_INFO['ip_address'] = getIPAddress(serviceDict[u'PrimaryService'])
|
||||
|
||||
netinfo_dict = dict(
|
||||
primary_interface_name = ifname,
|
||||
primary_ip_address = NETWORK_INFO['ip_address'],
|
||||
)
|
||||
|
||||
# CRITICAL!
|
||||
if os.path.exists(conditionalitemspath):
|
||||
# "ConditionalItems.plist" exists, so read it FIRST (existing_dict)
|
||||
existing_dict = plistlib.readPlist(conditionalitemspath)
|
||||
# Create output_dict which joins new data generated in this script with existing data
|
||||
output_dict = dict(existing_dict.items() + netinfo_dict.items())
|
||||
else:
|
||||
# "ConditionalItems.plist" does not exist,
|
||||
# output only consists of data generated in this script
|
||||
output_dict = netinfo_dict
|
||||
|
||||
# Write out data to "ConditionalItems.plist"
|
||||
plistlib.writePlist(output_dict, conditionalitemspath)
|
||||
|
||||
getNetworkInfo()
|
||||
Reference in New Issue
Block a user