#!/bin/sh

alterator_api_version=1
postinstall_dir="/usr/share/install2/postinstall.d"
run_postinstall_dir="/run/install2/postinstall.d"
livecd_postinstall_dir="/run/install2/livecd-postinstall.d"

. alterator-sh-functions

PROG=postinstall

run_postinstall()
{
	# copy unique scripts from $postinstall_dir to $root_dir/$postinstall_dir
	[ -d "$postinstall_dir" ] &&
		find "$postinstall_dir" -mindepth 1 -maxdepth 1 -type f -perm -u=x \
			-exec cp -n {} "$run_postinstall_dir" \;

	# run scripts
	export PATH=/run/install2/bin:$PATH
	for f in "$run_postinstall_dir"/* "$livecd_postinstall_dir/*"; do
		[ -f "$f" -a -x "$f" ] || continue

		echo "Running $f" >>/tmp/postinstall.log
		if "$f" >>/tmp/postinstall.log 2>&1; then
		    echo DONE >>/tmp/postinstall.log
		else
		    echo FAILED >>/tmp/postinstall.log
		fi
	done

	rm -f /_NEW_SYSTEM_
}

on_message()
{
        case "$in_action" in
        	write)
			echo "$PROG: write post" >&2
			run_postinstall
                        ;;
	esac
}

message_loop
