#!/bin/sh
# ***** BEGIN LICENSE BLOCK *****
# * Copyright (C) 2007  Alexey Gladkov <legion@altlinux.org>
# *
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License as published by
# * the Free Software Foundation; either version 2 of the License, or
# * (at your option) any later version.
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# * GNU General Public License for more details.
# *
# * You should have received a copy of the GNU General Public License
# * along with this program; if not, write to the Free Software
# * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
# ***** END LICENSE BLOCK *****

. /usr/share/alterator/build/backend3.sh

#installer license
installer_path='/tmp/metadata'
#system license
system_path='/usr/share/alt-license'

on_message() {
	case "$in_action" in
        	read)
			local license_file= path lang languages

			languages="$(printf '%s' "$in_language" |tr ';' ' ') all"
	
			for path in "$installer_path" "$system_path"; do
			    for lang in $languages; do
			    	    case "$lang" in
				    	    POSIX|C|all) lang="all";;
					    *) lang="$(printf %s "${lang%%_*}" |tr '[A-Z]' '[a-z]')";;
				    esac

		    		license_file="$path/license.$lang.html"
				[ ! -s "$license_file" ] || break 2
			    done
			done

			if [ -s "$license_file" ]; then
				printf '(license "%s")' "$(cat "$license_file" |simple_quote)"
			else
				printf '(error "%s")' "License file not found"
			fi
                        ;;
		*)
			echo '#f'
			;;
        esac
}

message_loop
