Commit a2ade420 by Jungsub Shin

oci-template: Add logic for no /etc/passwd, group

OCI image spec dosen't specify action when there is no /etc/passwd or /etc/group. So if there is no /etc/passwd with string user info, set uid to 0. If there is no /etc/group with string group info, set gid to 0. Signed-off-by: Jungsub Shin jungsub_shin@tmax.co.kr
parent b8cfbbd1
...@@ -151,17 +151,27 @@ getuidgid() { ...@@ -151,17 +151,27 @@ getuidgid() {
usergroup=(${usergroup//:/ }) usergroup=(${usergroup//:/ })
user=${usergroup[0]:-0} user=${usergroup[0]:-0}
if ! isdecimal "${user}" && [ -f ${passwdpath} ]; then if ! isdecimal "${user}"; then
user=$(grep "^${user}:" "${passwdpath}" | awk -F: '{print $3}') if [ -f ${passwdpath} ]; then
else user=$(grep "^${user}:" "${passwdpath}" | awk -F: '{print $3}')
user=0 else
user=0
fi
fi fi
group=${usergroup[1]:-} group=${usergroup[1]:-}
if [ -z "${group}" ] && [ -f "${passwdpath}" ]; then if [ -z "${group}" ]; then
group=$(grep "^[^:]*:[^:]*:${user}:" "${passwdpath}" | awk -F: '{print $4}') if [ -f "${passwdpath}" ]; then
elif ! isdecimal "${group}" && [ -f "${grouppath}" ]; then group=$(grep "^[^:]*:[^:]*:${user}:" "${passwdpath}" | awk -F: '{print $4}')
group=$(grep "^${group}:" "${grouppath}" | awk -F: '{print $3}') else
group=0
fi
elif ! isdecimal "${group}"; then
if [ -f "${grouppath}" ]; then
group=$(grep "^${group}:" "${grouppath}" | awk -F: '{print $3}')
else
group=0
fi
fi fi
echo "${user:-0} ${group:-0}" echo "${user:-0} ${group:-0}"
......
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