|
17 | 17 | # limitations under the License. |
18 | 18 | # |
19 | 19 |
|
20 | | -dmg_package "Xcode" do |
21 | | - source node['xcode']['url'] |
22 | | - checksum node['xcode']['checksum'] |
23 | | - action :install |
| 20 | +file_basename = ::File.basename(node['xcode']['url']) |
| 21 | +installer_path = "#{Chef::Config[:file_cache_path]}/#{file_basename}" |
| 22 | +installer_extension = ::File.extname installer_path |
| 23 | + |
| 24 | +if ::Dir.exist? '/Applications/Xcode.app' |
| 25 | + Chef::Log.info('Xcode already installed.') |
| 26 | +else |
| 27 | + remote_file "Download #{file_basename}" do |
| 28 | + backup false |
| 29 | + path installer_path |
| 30 | + source node['xcode']['url'] |
| 31 | + checksum node['xcode']['checksum'] |
| 32 | + not_if { ::File.exist? installer_path } |
| 33 | + end |
| 34 | + |
| 35 | + case installer_extension |
| 36 | + when '.dmg' |
| 37 | + dmg_package 'Xcode' do |
| 38 | + file installer_path |
| 39 | + action :install |
| 40 | + end |
| 41 | + when '.xip' |
| 42 | + include_recipe 'homebrew' |
| 43 | + package 'xz' |
| 44 | + |
| 45 | + remote_file 'Download PBZX v2 unpacker' do |
| 46 | + backup false |
| 47 | + path "#{Chef::Config[:file_cache_path]}/parse_pbzx2.py" |
| 48 | + source 'https://gist.githubusercontent.com/pudquick/ff412bcb29c9c1fa4b8d/raw/24b25538ea8df8d0634a2a6189aa581ccc6a5b4b/parse_pbzx2.py' |
| 49 | + not_if { ::File.exist? "#{Chef::Config[:file_cache_path]}/Content" } |
| 50 | + end |
| 51 | + |
| 52 | + execute 'Verify the signature and certificate chain that signed the archive' do |
| 53 | + command "pkgutil --check-signature #{installer_path}" |
| 54 | + cwd Chef::Config[:file_cache_path] |
| 55 | + end |
| 56 | + |
| 57 | + execute 'Extract the PBZX stream from the archive' do |
| 58 | + command "xar -xf #{file_basename} Content -C ./" |
| 59 | + cwd Chef::Config[:file_cache_path] |
| 60 | + end |
| 61 | + |
| 62 | + execute 'Unpack PBZX archive' do |
| 63 | + command 'python parse_pbzx2.py Content' |
| 64 | + cwd Chef::Config[:file_cache_path] |
| 65 | + end |
| 66 | + |
| 67 | + file "#{Chef::Config[:file_cache_path]}/Content" do |
| 68 | + backup false |
| 69 | + action :delete |
| 70 | + only_if { ::File.exist? "#{Chef::Config[:file_cache_path]}/Content" } |
| 71 | + end |
| 72 | + |
| 73 | + execute 'Decompress the archive' do |
| 74 | + command 'xz -d Content.part00.cpio.xz' |
| 75 | + cwd Chef::Config[:file_cache_path] |
| 76 | + end |
| 77 | + |
| 78 | + execute 'Unpack the CPIO archive' do |
| 79 | + command 'cpio --quiet -idm < ./Content.part00.cpio' |
| 80 | + cwd Chef::Config[:file_cache_path] |
| 81 | + end |
| 82 | + |
| 83 | + file "#{Chef::Config[:file_cache_path]}/Content.part00.cpio" do |
| 84 | + backup false |
| 85 | + action :delete |
| 86 | + only_if { ::File.exist? "#{Chef::Config[:file_cache_path]}/Content.part00.cpio" } |
| 87 | + end |
| 88 | + |
| 89 | + execute 'Move the resulting Xcode app bundle into /Applications' do |
| 90 | + command 'mv Xcode.app /Applications/Xcode.app' |
| 91 | + cwd Chef::Config[:file_cache_path] |
| 92 | + end |
| 93 | + |
| 94 | + file installer_path do |
| 95 | + backup false |
| 96 | + action :delete |
| 97 | + only_if { ::Dir.exist? installer_path } |
| 98 | + end |
| 99 | + else |
| 100 | + Chef::Log.error("Not supported file extension: '#{installer_extension}'.") |
| 101 | + end |
| 102 | +end |
| 103 | + |
| 104 | +execute 'Switch Xcode' do |
| 105 | + command 'xcode-select --switch /Applications/Xcode.app/Contents/Developer' |
| 106 | + not_if { system('xcodebuild -version > /dev/null 2>&1') } |
24 | 107 | end |
25 | 108 |
|
26 | 109 | dmg_package node['xcode']['cli']['package_name'] do |
|
32 | 115 | action :install |
33 | 116 | end |
34 | 117 |
|
35 | | -template "/Library/Preferences/com.apple.dt.Xcode.plist" do |
36 | | - source "com.apple.dt.Xcode.plist.erb" |
37 | | - owner "root" |
38 | | - group "wheel" |
| 118 | +template '/Library/Preferences/com.apple.dt.Xcode.plist' do |
| 119 | + source 'com.apple.dt.Xcode.plist.erb' |
39 | 120 | mode 00644 |
40 | 121 | variables({ |
41 | 122 | :last_gm_license => node['xcode']['last_gm_license'], |
|
0 commit comments