#! /bin/sh

tag=
case "$1" in
--tag)	tag="--branch $2";;
esac

#############################################################################
# download Noto font emojis

if [ -d noto-emojis ]
then	if [ -d noto-emojis/.git ]
	then	(cd noto-emojis; git pull)
	else	echo WARNING: directory noto-emojis already exists but no git config - Exit
		exit 9
	fi
else
	notogit=https://github.com/googlefonts/noto-emoji
	if git clone $tag --depth 1 -n --filter=blob:none $notogit noto-emojis
	then	true
	else	echo WARNING: given git tag $tag not found - Exit
		exit 9
	fi
	(cd noto-emojis
	 git sparse-checkout set --no-cone png/128 third_party/region-flags/png
	 git checkout
	)
fi
(mkdir -p noto; rm -f noto/*.png; ln noto-emojis/png/128/*.png noto/)

#############################################################################
# download Noto third-party flags emojis
# like getflags -n but use same repository

if [ -d noto-emoji-flags ]
then	if [ -d noto-emoji-flags/.git ]
	then	(cd noto-emoji-flags; git pull)
	else	echo WARNING: directory noto-emoji-flags already exists but no git config - Exit
		exit 9
	fi
else
	ln -s noto-emojis noto-emoji-flags
fi
(cd noto-emoji-flags; rm -f *.png; ln third_party/region-flags/png/*.png ./)

#############################################################################
# download rename Noto third-party flags

`dirname $0`/getflags -e

#############################################################################
# end
