#!/bin/bash

#TODO: make this profile work on itself, eg some stuff from inheriting profiles should be moved in, stuff implemented etc
var_DEFAULTFS="/boot:32:ext2:+ swap:256:swap /:7500:ext3 /home:*:ext3"
var_TARGET_DIR="/mnt" # When overriding this, do _not_ add a trailing /.  It's not needed and maybe you could even break something
var_RUNTIME_PACKAGES=
var_PKG_FILE=$RUNTIME_DIR/package-list
var_MIRRORLIST="/etc/pacman.d/mirrorlist"
var_UI_TYPE="cli" # set to cli or dia for dialog

###### Phases ( can be overridden by more specific procedures) ######
phase_preparation=(\
	configure \
	intro \
	sysprep \
	select_source \
	runtime_network \
	runtime_packages)

phase_basics=(\
	set_clock \
	prepare_disks)

phase_system=(\
	package_list \
	install_packages \
	auto_fstab \
	auto_network \
	auto_locale \
	configure_system \
	mkinitcpio \
	locales \
	install_bootloader)


phase_finish=(msg_report)



###### Workers ( can be overridden by more specific procedures) ######
worker_intro ()
{
	ask_yesno "This is a low-interactivity 'common defaults' installation.  Do you really want to do this?  We may overwrite your data."
	if [ $? -gt 0 ]
	then
		die_error "User aborted base profile execution"
	fi
}


worker_sysprep ()
{
	mount -o remount,rw / &>/dev/null
}


worker_configure ()
{
	var_UI_TYPE=${arg_ui_type:-cli}
}


worker_select_source ()
{
	var_PKG_SOURCE_TYPE='cd'
	var_FILE_URL="file:///src/core/pkg"
	var_SYNC_URL=
	# if you override to use ftp (or ask user and he chooses ftp) don't forget to configure the network and to select_mirrors
}


worker_runtime_network ()
{
	#network is assumed to be functional for now because we do it first with /arch/setup. once that falls away, we'll need to implement it here
	true
}


worker_runtime_packages ()
{
	for pkg in $var_RUNTIME_PACKAGES
	do
		$PACMAN -Sy --noconfirm --needed $pkg
	done
}


worker_set_clock ()
{
	interactive_set_clock
}


worker_prepare_disks ()
{
	partition # use lib-archboot function by default
	# in official installer: autoprepare or diy first partitions, then mountpoints
}


# Put the list of packages to be installed in $TARGET_PACKAGES
worker_package_list ()
{
	#TODO: sensible list of packages. maybe just 'base'
	true
}


worker_install_packages ()
{
	target_prepare_pacman core #TODO: it would be better if this was a separate worker, i think
	[ -z "$TARGET_PACKAGES" ] && die_error "No packages listed to be installed!"
	installpkg
}


worker_auto_fstab ()
{
	target_configure_fstab
}


worker_auto_network ()
{
	[ "$S_DHCP" = 1 ] && target_configure_network dhcp "$PROXY_HTTP" "$PROXY_FTP"
	[ "$S_DHCP" != 1 ] && target_configure_network fixed "$PROXY_HTTP" "$PROXY_FTP"
}


worker_auto_locale ()
{
	target_configure_inital_locale
}


worker_configure_system ()
{
	#TODO: what to do here?
	true
}


worker_mkinitcpio ()
{
	run_mkinitcpio
}


worker_locales ()
{
	target_locale-gen
}


worker_install_bootlader ()
{
	#TODO: ask which disk, install grub on it
	true
}

worker_msg_report ()
{
	show_report
}
