Skip to content

Commit

Permalink
local config override
Browse files Browse the repository at this point in the history
Related to #9,  "Add local config override file"

Distro configs sorted out into associative arrays, and
`distro_configure_repos` function sorted into separate 'repo' configs.

Now distros and repos params can be overridden in a local config file.
A poor example is included.

This also paves the way to a solution for #3.

Package overrides not done.

Also, architecture handling mess refactored into separate file
  • Loading branch information
zultron committed Apr 11, 2015
1 parent b50b713 commit 49f96a7
Show file tree
Hide file tree
Showing 20 changed files with 342 additions and 266 deletions.
6 changes: 6 additions & 0 deletions local-config-example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@
# need exit status from Docker.
#DOCKER_ALWAYS_ALLOCATE_TTY=true

# Override distro settings
#
# Custom mirror
#DISTRO_MIRROR[jessie]="http://http.debian.net/debian"
# Restrict list of arches
#DISTRO_ARCHES[jessie]="armhf"
56 changes: 56 additions & 0 deletions scripts/architecture.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
arch_default() {
# The default architecture is the first in the $DISTRO_ARCHES list
local DISTRO=$1
echo ${DISTRO_ARCHES[$DISTRO]} | awk '{print $1}'
}

arch_host() {
# The host arch is given with the '-a' option
local DISTRO=$1
local ARCH=$2

if test $ARCH = 'default'; then
ARCH=$(arch_default)
fi
echo $ARCH
}

arch_build() {
# The build arch for a package is the host arch if the package
# cannot be cross-built. Otherwise, if the host arch is a
# 'personality' of the machine arch (e.g. amd64->i386), use the
# host arch. Otherwise, use the machine arch.
local DISTRO=$1
local ARCH=$2
local HOST_ARCH=$(arch_host $DISTRO $ARCH)

if $NATIVE_BUILD_ONLY || \
! distro_base_repo $DISTRO $HOST_ARCH >/dev/null; then
echo $HOST_ARCH
return
fi

# By default, the build arch is the machine arch...
local BUILD_ARCH=$(arch_machine)

# ...But check for 'personality' compatibility
if test $BUILD_ARCH = amd64 -a $HOST_ARCH = i386; then
BUILD_ARCH=i386
fi

echo $BUILD_ARCH
}

arch_machine() {
# The machine arch is the Docker host's arch
dpkg-architecture -qDEB_BUILD_ARCH
}

arch_is_foreign() {
local DISTRO=$1
local ARCH=$2
local RES
test $(arch_host $DISTRO $ARCH) = $(arch_build $DISTRO $ARCH) && \
RES=0 || RES=1
return $RES
}
5 changes: 5 additions & 0 deletions scripts/base-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ GNUPGHOME=$CONFIG_DIR/gpg
# Scripts and configs directories
SCRIPTS_DIR=scripts
DISTRO_CONFIG_DIR=$SCRIPTS_DIR/distro
REPO_CONFIG_DIR=$SCRIPTS_DIR/repo
PACKAGE_CONFIG_DIR=$SCRIPTS_DIR/package

# Suffix for package version
Expand All @@ -74,3 +75,7 @@ DBUILD=$(basename $0)

# ccache directory
CCACHE_DIR=$CONFIG_DIR/ccache


# Default arch list
ARCHES="amd64 i386 armhf"
12 changes: 12 additions & 0 deletions scripts/debian-binary-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,21 @@ ccache_setup() {
fi
}

binary_package_check_arch() {
local ARCH=$(arch_host $DISTRO $HOST_ARCH)

# Check package's list of excluded arches
for a in $EXCLUDE_ARCHES; do
if test $a = $ARCH; then
error "Package $PACKAGE excluded from arch $ARCH"
fi
done
}

binary_package_build() {
msg "Building binary package '$PACKAGE'"
source_package_init
binary_package_check_arch
ccache_setup
sbuild_build_package
}
Expand Down
193 changes: 170 additions & 23 deletions scripts/distro.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,107 @@
debug " Sourcing distro.sh"

