Files
linuxkit/alpine/packages/mobyconfig/usr/bin/mobyconfig
Justin Cormack f3a8e77c99 Split config database setup by platform
Add basic database setup for AWS, GCP although these are not yet used
by the setup code but will be useful later.

Currently each is gated by `mobyplatform` but this can be removed once we
construct Moby per platform, and once these are containerised so they
are not run from `openrc`.

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
2017-01-23 18:08:26 +00:00

81 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
if [ $# -ne 2 ]
then
printf "usage: $0 [get|set|wait|exists|path|dir|find] key\n"
exit 0
fi
BASE=/Database
KEY=$(echo $2 | sed 's@^/@@')
if [ $1 == "exists" ]
then
[ -d ${BASE}/${KEY} ] && exit 0
[ -f ${BASE}/${KEY} ] || exit 1
VALUE="$(cat ${BASE}/${KEY} | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
[ -z "${VALUE}" ] && exit 1
exit 0
fi
if [ $1 == "dir" ]
then
[ -d ${BASE}/${KEY} ] && exit 0 || exit 1
fi
if [ $1 == "get" ]
then
if [ -f ${BASE}/${KEY} ]
then
cat ${BASE}/${KEY}
exit 0
else
printf "No such key: ${KEY}\n" 1>&2
exit 1
fi
fi
if [ $1 == "set" ]
then
mkdir -p $(dirname "${BASE}/${KEY}")
cat - > ${BASE}/${KEY}
exit 0
fi
if [ $1 == "wait" ]
then
while [ ! -s ${BASE}/${KEY} ]
do
sleep 1
done
exit 0
fi
if [ $1 == "path" ]
then
if [ -e ${BASE}/${KEY} ]
then
printf ${BASE}/${KEY}
exit 0
else
printf "No such key: ${KEY}\n" 1>&2
exit 1
fi
fi
if [ $1 == "find" ]
then
if [ -e ${BASE}/${KEY} ]
then
find ${BASE}/${KEY} -type f | sed "s@^${BASE}@@g"
exit 0
else
printf "No such key: ${KEY}\n" 1>&2
exit 1
fi
fi
printf "usage: $0 [get|set|wait|exists|path|dir|find] key\n"
exit 1