#!/bin/bash

INC=/usr/share/ltsp/diskless-functions
if [ ! -e "$INC" ]; then
	echo "couldn't find $INC, exiting..." >&2
	exit 16
fi
. "$INC"


if [ -z "$*" ]; then
	echo "Usage: $PROG YUM_CONFIG..."
	exit 1
fi

echo_header "Starting $PROG..."

yum_opts=
cfg=
while [ -n "$1" ]; do
	case "$1" in
		-*)
			yum_opts+="$1 "
			shift && continue
		;;
		*)
			cfg="$1"
		;;
	esac
	[ -z "$cfg" ] && break

	if [ -s "$cfg" ]; then
		action "processing: ${yum_opts}$cfg" yum -y ${yum_opts} -c "$cfg" update
	else
		error "$cfg: no such file or it's empty"
	fi

	# uncomment next line if you don't want to keep opts for others
	#opts=
	cfg=
	shift
done
echo

action "$(echo_date) running ltsp-update..."
/usr/sbin/diskless-update-bootdir -d ltsp /opt/ltsp
/usr/sbin/diskless-update-bootdir /var/diskless/CHROOTS
echo

exit 0
