Files
linuxkit/alpine/packages/mobyconfig/usr/bin/mobyconfig
Justin Cormack 114a6971e0 Always have database at /Database
Use a bind mount for OSX and Windows for 9p filesystem.

This makes it easier to use a different database source,
and to share database into system containers.

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
2017-01-19 14:34:29 +00:00

90 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
if [ $# -ne 2 ]
then
printf "usage: $0 [get|exists|path|dir|find] key\n"
exit 0
fi
if [ $1 == "set" ]
then
printf "Configuration is immutable\n" 1>&2
exit 1
fi
if [ ! -d /Database ]
then
mkdir -p /Database
case "$(mobyplatform)" in
windows)
mkdir -p /tmp/db
/sbin/9pmount-vsock listen db /tmp/db
[ $? -ne 0 ] && rm -rf /Database && printf "Could not mount configuration database\n" 1>&2 && exit 1
mount --bind /tmp/db/branch/master/ro/com.docker.driver.amd64-linux /Database
;;
mac)
mkdir -p /tmp/db
mount -t 9p -o trans=virtio,dfltuid=1001,dfltgid=50,version=9p2000 db /tmp/db
[ $? -ne 0 ] && rm -rf /Database && printf "Could not mount configuration database\n" 1>&2 && exit 1
mount --bind /tmp/db/branch/master/ro/com.docker.driver.amd64-linux /Database
;;
esac
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 == "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|exists|path|dir|find] key\n"
exit 1