#! /bin/bash

USAGE="import [<flavour>]"

while :
do
	case "$1" in
	-*)
		usage ;;
	*)
		break
	esac
	shift
done

flavour=$1

#
# check the repo validities
#
kdist__cd_kernel_topdir &&
configs__get_repository >/dev/null ||
exit

if ! test -f .config; then
	die "Nothing to import, .config is missing"
fi

#
# Build the new config name
#
if ! test $flavour; then
	flavour=$(config__get_flavour .config) ||
		die "Your current config has no name, specify one."
fi
arch=$(config__architecture .config)
vers=$(config__version)
dst=$vers/$arch/$flavour
src="$(pwd)/.config"

echo Importing current config to $dst
cd $(configs__get_repository)

if test -f $dst; then
	die "config already exists, aborting."
fi

mkdir -p $(dirname $dst)
cp $src $dst
git add $dst
