Skip to content

Commit

Permalink
add facts to facilitate license acceptance of GUI Xcode and cut down …
Browse files Browse the repository at this point in the history
…on shellouts
  • Loading branch information
keeleysam committed Oct 19, 2016
1 parent 5e4baca commit 56b6195
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 24 deletions.
11 changes: 11 additions & 0 deletions lib/facter/xcode_active_directory.rb
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
43 changes: 43 additions & 0 deletions lib/facter/xcode_license_accepted.rb
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
26 changes: 13 additions & 13 deletions lib/facter/xcode_product.rb
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
13 changes: 6 additions & 7 deletions lib/facter/xcode_tools_present.rb
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
6 changes: 3 additions & 3 deletions manifests/init.pp
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
}
}
8 changes: 7 additions & 1 deletion manifests/install.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class xcode_tools::install {
if $::xcode_tools_present == false {
if $facts['xcode_tools_present'] == false {

file {'/private/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress':
ensure => 'present'
Expand All @@ -11,5 +11,11 @@
} ->

exec {'/bin/rm -f private/tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress': }

}

unless $facts['xcode_license_accepted'] {
exec { '/usr/bin/xcodebuild -license accept': }
}

}

0 comments on commit 56b6195

Please sign in to comment.