modified version of jenkins debian glue (https://github.com/mika/jenkins-debian-glue) for devuan
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

47 lines
1.1 KiB

  1. #!/usr/bin/env ruby
  2. if ARGV[0].nil?
  3. $stderr.puts "Usage: #{File.basename $0} <file>"
  4. exit 1
  5. end
  6. if not system "which checkbashisms >/dev/null 2>&1"
  7. $stderr.puts "Error: program checkbashisms does not exist (install devscripts package)."
  8. exit 1
  9. end
  10. file = ARGV[0]
  11. if not File.exists? file
  12. $stderr.puts "Error: file #{file} could not be read."
  13. exit 1
  14. end
  15. # Make sure we're looking at sh code.
  16. mimetype = `file -b -i --keep-going #{file}`.gsub(/\n/,"")
  17. if not /.*x-shellscript/i.match(mimetype)
  18. $stderr.puts "File #{file} doesn't look like sh code [#{mimetype}]. Ignoring."
  19. exit 0
  20. end
  21. output = %x{checkbashisms --posix #{file} 2>&1}
  22. num_lines = output.lines.count / 2 # checkbasims has one line message and one line code
  23. exit 0 if num_lines == 0 # nothing found, jey
  24. counter = 1
  25. if output =~ /does not appear to have a #! interpreter line/
  26. $stderr.puts "File #{file} does not appear to have a #! interpreter line, skipping."
  27. exit 0
  28. end
  29. # output result in TAP format
  30. puts "1..#{num_lines}"
  31. output.gsub(/:\n/, ':').each_line do |critic|
  32. next unless critic =~ /^possible bashism in/
  33. puts "not ok #{counter} #{critic}"
  34. counter += 1
  35. end