#!/usr/bin/make -f

major-rubyversion=$(shell ruby -v | cut -d ' ' -f 2 | cut -d '.' -f 1)
minor-rubyversion=$(shell ruby -v | cut -d ' ' -f 2 | cut -d '.' -f 2)
minormax-rubyversion=$(shell echo $$(( $(minor-rubyversion) + 1 )) )


%:
	dh $@

DRADIS_HOME=debian/dradis/usr/lib/dradis

override_dh_install:
	dh_install -X COPYING -X LICENSE

	# Install Gemfile.plugins with all plugins enabled to bundle all
	# gems needed by all plugins
	cp $(DRADIS_HOME)/Gemfile.plugins.template $(DRADIS_HOME)/Gemfile.plugins
	sed -i '1s/^/# PLEASE DO NOT EDIT OR MODIFY THIS FILE IN KALI. IT WILL BREAK DRADIS\n/' $(DRADIS_HOME)/Gemfile.plugins
	sed -i -e 's/^\(#.\)\?gem /gem /' $(DRADIS_HOME)/Gemfile.plugins

	# Download and bundle the required gems
	set -e; cd $(DRADIS_HOME); \
	bundle install --no-cache --path . --without assets development test

	# Drop some directories which are replaced by symlinks
	cd $(DRADIS_HOME) && rm -rf tmp log attachments backup

	# Keep a copy of db/schema.rb in the package
	mv $(DRADIS_HOME)/db/schema.rb $(DRADIS_HOME)/db/schema.rb.initial

override_dh_makeshlibs:
	# Disable as it generates useless stuff

override_dh_installsystemd:
	dh_installsystemd --no-enable --no-start

override_dh_dwz:
override_dh_strip:
	# this command fails because of a lot of issues on binaraies in
	# gems installed via bundle

override_dh_gencontrol:
	dh_gencontrol -- -Vruby:Depends="ruby (>= 1:$(major-rubyversion).$(minor-rubyversion)), ruby (<< 1:$(major-rubyversion).$(minormax-rubyversion))"
