Blame SOURCES/mk-docker-opts.sh

37628b
#!/bin/bash
37628b
37628b
usage() {
37628b
	echo "$0 [-f FLANNEL-ENV-FILE] [-d DOCKER-ENV-FILE] [-i] [-c] [-m]
37628b
37628b
Generate Docker daemon options based on flannel env file
37628b
OPTIONS:
37628b
	-f	Path to flannel env file. Defaults to /run/flannel/subnet.env
37628b
	-d	Path to Docker env file to write to. Defaults to /run/docker_opts.env
37628b
	-i	Output each Docker option as individual var. e.g. DOCKER_OPT_MTU=1500
37628b
	-c	Output combined Docker options into DOCKER_OPTS var
37628b
	-k	Set the combined options key to this value (default DOCKER_OPTS=)
37628b
	-m	Do not output --ip-masq (useful for older Docker version)
37628b
" >/dev/stderr 
37628b
37628b
	exit 1
37628b
}
37628b
37628b
flannel_env="/run/flannel/subnet.env"
37628b
docker_env="/run/docker_opts.env"
37628b
combined_opts_key="DOCKER_OPTS"
37628b
indiv_opts=false
37628b
combined_opts=false
37628b
ipmasq=true
37628b
37628b
while getopts "f:d:ick:" opt; do
37628b
	case $opt in
37628b
		f)
37628b
			flannel_env=$OPTARG
37628b
			;;
37628b
		d)
37628b
			docker_env=$OPTARG
37628b
			;;
37628b
		i)
37628b
			indiv_opts=true
37628b
			;;
37628b
		c)
37628b
			combined_opts=true
37628b
			;;
37628b
		m)
37628b
			ipmasq=false
37628b
			;;
37628b
		k)
37628b
			combined_opts_key=$OPTARG
37628b
			;;
37628b
		\?)
37628b
			usage
37628b
			;;
37628b
	esac
37628b
done
37628b
37628b
if [ $indiv_opts = false ] && [ $combined_opts = false ]; then
37628b
	indiv_opts=true
37628b
	combined_opts=true
37628b
fi
37628b
37628b
if [ -f "$flannel_env" ]; then
37628b
	source $flannel_env
37628b
fi
37628b
37628b
if [ -n "$FLANNEL_SUBNET" ]; then
37628b
	DOCKER_OPT_BIP="--bip=$FLANNEL_SUBNET"
37628b
fi
37628b
37628b
if [ -n "$FLANNEL_MTU" ]; then
37628b
	DOCKER_OPT_MTU="--mtu=$FLANNEL_MTU"
37628b
fi
37628b
37628b
if [ "$FLANNEL_IPMASQ" = true ] && [ $ipmasq = true ] ; then
37628b
	DOCKER_OPT_IPMASQ="--ip-masq=false"
37628b
fi
37628b
37628b
eval docker_opts="\$${combined_opts_key}"
37628b
docker_opts+=" "
37628b
37628b
echo -n "" >$docker_env
37628b
for opt in $(compgen -v DOCKER_OPT_); do
37628b
	eval val=\$$opt
37628b
37628b
	if [ "$indiv_opts" = true ]; then
37628b
		echo "$opt=\"$val\"" >>$docker_env
37628b
	fi
37628b
37628b
	docker_opts+="$val "
37628b
done
37628b
37628b
if [ "$combined_opts" = true ]; then
37628b
	echo "${combined_opts_key}=\"${docker_opts}\"" >>$docker_env
37628b
fi