#!/bin/sh

po_domain="alterator-livecd"
alterator_api_version=1
postinstall_hooks_dir=/usr/lib/alterator/hooks/livecd-postinstall.d
livecd_root_dir=/livecd-root

. alterator-sh-functions
. alterator-livecd-functions

on_message() {
  case "$in_action" in
    write)
	case "$in__objects" in
		/)
		# update /etc/fstab after installation
		chroot "$livecd_root_dir" service livecd-fstab start >&2 ||:
		# resurrect fixed mount points at the end of installer work
		chroot "$livecd_root_dir" mount -a
		# turn on swap again
		chroot "$livecd_root_dir" swapon -a

		# Unmount /livecd-root and remove it.
		mount | sed -r -n "s;^.+ on ($livecd_root_dir/.+) type .+$;\1;p" | sort -r | xargs umount
		umount -l "$livecd_root_dir" && rmdir "$livecd_root_dir" ||
			write_error "`_ "Can't remove $livecd_root_dir"`"
		;;
		run-postinstall)
		# Run postintall scripts in livecd root.
		chroot "$livecd_root_dir" run-parts "$postinstall_hooks_dir"
		;;
	esac
	;;
	read)
	local languages= html_file=

	languages="$(printf '%s' "$in_language" |tr ';' ' ') all"
	html_file="$(find_htmlfile "livecd-finish" "$languages")"
	if [ -s "$html_file" ]; then
		write_string_param "url" "$html_file"
	else
		write_error "`_ "File not found"`"
	fi
	;;
  esac
}

message_loop
