#!/usr/bin/make -f
# -*- makefile -*-

include /usr/share/cdbs/1/rules/debhelper.mk

# Uncomment this to turn on verbose mode.
#DEB_VERBOSE_ALL=1
#DH_VERBOSE=1

binary-install/foreman::
	# Cleanup unused files
	find debian/foreman -name '.cvsignore' -type f | xargs rm -f
	find debian/foreman -name '.gitignore' -type f | xargs rm -f
	find debian/foreman -name '.git' -type d | xargs rm -rf
	find debian/foreman -name '.svn' -type d | xargs rm -rf
	# Mark scripts as executable
	chmod a+x debian/foreman/usr/share/foreman/vendor/rails/activesupport/lib/active_support/vendor/builder-2.1.2/blankslate.rb
	chmod a+x debian/foreman/usr/share/foreman/vendor/rails/activesupport/lib/active_support/vendor/builder-2.1.2/builder.rb
	chmod a+x debian/foreman/usr/share/foreman/vendor/rails/activesupport/lib/active_support/vendor/builder-2.1.2/builder/blankslate.rb
	chmod a+x debian/foreman/usr/share/foreman/vendor/rails/activesupport/lib/active_support/vendor/builder-2.1.2/builder/css.rb
	chmod a+x debian/foreman/usr/share/foreman/vendor/rails/activesupport/lib/active_support/vendor/builder-2.1.2/builder/xchar.rb
	chmod a+x debian/foreman/usr/share/foreman/vendor/rails/activesupport/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb
	chmod a+x debian/foreman/usr/share/foreman/vendor/rails/activesupport/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb
	chmod a+x debian/foreman/usr/share/foreman/vendor/rails/activesupport/lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb
	# Remove executable bit from files where not necessary
	chmod a-x debian/foreman/usr/share/foreman/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/lib/rchardet/*.rb
	chmod a-x debian/foreman/usr/share/foreman/vendor/rails/actionmailer/lib/action_mailer/vendor/text-format-0.6.3/text/format.rb
	chmod a-x debian/foreman/usr/share/foreman/vendor/rails/actionpack/lib/action_controller/request.rb
	chmod a-x debian/foreman/usr/share/foreman/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
	chmod a-x debian/foreman/usr/share/foreman/vendor/rails/activerecord/lib/active_record/*.rb
	chmod a-x debian/foreman/usr/share/foreman/vendor/rails/activerecord/test/cases/base_test.rb
	chmod a-x debian/foreman/usr/share/foreman/vendor/rails/railties/bin/rails
	chmod a-x debian/foreman/usr/share/foreman/vendor/rails/railties/fresh_rakefile
	chmod a-x debian/foreman/usr/share/foreman/vendor/rails/railties/lib/commands/generate.rb
	chmod a-x debian/foreman/usr/share/foreman/vendor/rails/activerecord/test/cases/counter_cache_test.rb
	chmod a-x debian/foreman/usr/share/foreman/vendor/rails/activesupport/lib/active_support/vendor/i18n-0.4.1/i18n.rb
	# Remove license files
	rm -f debian/foreman/usr/share/foreman/vendor/gems/googlecharts-1.3.6/License.txt
	rm -f debian/foreman/usr/share/foreman/vendor/gems/rack-1.1.0/COPYING
	rm -f debian/foreman/usr/share/foreman/vendor/plugins/acts_as_audited/LICENSE
	rm -f debian/foreman/usr/share/foreman/vendor/plugins/google_visualr/MIT-LICENSE
	rm -f debian/foreman/usr/share/foreman/vendor/plugins/has_many_polymorphs/LICENSE
	rm -f debian/foreman/usr/share/foreman/vendor/plugins/proxy/MIT-LICENSE
	rm -f debian/foreman/usr/share/foreman/vendor/plugins/ruby-net-ldap/COPYING
	rm -f debian/foreman/usr/share/foreman/vendor/plugins/ruby-net-ldap/LICENSE
	rm -f debian/foreman/usr/share/foreman/vendor/plugins/searchlogic/LICENSE
	rm -f debian/foreman/usr/share/foreman/vendor/plugins/virt/LICENSE.txt
	rm -f debian/foreman/usr/share/foreman/vendor/plugins/will_paginate/LICENSE
	rm -f debian/foreman/usr/share/foreman/vendor/rails/actionmailer/MIT-LICENSE
	rm -f debian/foreman/usr/share/foreman/vendor/rails/actionmailer/lib/action_mailer/vendor/tmail-1.2.7/tmail/vendor/rchardet-1.3/COPYING
	rm -f debian/foreman/usr/share/foreman/vendor/rails/actionpack/MIT-LICENSE
	rm -f debian/foreman/usr/share/foreman/vendor/rails/activerecord/MIT-LICENSE
	rm -f debian/foreman/usr/share/foreman/vendor/rails/activeresource/MIT-LICENSE
	rm -f debian/foreman/usr/share/foreman/vendor/rails/activesupport/MIT-LICENSE
	rm -f debian/foreman/usr/share/foreman/vendor/rails/railties/MIT-LICENSE
	rm -f debian/foreman/usr/share/foreman/vendor/rails/railties/lib/rails_generator/generators/components/plugin/templates/MIT-LICENSE
	# Fix scripts
	sed -e 's:/usr/local/bin/ruby:/usr/bin/env ruby:' -i debian/foreman/usr/share/foreman/vendor/plugins/has_many_polymorphs/test/integration/app/public/dispatch.cgi
	sed -e 's:/usr/local/bin/ruby:/usr/bin/env ruby:' -i debian/foreman/usr/share/foreman/vendor/plugins/has_many_polymorphs/test/integration/app/public/dispatch.rb
	sed -e 's:/usr/local/bin/ruby:/usr/bin/env ruby:' -i debian/foreman/usr/share/foreman/vendor/gems/ruby2ruby-1.2.5/test/test_ruby2ruby.rb
	sed -e 's:/usr/local/bin/ruby:/usr/bin/env ruby:' -i debian/foreman/usr/share/foreman/vendor/gems/ruby_parser-2.0.5/test/test_ruby_lexer.rb
	sed -e 's:/usr/local/bin/ruby:/usr/bin/env ruby:' -i debian/foreman/usr/share/foreman/vendor/gems/ruby_parser-2.0.5/test/test_ruby_parser.rb
	sed -e 's:/usr/local/bin/ruby:/usr/bin/env ruby:' -i debian/foreman/usr/share/foreman/vendor/gems/sexp_processor-3.0.5/test/test_composite_sexp_processor.rb
	sed -e 's:/usr/local/bin/ruby:/usr/bin/env ruby:' -i debian/foreman/usr/share/foreman/vendor/gems/sexp_processor-3.0.5/test/test_environment.rb
	sed -e 's:/usr/local/bin/ruby:/usr/bin/env ruby:' -i debian/foreman/usr/share/foreman/vendor/gems/sexp_processor-3.0.5/test/test_sexp.rb
	sed -e 's:/usr/local/bin/ruby:/usr/bin/env ruby:' -i debian/foreman/usr/share/foreman/vendor/gems/sexp_processor-3.0.5/test/test_sexp_processor.rb
	# Patch environments.rb - necessary since changing source format to 3.0 (native)
	patch -p0 debian/foreman/usr/share/foreman/config/environment.rb debian/patches/01_gem_dependencies.patch
