Add commandline argument for config file

A config file can be specified when running build, e.g.:

  ./build.sh myconfig
This commit is contained in:
Sam Tygier 2018-12-18 21:06:18 +00:00 committed by XECDesign
parent cc6605695d
commit 7fbfdda31e
3 changed files with 32 additions and 14 deletions

View File

@ -95,6 +95,13 @@ A simple example for building Raspbian:
IMG_NAME='Raspbian' IMG_NAME='Raspbian'
``` ```
The config file can also be specified on the command line as an argument the `build.sh` or `build-docker.sh` scripts.
```
./build -c myconfig
```
This is parsed after `config` so can be used to override values set there.
## How the build process works ## How the build process works

View File

@ -19,24 +19,25 @@ if [ -f config ]; then
source config source config
fi fi
while getopts "c:" flag
do
case "$flag" in
c)
EXTRA_CONFIG="$OPTARG"
config_file=( "${config_file[@]}" "--env-file" "$(pwd)/${EXTRA_CONFIG}")
source "$EXTRA_CONFIG"
;;
esac
done
CONTAINER_NAME=${CONTAINER_NAME:-pigen_work} CONTAINER_NAME=${CONTAINER_NAME:-pigen_work}
CONTINUE=${CONTINUE:-0} CONTINUE=${CONTINUE:-0}
PRESERVE_CONTAINER=${PRESERVE_CONTAINER:-0} PRESERVE_CONTAINER=${PRESERVE_CONTAINER:-0}
if [ "$*" != "" ] || [ -z "${IMG_NAME}" ]; then if [ -z "${IMG_NAME}" ]; then
if [ -z "${IMG_NAME}" ]; then echo "IMG_NAME not set in 'config'" 1>&2
echo "IMG_NAME not set in 'config'" 1>&2 echo 1>&2
echo 1>&2 exit 1
fi
cat >&2 <<EOF
Usage:
build-docker.sh [options]
Optional environment arguments: ( =<default> )
CONTAINER_NAME=pigen_work set a name for the build container
CONTINUE=1 continue from a previously started container
PRESERVE_CONTAINER=1 keep build container even on successful build
EOF
exit 1
fi fi
CONTAINER_EXISTS=$($DOCKER ps -a --filter name="$CONTAINER_NAME" -q) CONTAINER_EXISTS=$($DOCKER ps -a --filter name="$CONTAINER_NAME" -q)

View File

@ -127,6 +127,16 @@ if [ -f config ]; then
source config source config
fi fi
while getopts "c:" flag
do
case "$flag" in
c)
EXTRA_CONFIG="$OPTARG"
source "$EXTRA_CONFIG"
;;
esac
done
if [ -z "${IMG_NAME}" ]; then if [ -z "${IMG_NAME}" ]; then
echo "IMG_NAME not set" 1>&2 echo "IMG_NAME not set" 1>&2
exit 1 exit 1