# Run the common initialization process
# USAGE: initialization_default $command_line_argument[…]
initialization_default() {
	# Exit if the current process has been spawned by the root user.
	init_fail_as_root

	# Set the options for the current shell.
	init_shell_options

	# Check early if ./play.it has been called in a listing mode, since most of the initialisation steps are not required in these modes.
	# This is called before options parsing because the listing mode might have been set by a parent ./play.it process.
	init_archives_list
	init_games_list

	# Check the expected compatibility level against the current library version.
	init_compatibility_level_check

	# Set the default and current options.
	init_options "$@"
	init_options_validity_check
	init_output_directory

	# If some early action is set, run it then exit.
	init_early_actions

	# Set up the base archive.
	init_archive

	# Run no-op actions as soon as the base archive is set.
	init_noop_actions
	init_packages_already_built

	# Set the path to the temporary directory.
	init_working_directory
	init_working_directory_checks

	# Set the default package, used by the context system when no explicit package context is set.
	init_package

	# Check for the presence of required tools.
	init_requirements_check

	# Check for the presence of extra archives.
	init_extra_archives_required
	init_extra_archives_optional

	# Check the archives integrity.
	init_archives_integrity_check
}

# Automatically run the initialization process when sourcing the library from an old game script
# This can be bypassed by setting $LIB_ONLY to any non-null value
if \
	[ -z "${LIB_ONLY:-}" ] && \
	! compatibility_level_is_at_least '2.31'
then
	initialization_default "$@"
fi

