File gimp-help-update-spec.sh of Package gimp-help

#!/bin/bash

LANGUAGES_NO_IMAGES="pl sv"
LANGUAGES_INCOMPLETE='cs hr lt zh_CN'
LANGUAGES_NO_EXAMPLES='es ko nl pl ru sv'

unset ${!LANG_NAME__*}
LANG_NAME__af="Afrikaans"
LANG_NAME__am="Amharic"
LANG_NAME__ang="Old English"
LANG_NAME__ar="Arabic"
LANG_NAME__as="Assamese"
LANG_NAME__ast="Asturian"
LANG_NAME__az="Azeri"
LANG_NAME__be="Belarusian"
LANG_NAME__be__AT__latin="Belarusian Latin"
LANG_NAME__bg="Bulgarian"
LANG_NAME__bn="Bengali"
LANG_NAME__bn_BD="Bengali / Bangla"
LANG_NAME__bn_IN="Bengali, India"
LANG_NAME__br="Breton"
LANG_NAME__bs="Bosnian"
LANG_NAME__ca="Catalan"
LANG_NAME__cs="Czech"
LANG_NAME__cy="Welsh"
LANG_NAME__da="Danish"
LANG_NAME__de="German"
LANG_NAME__dz="Dzongkha"
LANG_NAME__el="Greek"
LANG_NAME__en_AU="English, Australia"
LANG_NAME__en_CA="English, Canada"
LANG_NAME__en_GB="English, Great Britain"
LANG_NAME__en_US="English, USA"
LANG_NAME__eo="Esperanto"
LANG_NAME__es="Spanish"
LANG_NAME__es_AR="Spanish, Argentina"
LANG_NAME__es_CL="Spanish, Chile"
LANG_NAME__es_CO="Spanish, Colombia"
LANG_NAME__es_CR="Spanish, Costa Rica"
LANG_NAME__es_DO="Spanish, Dominican Republic"
LANG_NAME__es_EC="Spanish, Ecuador"
LANG_NAME__es_ES="Spanish, Spain"
LANG_NAME__es_GT="Spanish, Guatemala"
LANG_NAME__es_HN="Spanish, Honduras"
LANG_NAME__es_MX="Spanish, Mexico"
LANG_NAME__es_NI="Spanish, Nicaragua"
LANG_NAME__es_PA="Spanish, Panama"
LANG_NAME__es_PE="Spanish, Peru"
LANG_NAME__es_PR="Spanish, Puerto Rico"
LANG_NAME__es_SV="Spanish, El Salvador"
LANG_NAME__es_UY="Spanish, Uruguay"
LANG_NAME__es_VE="Spanish, Venezuela"
LANG_NAME__et="Estonian"
LANG_NAME__eu="Basque"
LANG_NAME__fa="Persian"
LANG_NAME__fi="Finnish"
LANG_NAME__fr="French"
LANG_NAME__fur="Friulian"
LANG_NAME__ga="Irish"
LANG_NAME__gl="Galician"
LANG_NAME__gn="Brazilian Guarani"
LANG_NAME__gu="Gujarati"
LANG_NAME__he="Hebrew"
LANG_NAME__hi="Hindi"
LANG_NAME__hr="Croatian"
LANG_NAME__hu="Hungarian"
LANG_NAME__hy="Armenian"
LANG_NAME__id="Indonesian"
LANG_NAME__io="Ido"
LANG_NAME__is="Icelandic"
LANG_NAME__it="Italian"
LANG_NAME__ja="Japanese"
LANG_NAME__ka="Georgian"
LANG_NAME__km="Khmer"
LANG_NAME__kn="Kannada"
LANG_NAME__ko="Korean"
LANG_NAME__ku="Kurdish"
LANG_NAME__ky="Kyrgyz"
LANG_NAME__li="Limburgish"
LANG_NAME__lo="Lao"
LANG_NAME__lt="Lithuanian"
LANG_NAME__lv="Latvian"
LANG_NAME__mai="Maithili"
LANG_NAME__mg="Malagasy"
LANG_NAME__mi="Maori"
LANG_NAME__mk="Macedonian"
LANG_NAME__ml="Malayalam"
LANG_NAME__mn="Mongolian"
LANG_NAME__mr="Marathi"
LANG_NAME__ms="Malay"
LANG_NAME__nb="Norwegian Bokmal"
LANG_NAME__nds__AT__NFE="Low Saxon NFE (Northern Frisian Enclave)"
LANG_NAME__ne="Nepali"
LANG_NAME__nl="Dutch"
LANG_NAME__nn="Norwegian Nynorsk"
LANG_NAME__nso="Northern Sotho"
LANG_NAME__oc="Occitan"
LANG_NAME__or="Oriya"
LANG_NAME__pa="Punjabi"
LANG_NAME__pa_IN="Punjabi (Gurmukhi)"
LANG_NAME__pa_PK="Punjabi (Shahmukhi)"
LANG_NAME__pl="Polish"
LANG_NAME__ps="Pashto, Pushto"
LANG_NAME__pt="Portuguese"
LANG_NAME__pt_BR="Brasilian Portuguese"
LANG_NAME__ro="Romanian"
LANG_NAME__ru="Russian"
LANG_NAME__rw="Kinyarwanda"
LANG_NAME__si="Sinhala"
LANG_NAME__sk="Slovak"
LANG_NAME__sl="Slovenian"
LANG_NAME__sq="Albanian"
LANG_NAME__sr="Serbian"
LANG_NAME__sr__AT__Latn="Serbian Latin"
LANG_NAME__sr__AT__ije="Serbian Cyrillic"
LANG_NAME__sv="Swedish"
LANG_NAME__ta="Tamil"
LANG_NAME__te="Telugu"
LANG_NAME__tg="Tajik"
LANG_NAME__th="Thai"
LANG_NAME__tk="Turkmen"
LANG_NAME__tr="Turkish"
LANG_NAME__tt="Tatar"
LANG_NAME__ug="Uighur"
LANG_NAME__uk="Ukrainian"
LANG_NAME__ur="Urdu"
LANG_NAME__uz="Uzbek"
LANG_NAME__uz__AT__cyrillic="Uzbek Cyrillic"
LANG_NAME__vi="Vietnamese"
LANG_NAME__wa="Walloon"
LANG_NAME__wal="Walaita"
LANG_NAME__xh="Xhosa"
LANG_NAME__yi="Yiddish"
LANG_NAME__yo="Yoruba"
LANG_NAME__zh_CN="Simplified Chinese"
LANG_NAME__zh_HK="Chinese, Hong Kong"
LANG_NAME__zh_TW="Traditional Chinese"
LANG_NAME__zu="Zulu"


