File find-requires.sh of Package obs-server

#!/bin/bash

sourcearchive=$1
shift
limit="$1"
shift

tdir=`mktemp -d`

# extract files
tar xzf "$sourcearchive" -C "$tdir" >&/dev/null

cd "$tdir"/open-build-service*
for p do
  patch -p1 < "$p" >&/dev/null
done

cd src/api
rm -rf Gemfile.lock

ruby -rbundler -e 'exit' || echo "_ERROR_BUNDLER_NOT_INSTALLED_"
ruby -rbundler -e '
  limit = ARGV.map{|x| x.to_sym}
  limit << :default if !limit.empty? && !limit.include?(:default)
  Bundler.definition.dependencies.select{|d|
    limit.empty? || !(d.groups & limit).empty?
  }.each do |d|
    d.requirement.requirements.each do |op, ver|
      if ver.prerelease?
        prerel = ver.version.sub /^#{ver.release}\./, ""
        v = "#{ver.release}~#{prerel}"
      else
        v = ver.release
      end
      if op == "~>"
        puts "(rubygem(#{d.name}) >= #{v} with rubygem(#{d.name}) < #{v.bump})"
      elsif op == ">=" && v == Gem::Version.create("0")
        puts "rubygem(#{d.name})"
      else
        puts "rubygem(#{d.name}) #{op} #{v}"
      end
    end
  end' $limit | grep -v 'webui' | while read i; do echo -n $i", "; done

#cleanup
rm -rf "$tdir"