-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add facts to facilitate license acceptance of GUI Xcode and cut down …
…on shellouts
- Loading branch information
Showing
6 changed files
with
83 additions
and
24 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Facter.add(:xcode_active_directory) do | ||
confine kernel: 'Darwin' | ||
setcode do | ||
output = Facter::Util::Resolution.exec('/usr/bin/xcode-select -p') | ||
if $CHILD_STATUS.exitstatus.nonzero? | ||
nil | ||
else | ||
output | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'puppet/util/plist' | ||
|
||
Facter.add(:xcode_license_accepted) do | ||
confine kernel: 'Darwin' | ||
setcode do | ||
xcode_active_directory = Facter.value(:xcode_active_directory) | ||
if xcode_active_directory.nil? | ||
# no tools installed | ||
nil | ||
elsif xcode_active_directory == '/Library/Developer/CommandLineTools' | ||
# we are using the CLI tools which don't need license accepted | ||
true | ||
elsif xcode_active_directory.include? '.app' | ||
# we need to check license | ||
license_plist = '/Library/Preferences/com.apple.dt.Xcode.plist' | ||
|
||
result = false unless File.exist? license_plist | ||
|
||
license_plist_data = Puppet::Util::Plist.read_plist_file(license_plist) | ||
|
||
xcode_license_info_plist = xcode_active_directory.chomp('Developer') + 'Resources/LicenseInfo.plist' | ||
xcode_license_info_plist_data = Puppet::Util::Plist.read_plist_file(xcode_license_info_plist) | ||
|
||
xcode_info_plist = xcode_active_directory.chomp('Developer') + 'Info.plist' | ||
xcode_info = Puppet::Util::Plist.read_plist_file(xcode_info_plist) | ||
xcode_version = xcode_info['CFBundleShortVersionString'] | ||
|
||
license_type = xcode_license_info_plist_data['licenseType'] | ||
license_id = xcode_license_info_plist_data['licenseID'] | ||
|
||
if license_plist_data['IDEXcodeVersionForAgreedTo' + license_type + 'License'] != xcode_version | ||
result = false | ||
elsif license_plist_data['IDELast' + license_type + 'LicenseAgreedTo'] != license_id | ||
result = false | ||
else | ||
result = true | ||
end | ||
|
||
result | ||
|
||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
Facter.add(:xcode_product) do | ||
confine osfamily: 'Darwin' | ||
setcode do | ||
if Facter.value(:xcode_tools_present) == false | ||
# Oh man this is bad, but we need this file to exist | ||
Facter::Util::Resolution.exec('/usr/bin/touch /private/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress') | ||
# Facter::Util::Resolution.exec('/usr/sbin/softwareupdate -l | grep "\*.*Command Line" | head -n 1 | awk -F"*" \'{print $2}\' | sed -e \'s/^ *//\' | tr -d \'\n\'') | ||
swupd_out = Facter::Util::Resolution.exec('/usr/sbin/softwareupdate -l') | ||
output = nil | ||
swupd_out.each_line do |line| | ||
if line.include? '*' and line.include? 'Command Line' | ||
output = line.sub! ' * ', '' | ||
break | ||
end | ||
end | ||
output.strip | ||
if Facter.value(:xcode_tools_present) == false | ||
# Oh man this is bad, but we need this file to exist | ||
Facter::Util::Resolution.exec('/usr/bin/touch /private/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress') | ||
# Facter::Util::Resolution.exec('/usr/sbin/softwareupdate -l | grep "\*.*Command Line" | head -n 1 | awk -F"*" \'{print $2}\' | sed -e \'s/^ *//\' | tr -d \'\n\'') | ||
swupd_out = Facter::Util::Resolution.exec('/usr/sbin/softwareupdate -l') | ||
output = nil | ||
swupd_out.each_line do |line| | ||
if line.include?('*') && line.include?('Command Line') | ||
output = line.sub! ' * ', '' | ||
break | ||
end | ||
end | ||
output.strip | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
Facter.add(:xcode_tools_present) do | ||
confine osfamily: 'Darwin' | ||
confine kernel: 'Darwin' | ||
setcode do | ||
Facter::Util::Resolution.exec('/usr/bin/xcode-select -p') | ||
if $CHILD_STATUS.exitstatus.nonzero? | ||
false | ||
else | ||
true | ||
end | ||
if Facter.value(:xcode_active_directory).nil? | ||
false | ||
else | ||
true | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
class xcode_tools { | ||
if $facts['os']['family'] == 'Darwin'{ | ||
include xcode_tools::install | ||
} | ||
if $facts['os']['family'] == 'Darwin'{ | ||
include xcode_tools::install | ||
} | ||
} |
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