Skip to content

Commit 6aa1dcb

Browse files
committed
fix the shebang-fix
Signed-off-by: Lincoln Baker <[email protected]>
1 parent 9765541 commit 6aa1dcb

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#
2+
# Copyright 2012-2020, Chef Software Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
#
18+
# Use this software definition to fix the shebang of knife binary
19+
# to point to the embedded ruby.
20+
#
21+
22+
name "knife-shebang-fix"
23+
24+
default_version "0.0.1"
25+
26+
license :project_license
27+
skip_transitive_dependency_licensing true
28+
29+
build do
30+
if windows?
31+
# No action needed on Windows
32+
else
33+
block "Update knife shebang to point to embedded Ruby" do
34+
# Fix the shebang for knife binary specifically
35+
# #!/usr/bin/env ruby
36+
knife_file = "#{install_dir}/embedded/bin/knife"
37+
if File.exist?(knife_file)
38+
update_shebang = false
39+
rest_of_the_file = ""
40+
41+
File.open(knife_file) do |f|
42+
shebang = f.readline
43+
if shebang.start_with?("#!") &&
44+
shebang.include?("ruby") &&
45+
!shebang.include?("#{install_dir}/embedded/bin/ruby")
46+
rest_of_the_file = f.read
47+
update_shebang = true
48+
end
49+
end
50+
51+
if update_shebang
52+
File.open(knife_file, "w+") do |f|
53+
f.puts("#!#{install_dir}/embedded/bin/ruby")
54+
f.puts(rest_of_the_file)
55+
end
56+
end
57+
end
58+
end
59+
end
60+
end

omnibus/config/software/server-complete.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
# moved earlier because it is external to this repo and pinned, so should change infrequently
3939
dependency "chef" # for embedded chef-client -z runs (built from main - build last)
4040

41+
# fix knife shebang after chef is installed
42+
dependency "knife-shebang-fix"
43+
4144
dependency "private-chef-ctl" # additional project-specific private-chef-ctl subcommands
4245

4346
# download the gpg-key beforehand for rhel systems to

0 commit comments

Comments
 (0)