#!/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 $@

overidde_dh_auto_clean:
	rm -rf .bundle Gemfile.lock

override_dh_auto_build:
	echo -n "DEPENDENCY CHECK":
	bundle install --local --no-cache --without test --path debian/gems && echo "OK" || echo "NOT OK"
	rm -rf debian/gems
	#Install only the activerecord gem version 6.*: not currently in Debian but required fo this version.
	bundle install --gemfile=debian/Gemfile --path bundle

override_dh_install:
	dh_install --sourcedir=$$(pwd)
	# Drop unwanted executable permissions
	find debian/beef-xss/usr/share/beef-xss/modules \
	     debian/beef-xss/usr/share/beef-xss/extensions \
	     -type f -executable -print0 | \
	     xargs -0 chmod -x
	chmod 755 debian/beef-xss/usr/share/beef-xss/modules/exploits/rfi_scanner/update-list
	chmod 755 debian/beef-xss/usr/share/beef-xss/modules/exploits/shell_shock_scanner/update-list

override_dh_gencontrol:
	# this can be remove once we remove the bundle install of activerecord gem version 6.*
	dh_gencontrol -- -Vruby:Depends="ruby (>= 1:$(major-rubyversion).$(minor-rubyversion)), ruby (<< 1:$(major-rubyversion).$(minormax-rubyversion))"