# Distros
declare DISTROS
declare -A DISTRO_PACKAGES
declare -A DISTRO_ARCHES
declare -A DISTRO_REPOS
declare -A DISTRO_CODENAME
for arch in $ARCHES; do
eval "declare -A DISTRO_ARCHES_$arch"
done

# Repos
declare REPOS
declare -A REPO_MIRROR
declare -A REPO_ARCHES
declare -A REPO_KEY
declare -A REPO_COMPONENTS
declare -A REPO_IS_BASE

distro_read_config() {
local DISTRO=$1
DISTROS+=" $DISTRO"

# set up defaults
DISTRO_PACKAGES[$DISTRO]=
DISTRO_ARCHES[$DISTRO]="$ARCHES"
DISTRO_REPOS[$DISTRO]=
DISTRO_CODENAME[$DISTRO]=$DISTRO

. $DISTRO_CONFIG_DIR/$DISTRO.sh
}

distro_read_all_configs() {
debug " Sourcing distro configurations:"
for config in $DISTRO_CONFIG_DIR/*.sh; do
local distro=$(basename $config .sh)
debug " $distro"
distro_read_config $distro
done
}

repo_read_config() {
local REPO=$1
REPOS+=" $REPO"

# set up defaults
REPO_MIRROR[$REPO]=
REPO_ARCHES[$REPO]="$ARCHES"
REPO_KEY[$REPO]=
REPO_COMPONENTS[$REPO]="main"
REPO_IS_BASE[$REPO]="false"

. $REPO_CONFIG_DIR/$REPO.sh
}

repo_read_all_configs() {
debug " Sourcing repo configurations:"
for config in $REPO_CONFIG_DIR/*.sh; do
local repo=$(basename $config .sh)
debug " $repo"
repo_read_config $repo
done
}

distro_base_mirror() {
local DISTRO=$1
local ARCH=$2
echo ${REPO_MIRROR[$(distro_base_repo $DISTRO $ARCH)]}
}

distro_base_components() {
local DISTRO=$1
local ARCH=$2
echo ${REPO_COMPONENTS[$(distro_base_repo $DISTRO $ARCH)]}
}

repo_has_arch() {
local REPO=$1
local ARCH=$2
local ARCHES=" ${REPO_ARCHES[$REPO]} "
local RES
test "$ARCHES" != "${ARCHES/ $ARCH /}" && RES=0 || RES=1
return $RES
}

distro_base_repo() {
local DISTRO=$1
local ARCH=$2
local repo
for repo in ${DISTRO_REPOS[$DISTRO]}; do
if repo_has_arch $repo $ARCH && ${REPO_IS_BASE[$repo]}; then
echo $repo
return
fi
done
return 1
}

repo_add_apt_key() {
KEY=$1
REPO=$1
KEY=${REPO_KEY[$REPO]}
test -n "$KEY" || return 0

KEYRING=$CHROOT_DIR/etc/apt/trusted.gpg.d/sbuild-extra.gpg
debug " Adding apt key '$KEY'"
case $KEY in
Expand All @@ -26,33 +126,80 @@ repo_add_apt_key() {
}

repo_add_apt_source() {
local NAME=$1
local URL=$2
local ARCHES=${3:-$BUILD_ARCH}
local COMPONENTS="main${4:+ $4}"
echo "deb [arch=$ARCHES] $URL $CODENAME $COMPONENTS" \
>> $CHROOT_DIR/etc/apt/sources.list.d/$NAME.list
local REPO=$1
local URL=${REPO_MIRROR[$REPO]}
local ARCHES=$(echo ${REPO_ARCHES[$REPO]} | sed 's/ /,/g')
local CODENAME=${DISTRO_CODENAME[$DISTRO]}
local COMPONENTS=${REPO_COMPONENTS[$REPO]}

if test $REPO = local; then
CODENAME=$DISTRO
else
CODENAME=${DISTRO_CODENAME[$DISTRO]}
fi
run bash -c "echo deb [arch=$ARCHES] $URL $CODENAME $COMPONENTS \\
>> $CHROOT_DIR/etc/apt/sources.list.d/$REPO.list"
}

repo_configure_dovetail_automata() {
# Dovetail Automata LLC Machinekit repository; currently Wheezy,
# Jessie, Trusty
repo_add_apt_source machinekit http://deb.dovetail-automata.com
repo_add_apt_key 7F32AE6B73571BB9
repo_configure() {
local REPO=$1
debug " Configuring repo $REPO"
repo_add_apt_source $REPO
repo_add_apt_key $REPO
}

repo_configure_emdebian() {
# Emdebian.org cross-build toolchain
repo_add_apt_source emdebian http://emdebian.org/tools/debian
repo_add_apt_key \
http://emdebian.org/tools/debian/emdebian-toolchain-archive.key
distro_clear_apt() {
if test -f $CHROOT_DIR/etc/apt/sources.list; then
debug " Cleaning old apt sources lists"
run bash -c "> $CHROOT_DIR/etc/apt/sources.list"
run rm -f $CHROOT_DIR/etc/apt/sources.list.d/*
fi
}

repo_configure_rcn() {
# Robert C Nelson's Beaglebone Black distro; currently Wheezy,
# Jessie, Trusty
repo_add_apt_source rcn http://repos.rcn-ee.net/debian armhf
repo_add_apt_key \
http://repos.rcn-ee.net/debian/conf/repos.rcn-ee.net.gpg.key
distro_configure_apt() {
local DISTRO=$1
distro_clear_apt

debug " Configuring distro $DISTRO"
for repo in ${DISTRO_REPOS[$DISTRO]} local; do
repo_configure $repo
done

# Set apt proxy
if test -n "$HTTP_PROXY"; then
debug " Setting apt proxy: $HTTP_PROXY"
run bash -c "echo Acquire::http::Proxy \\\"$HTTP_PROXY\\\"\\; > \
$CHROOT_DIR/etc/apt/apt.conf.d/05proxy"
run_debug cat $CHROOT_DIR/etc/apt/apt.conf.d/05proxy
fi

}

distro_debug() {
for d in $DISTROS; do
echo "distro $d:"
echo " codename ${DISTRO_CODENAME[$d]}"
echo " arches ${DISTRO_ARCHES[$d]}"
echo " repos ${DISTRO_REPOS[$d]}"
for a in ${DISTRO_ARCHES[$d]}; do
echo " arch $a:"
echo " base repo: $(distro_base_repo $d $a)"
echo " base mirror: $(distro_base_mirror $d $a)"
echo " base components: $(distro_base_components $d $a)"
repos=
for r in ${DISTRO_REPOS[$d]}; do
if repo_has_arch $r $a; then
repos+=" $r"
fi
done
echo " repos: $repos"
done
done
for r in $REPOS; do
echo "repo $r:"
echo " mirror ${REPO_MIRROR[$r]}"
echo " components ${REPO_COMPONENTS[$r]}"
echo " arches ${REPO_ARCHES[$r]}"
echo " key ${REPO_KEY[$r]:-(none)}"
done
}
25 changes: 5 additions & 20 deletions scripts/distro/jessie.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
# RT kernel packages
PACKAGES="xenomai rtai linux linux-tools linux-latest"
DISTRO_PACKAGES[jessie]="xenomai rtai linux linux-tools linux-latest"
# ZeroMQ packages
PACKAGES+=" czmq"
DISTRO_PACKAGES[jessie]+=" czmq"
# Zultron Debian package repo
PACKAGES+=" dovetail-automata-keyring"

# Jessie arches
ARCHES="amd64 i386 armhf"

# Jessie distro mirror and keys
DISTRO_MIRROR=http://http.debian.net/debian

distro_configure_repos() {
# Cross-build tools
repo_configure_emdebian

# Dovetail Automata; enable to pull deps not built locally
#repo_configure_dovetail_automata # include for partial builds

# RCN's ARM repo
# repo_configure_rcn
}
DISTRO_PACKAGES[jessie]+=" dovetail-automata-keyring"

# Repos to configure for jessie
DISTRO_REPOS[jessie]="debian emdebian"
Loading

0 comments on commit 49f96a7

Please sign in to comment.