Unverified Commit 8a82c80b by Serge Hallyn Committed by GitHub

Merge pull request #2016 from flx42/lxc-oci-misc-improvements

lxc-oci misc improvements
parents 6d75f4cb a787c332
......@@ -121,6 +121,40 @@ getenv() {
return
}
# FIXME 1: only support numerical values in the configuration file.
# FIXME 2: from the OCI image spec: "If group/gid is not specified,
# the default group and supplementary groups of the given user/uid in
# /etc/passwd from the container are applied."
getuidgid() {
if [ "$#" -eq 0 ]; then
echo "0 0"
return
fi
configpath="$1"
uidgid=`cat "${configpath}" | jq -c -r '.config.User // "0:0"'`
uidgid=(${uidgid//:/ })
printf '%d %d' ${uidgid[0]:-0} ${uidgid[1]:-0} 2>/dev/null || true
return
}
# get cwd from oci image.
getcwd() {
if [ "$#" -eq 0 ]; then
echo "/"
return
fi
configpath="$1"
cwd=`cat "${configpath}" | jq -c -r '.config.WorkingDir // "/"'`
echo "${cwd}"
return
}
usage() {
cat <<EOF
LXC container template for OCI images
......@@ -289,8 +323,20 @@ EOF
cat <<EOF > ${LXC_ROOTFS}/etc/hosts
127.0.0.1 localhost
127.0.1.1 ${LXC_NAME}
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
uidgid=($(getuidgid ${OCI_CONF_FILE}))
echo "lxc.init.uid = ${uidgid[0]}" >> "${LXC_CONF_FILE}"
echo "lxc.init.gid = ${uidgid[1]}" >> "${LXC_CONF_FILE}"
cwd=$(getcwd ${OCI_CONF_FILE})
echo "lxc.init.cwd = ${cwd}" >> "${LXC_CONF_FILE}"
if [ -n "$LXC_MAPPED_UID" ] && [ "$LXC_MAPPED_UID" != "-1" ]; then
chown $LXC_MAPPED_UID $LXC_PATH/config $LXC_PATH/fstab >/dev/null 2>&1 || true
fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment