#!/bin/sh

alterator_api_version=1
default_steps_file=/usr/share/install2/installer-steps
old_step_dir=/usr/share/install2/steps
new_step_dir=/usr/share/alterator/steps

#turn off auto expansion
set -f

. alterator-sh-functions

print_step()
{
    while read uri help icon name;do
	write_table_item \
	    name "$uri" \
	    label "$name" \
	    help "$help" \
	    icon "$icon"
    done
}

on_message()
{
	case "$in_action" in
		list)
		    [ -n "$in_steps_file" ] || in_steps_file="$default_steps_file"

		    if [ ! -s "$in_steps_file" ];then
			write_error "Step file \"$in_steps_file\" not found"
			return
		    fi

		    local p=
		    while read f; do
			p="$(find -L $old_step_dir $new_step_dir -type f -name "$f.desktop" -print -quit)"
			[ -n "$p" ] || continue
			alterator-dump-desktop \
			    -v lang="$in_language" \
			    -v out="X-Alterator-URI;X-Alterator-Help;Icon;Name" \
			    -v def="/notfound;notfound;altlinux;" \
			    "$p"
		    done<"$in_steps_file"|
			print_step
		;;
	esac
}

message_loop
