|
| 1 | +# |
| 2 | +# Author:: Adam Jacob (<[email protected]>) |
| 3 | +# Copyright:: Copyright (c) 2010 Opscode, Inc. |
| 4 | +# License:: Apache License, Version 2.0 |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +# |
| 18 | + |
| 19 | +require'chef/knife' |
| 20 | + |
| 21 | +classChef |
| 22 | +classKnife |
| 23 | +classCookbookSiteVendor < Knife |
| 24 | + |
| 25 | +banner"Sub-Command: cookbook site vendor COOKBOOK [VERSION] (options)" |
| 26 | + |
| 27 | +defrun |
| 28 | +vendor_path=File.join(Chef::Config[:cookbook_path].first) |
| 29 | +cookbook_path=File.join(vendor_path,name_args[0]) |
| 30 | +upstream_file=File.join(vendor_path,"#{name_args[0]}.tar.gz") |
| 31 | +branch_name="#{name_args[0]}-chef-upstream" |
| 32 | + |
| 33 | +download=Chef::Knife::CookbookSiteDownload.new |
| 34 | +download.config[:file]=upstream_file |
| 35 | +download.name_args=name_args |
| 36 | +download.run |
| 37 | + |
| 38 | +Dir.chdir(vendor_path)do |
| 39 | +Chef::Log.info("Checking out the master branch") |
| 40 | +system("git checkout master") |
| 41 | +branch_output=`git branch --no-color | grep #{branch_name}` |
| 42 | +ifbranch_output =~ /#{branch_name}$/m |
| 43 | +system("git checkout #{branch_name}") |
| 44 | +else |
| 45 | +system("git checkout -b #{branch_name}") |
| 46 | +end |
| 47 | +system("rm -r #{cookbook_path}") |
| 48 | +system("tar zxvf #{upstream_file}") |
| 49 | +system("rm #{upstream_file}") |
| 50 | +system("git add #{name_args[0]}") |
| 51 | +system("git commit -a -m 'Import #{name_args[0]} version #{download.version}'") |
| 52 | +system("git tag -f #{name_args[0]}-#{download.version}") |
| 53 | +system("git checkout master") |
| 54 | +system("git merge #{branch_name}") |
| 55 | +end |
| 56 | +Chef::Log.info("Cookbook #{name_args[0]} version #{download.version} successfully vendored") |
| 57 | +end |
| 58 | + |
| 59 | +end |
| 60 | +end |
| 61 | +end |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | + |
0 commit comments