#!/bin/sh -efu
### This file is covered by the GNU General Public License
### version 2 or later.
###
### Copyright (C) 2018  ALT Linux Team
### Author: Leonid Krivoshein <klark@altlinux.org>

if [ -z "${__included_rescue_launcher_auto-}" ]; then
__included_rescue_launcher_auto=1

. /usr/libexec/rescue-launcher/net-functions

# Probe by all known ways
autorun_probe_auto_method() {
	local rundir="/usr/libexec/rescue-launcher"
	local etcdir="/etc/rescue-launcher"
	local i= methods=

	autorun_debug "Using AUTO..."

	if [ -r "$etcdir/local.list" ]; then
		methods="$(cat $etcdir/local.list)"
	fi
	if [ -r "$etcdir/network.list" ]; then
		autorun_networking ||:
		if [ "${AUTORUN_NETOK-}" = "1" ]; then
			methods="$methods $(cat $etcdir/network.list)"
		fi
	fi
	if [ -r "$etcdir/virtual.list" ]; then
		methods="$methods $(cat $etcdir/virtual.list)"
	fi

	for i in $methods; do
		test -r "$rundir/methods/$i" || continue

		. "$rundir/methods/$i"

		if autorun_probe_${i}_method; then
			return 0
		fi
	done

	return 1
}

fi #__included_rescue_launcher_auto
