File debian.rules of Package roundcubemail-selfcontained

#!/usr/bin/make -f

DH_VERBOSE=1

DESTDIR = $(CURDIR)/debian/roundcubemail

%:
	dh $@

override_dh_auto_build:
	echo $(CURDIR)
	find debian/ -type f | sort

	rm -rvf temp/js_cache/ tests/

    # echo "Asset loc $(CURDIR)/public_html/assets/"

	# All assets
	for file in $$(find $(CURDIR) -type f \
			-name "*.css" -o \
			-name "*.js" -o \
			-name "*.eot" -o \
			-name "*.gif" -o \
			-name "*.ico" -o \
			-name "*.jpg" -o \
			-name "*.mp3" -o \
			-name "dummy.pdf" -o \
			-name "*.png" -o \
			-name "*.svg" -o \
			-name "*.swf" -o \
			-name "*.tif" -o \
			-name "*.tiff" -o \
			-name "*.ttf" -o \
			-name "*.wav" -o \
			-name "*.webp" -o \
			-name "*.woff" -o \
			-name "*.woff2" \
		); do \
		asset_loc=$$(dirname $$(echo $${file} | sed \
				-e "s|$(CURDIR)|$(CURDIR)/public_html/assets/|g" \
				-e "s|$(CURDIR)|$(CURDIR)/public_html/assets/|g" \
				-e "s|$(CURDIR)|$(CURDIR)/public_html/assets/|g") ; \
			) ; \
		mkdir -p $${asset_loc} ; \
		cp -avf $${file} $${asset_loc}/$$(basename $${file}); \
	done


	install -d $(CURDIR)/public_html/assets/program/
	install -d $(CURDIR)/public_html/assets/program/js
	install -d $(CURDIR)/public_html/assets/program/resources
	cp -LR $(CURDIR)/public_html/program/js $(CURDIR)/public_html/assets/program/
	cp -LR $(CURDIR)/public_html/program/resources $(CURDIR)/public_html/assets/program/

	for plugin in `find $(CURDIR)/plugins/ -type d -mindepth 1 -maxdepth 1 -exec basename {} \;) | sort -u`; do \
		if [ -f "$(CURDIR)/plugins/$${plugin}/config.inc.php.dist" ]; then \
			mv $(CURDIR)/plugins/$${plugin}/config.inc.php.dist $(CURDIR)/config/$${plugin}.inc.php ; \
			echo "etc/roundcubemail/$${plugin}.inc.php usr/share/roundcubemail/plugins/$${plugin}/config.inc.php" >> debian/roundcubemail.links ; \
			echo "config/$${plugin}.inc.php etc/roundcubemail/" >> debian/roundcubemail.install ; \
		fi ; \
		if [ -d "$(CURDIR)/public_html/assets/plugins/$${plugin}" ]; then \
			echo "public_html/assets/plugins/$${plugin} usr/share/roundcubemail/public_html/assets/plugins" >> debian/roundcubemail.install ; \
		fi ; \
		echo "usr/share/roundcubemail/plugins/$${plugin}" >> debian/roundcubemail.dirs ; \
		echo "plugins/$${plugin} usr/share/roundcubemail/plugins/" >> debian/roundcubemail.install ; \
		if [ -d "$(CURDIR)/plugins/$${plugin}/lib/Roundcube" ]; then \
			echo "usr/share/roundcubemail/plugins/$${plugin}/lib" >> debian/roundcubemail.dirs ; \
			echo "plugins/$${plugin}/lib/Roundcube usr/share/roundcubemail/plugins/$${plugin}/lib/" >> debian/roundcubemail.install ; \
		fi ; \
	done

	cp -a ${CURDIR}/public_html/plugins/ $(CURDIR)/public_html/assets/plugins/
	cp -a ${CURDIR}/public_html/skins/ $(CURDIR)/public_html/assets/skins/

	cp -v ../SOURCES/2017111400.sql SQL/mysql/

	if [ -f "/etc/plesk-release" ]; then \
		cp -v ../SOURCES/plesk.config.inc.php config/config.inc.php ; \
		cp -v ../SOURCES/plesk.managesieve.inc.php config/managesieve.inc.php ; \
		cp -v ../SOURCES/plesk.password.inc.php config/password.inc.php ; \
		cp -v ../SOURCES/plesk.calendar.inc.php config/calendar.inc.php ; \
		cp -v ../SOURCES/plesk.kolab_addressbook.inc.php config/kolab_addressbook.inc.php ; \
		cp -v ../SOURCES/plesk.kolab_chat.inc.php config/kolab_chat.inc.php ; \
		cp -v ../SOURCES/plesk.kolab_folders.inc.php config/kolab_folders.inc.php ; \
		cp -v ../SOURCES/plesk.libkolab.inc.php config/libkolab.inc.php ; \
		cp -v ../SOURCES/plesk.acl.inc.php config/acl.inc.php ; \
		cp -v ../SOURCES/plesk.tasklist.inc.php config/tasklist.inc.php ; \
		sed -i -e 's/www-data adm/roundcube_sysuser roundcube_sysgroup/g' debian/logrotate ; \
	else \
		find config/ -type f | sort ; \
		if [ -f "config/config.inc.php.sample" ]; then \
			mv config/config.inc.php.sample config/config.inc.php ; \
		fi ; \
	fi


override_dh_install:
	if [ ! -f "/etc/plesk-release" ]; then \
		mkdir -p $(CURDIR)/debian/roundcubemail/etc/apache2/sites-available ; \
		install -pm 644 $(CURDIR)/debian/conf/roundcubemail.conf $(CURDIR)/debian/roundcubemail/etc/apache2/sites-available/roundcubemail.conf ; \
	fi

	dh_install

override_dh_compress:
	dh_compress -Xsql