#!/bin/bash

[ -n "$LKP_SRC" ] || LKP_SRC=$(dirname $(dirname $(readlink -e -v $0)))

rootfs=$1
[[ $rootfs ]] || rootfs=$(readlink -e /osimage/debian/latest)
[[ $rootfs ]] || {
	echo "What rootfs should I build packages for?"
	exit 1
}

show_cmd()
{
	echo "$@"
	"$@"
}

queue()
{
	echo queue "$@"
	command queue "$@"
}

. $LKP_SRC/distro/common

# create cgz for the below jobs first, to avoid circular dependency
show_cmd $LKP_SRC/sbin/pack-deps $rootfs pack-deps	|| exit

queue pack-deps.yaml rootfs=$rootfs benchmark=pack -q vip --wait 3600 || exit

if [[ $2 = 'each' ]]; then
	for i in $(show_deps_list); do
		queue pack-deps.yaml	rootfs=$rootfs benchmark=$i
	done
	for i in $(show_pack_list); do
		queue pack.yaml		rootfs=$rootfs benchmark=$i
	done
elif [[ $2 = 'all' ]]; then
	queue pack-deps.yaml -s "benchmark: all" rootfs=$rootfs
	queue pack.yaml -s "benchmark: all" rootfs=$rootfs
fi
