gem2deb shouldn't rewrite shebangs of shell scripts
gem2deb 0.2.9 happily rewrote the shebang line of a shell script in
/usr/bin of my package. Attached patch makes it only do that if ruby is
mentioned anywhere in the first line of the script: if it's not, and
there is a shebang in the line to begin with, I think it's safe to
assume it's not a Ruby script.
--
Dmitry Borodaenko
diff --git a/lib/gem2deb/dh_ruby.rb b/lib/gem2deb/dh_ruby.rb
index eb08399..001dba5 100644
--- a/lib/gem2deb/dh_ruby.rb
+++ b/lib/gem2deb/dh_ruby.rb
@@ -340,11 +340,16 @@ module Gem2Deb
def rewrite_shebangs(package, ruby_binary)
Dir.glob(File.join(destdir_for(package), @bindir, '**/*')).each do |path|
next if File.directory?(path)
- puts "Rewriting shebang line of #{path}" if @verbose
atomic_rewrite(path) do |input, output|
- old = input.gets # discard
- output.puts "#!#{ruby_binary}"
- unless old =~ /#!/
+ old = input.gets
+ if old =~ /ruby/ or old !~ /^#!/
+ puts "Rewriting shebang line of #{path}" if @verbose
+ output.puts "#!#{ruby_binary}"
+ unless old =~ /#!/
+ output.puts old
+ end
+ else
+ puts "Not rewriting shebang line of #{path}" if @verbose
output.puts old
end
output.print input.read
Reply to: