File debian.rules of Package roundcubemail-skin-now

#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

%:
	dh $@

override_dh_install:
	rm -rvf kolab/
	rm -rvf plesk/

	find . | sort

	find \
		/usr/share/roundcubemail/skins/kolab/ \
		/usr/share/roundcubemail/public_html/assets/skins/kolab/ \
		/usr/share/roundcubemail/plugins/libkolab/skins/kolab/ \
		/usr/share/roundcubemail/public_html/assets/plugins/libkolab/skins/kolab/ \
		-type f | sort | while read file; do \
			target_dir=$$(dirname $${file} | sed -e 's|/usr/share/roundcubemail|.|g' -e 's|/public_html/assets/|/|g' -e 's|/public_html/assets/plugins/libkolab/|/|g' -e 's|/kolab|/now|g') ; \
			file_name=$$(basename $${file}) ; \
			if [ ! -d i$${target_dir} ]; then \
				mkdir -p $${target_dir} ; \
			fi ; \
			cp -av $${file} $${target_dir} ; \
		done

	find . | sort

	sed -i -e 's/"kolab"/"now"/g' \
		$$(find skins/now/ plugins/libkolab/skins/now/ -type f)

	find kolab/ -type f | sort | while read file; do \
		target_dir="./skins/$$(dirname $${file})" ; \
		file_name=$$(basename $${file}) ; \
		if [ ! -d $${target_dir} ]; then \
			mkdir -p $${target_dir} ; \
		fi ; \
		cp -av $${file} $${target_dir} ; \
	done

	rm -rvf kolab/

	find . | sort

	sed -i -e 's/"kolab"/"now"/g' plugins/libkolab/skins/now/libkolab.less

	sed -i -e 's/"Kolab /"Kolab Now /g' skins/now/meta.json

	for file in $$(find . -type f -name "styles.less" -o -name "print.less" -o -name "embed.less" -o -name "libkolab.less"); do \
		lessc --relative-urls $${file} > $$(dirname $${file})/$$(basename $${file} .less).css ; \
		sed -i \
			-e "s|../../../skins/now/images/contactpic.png|../../../../skins/now/images/contactpic.png|" \
			-e "s|../../../skins/now/images/watermark.jpg|../../../../skins/now/images/watermark.jpg|" \
			$$(dirname $${file})/$$(basename $${file} .less).css ; \
	done

	for orig_dir in "skins/now/" "plugins/libkolab/skins/now/"; do \
		asset_dir="public_html/assets/$${orig_dir}" ; \
		\
		# Compress the CSS ; \
		for file in `find $${orig_dir} -type f -name "*.css"`; do \
			asset_loc=$$(dirname $$(echo $${file} | sed -e "s|$${orig_dir}|$${asset_dir}|g")) ; \
			mkdir -p $${asset_loc} ; \
			cat $${file} | cssmin > $${asset_loc}/$$(basename $${file}) ; \
		done || : \
		\
		# Compress the JS, but not the already minified ; \
		for file in `find $${orig_dir} -type f -name "*.js" ! -name "*.min.js"`; do \
			asset_loc=$$(dirname $$(echo $${file} | sed -e "s|$${orig_dir}|$${asset_dir}|g")) ; \
			mkdir -p $${asset_loc} ; \
			uglifyjs $${file} > $${asset_loc}/$$(basename $${file}) ; \
		done || : \
		\
		# The already minified JS can just be copied over to the assets location ; \
		for file in `find $${orig_dir} -type f -name "*.min.js"`; do \
			asset_loc=$$(dirname $$(echo $${file} | sed -e "s|$${orig_dir}|$${asset_dir}|g")) ; \
			mkdir -p $${asset_loc} ; \
			cp -av $${file} $${asset_loc}/$$(basename $${file}) ; \
		done || : \
		\
		# Other assets ; \
		for file in $$(find $${orig_dir} -type f \
			-name "*.eot" -o \
			-name "*.gif" -o \
			-name "*.ico" -o \
			-name "*.jpg" -o \
			-name "*.mp3" -o \
			-name "*.png" -o \
			-name "*.svg" -o \
			-name "*.swf" -o \
			-name "*.tif" -o \
			-name "*.ttf" -o \
			-name "*.woff" -o \
			-name "*.woff2" \
		); do \
			asset_loc=$$(dirname $$(echo $${file} | sed -e "s|$${orig_dir}|$${asset_dir}|g")) ; \
			mkdir -p $${asset_loc} ; \
			cp -avf $${file} $${asset_loc}/$$(basename $${file}) ; \
		done || : \
		\
		# Purge empty directories ; \
		find $${orig_dir} -type d -empty -delete || : ; \
	done

	cp -av skins/now/watermark.html public_html/assets/skins/now/watermark.html

	find . | sort

	rm -rvf skins/kolab/
	rm -rvf plugins/libkolab/skins/kolab/
	rm -rvf public_html/assets/plugins/libkolab/skins/kolab/
	rm -rvf public_html/assets/skins/kolab/

	cp -av skins/now/ debian/roundcubemail-skin-now/usr/share/roundcubemail/skins/.
	cp -av plugins/libkolab/skins/now/ debian/roundcubemail-skin-now/usr/share/roundcubemail/plugins/libkolab/skins/.
	cp -av public_html/assets/plugins/libkolab/skins/now/ debian/roundcubemail-skin-now/usr/share/roundcubemail/public_html/assets/plugins/libkolab/skins/.
	cp -av public_html/assets/skins/now/ debian/roundcubemail-skin-now/usr/share/roundcubemail/public_html/assets/skins/.