LANG_LIST=$(
	(
		for LNG in $LANGUAGES_NO_IMAGES ; do
			echo $LNG
		done
		tar -jtf gimp-help-2.4.1.tar.bz2 | sed -n '
s%.*/\([^/]*\)/[^/]*$%TRANS:\1%
/dir/d
/map/d
/src/d
/omf/d
/web/d
/po/d
/^TRANS:\('"${LANGUAGES_INCOMPLETE// /\\|}"'\)$/d
s/^TRANS:no$/TRANS:nb/
s/^TRANS:\(..\)$/\1/p
s/^TRANS:\(...\)$/\1/p
s/^TRANS:\(.._..\)$/\1/p
s/^TRANS:\(.._...\)$/\1/p
s/^TRANS:\(..._..\)$/\1/p
s/^TRANS:\(..._...\)$/\1/p
') | sort -u)

sed <gimp-help.spec >gimp-help.spec.in '
1,/%package/{
/%package/i \
@PACKAGE@
}
/^%prep/ a \
%prep
/%package/,/%prep/d

/^%changelog/a \
@FILES@\
%changelog
/^%files /,/^%changelog/d
'

exec <gimp-help.spec.in
exec >gimp-help.spec

while read -r ; do
    case "$REPLY" in
	@PACKAGE@ )
	    for LNG in $LANG_LIST ; do
		eval LNG_NAME\=\"\$LANG_NAME__${LNG//@/__AT__}\"
		if test -z "$LNG_NAME" ; then
		    echo >&2 "ERROR: No LANG_NAME name for \"$LNG\" defined ${LNG//@/__AT__}!"
		    LNG_NAME=FIXME
		fi
		case $LNG in
		    ja | ja_* ) GROUP=System/I18n/Japanese ;;
		    ko | ko_* ) GROUP=System/I18n/Korean ;;
		    zh_* ) GROUP=System/I18n/Chinese ;;
		    * ) GROUP=System/Localization ;;
		esac
		cat <<EOF
%package $LNG
Summary:        $LNG_NAME Help System Data for GIMP2
Group:          $GROUP
Requires:       %{name} = %{version}
Provides:       locale(%{name}:$LNG)

%description $LNG
GIMP-Help is a help system designed for use with the internal GIMP help
browser, external Web browsers and HTML renderers, and human eyes.
Docbook is used to create a highly customizable system for all needs.

This package provides $LNG_NAME data for gimp-help.

EOF
	    done
	    ;;
	@FILES@ )
	    for LNG in $LANG_LIST ; do
		eval 'case $LNG in
		    '"${LANGUAGES_NO_IMAGES// /|}"' ) IMAGES= ;;
		    * ) IMAGES="%lang($LNG) %{_datadir}/gimp/2.0/help/*/*/$LNG
" ;;
		esac'
		eval 'case $LNG in
		    '"${LANGUAGES_NO_EXAMPLES// /|}"' ) EXAMPLES= ;;
		    * ) EXAMPLES="%lang($LNG) %{_datadir}/gimp/2.0/help/*/*/examples/$LNG
" ;;
		esac'
		cat <<EOF
%files $LNG
%defattr (-,root,root)
%lang($LNG) %{_datadir}/gimp/2.0/help/$LNG
$IMAGES$EXAMPLES
EOF
	    done
	    ;;
	* )
	    echo "$REPLY"
	    ;;
    esac
done

rm gimp-help.spec.in