Created
March 1, 2012 19:37
-
-
Save rockpapergoat/1952522 to your computer and use it in GitHub Desktop.
wrapper for jamf policy runner
This file contains hidden or 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
| #!/usr/bin/env ruby | |
| # 110224, revised with loop to accept an array | |
| # 110425, swapped order of variable definition in get_version | |
| # 120301, made more generic, removed loop, added uninstall and install | |
| require 'FileUtils' | |
| def get_version(app) | |
| if File.exists?("#{app}/Contents/Info.plist") | |
| vers = `/usr/bin/defaults read "#{app}"/Contents/Info CFBundleShortVersionString`.chomp | |
| $?.success? ? vers : "ERROR: could not get version" | |
| else | |
| puts "#{app} is not installed." | |
| end | |
| return vers | |
| end | |
| def uninstall_app(app,version) | |
| if get_version(app).to_f < version.to_f | |
| puts "version matches: #{version}. removing..." | |
| #FileUtils.rm_rf(app, :verbose => true) | |
| else | |
| puts "version < #{version} of #{app} not present." | |
| return "1" | |
| end | |
| end | |
| def install_app(app,trigger) | |
| puts "installing #{app}" | |
| %x(/usr/sbin/jamf -policy -trigger #{trigger} -verbose) | |
| end | |
| if uninstall_app(ARGV[3],ARGV[4]) == "1" | |
| exit | |
| else | |
| install_app(ARGV[3],ARGV[5]) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment