#!/bin/bash

family=sablink

# The source package name will be the first token in the changelog
changelog="${family}/changelog"
package=$(sed -n '1s/\([^ ]*\).*/\1/p' ${changelog})

# Get some version info
release=$(sed -n "1s/^${package} (\([^-]*\)-.*/\1/p" ${changelog})
revision=$(sed -n "1s/^${package} (${release}-\([^)]*\).*/\1/p" ${changelog})

flavourconf=$(find ${family} -name config.flavour.$1)
if [ ! -f "${flavourconf}" ]; then
    echo "Found no flavour configuration for '$1'." 1>&2
    exit 1
fi

archconfdir=$(dirname ${flavourconf})
version="Ubuntu ${release}-${revision}-$1"
re="s/.*\(CONFIG_VERSION_SIGNATURE\).*/\1=""\"${version}\"""/"

# Generate .config
cat ${family}/config/config.common.${family} \
    ${archconfdir}/config.common.$(basename ${archconfdir}) \
    ${flavourconf} | sed -e "${re}" > .config
