#!/bin/sh

## Copyright (C) 2006-2014 Daniel Baumann <mail@daniel-baumann.ch>
##
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
## This is free software, and you are welcome to redistribute it
## under certain conditions; see COPYING for details.


set -e

# User is unprivileged
if [ "$(id -u)" -ne 0 ]
then
	echo "E: need root privileges"
	exit 1
fi

# Redirect stdout to stderr due Debconf usage
exec 1>&2

# Reading the default file
if [ -e /etc/default/extlinux ]
then
	. /etc/default/extlinux
fi

EXTLINUX_UPDATE="${EXTLINUX_UPDATE:-true}"

if [ "${EXTLINUX_UPDATE}" != "true" ]
then
	echo "P: extlinux-update is disabled in /etc/default/extlinux."

	exit 0
fi

# Running /etc/extlinux.d scripts
for _FILE in /etc/extlinux.d/*
do
	if [ -x "${_FILE}" ]
	then
		"${_FILE}"
	fi
done
