Skip to content

Commit

Permalink
workaround #1
Browse files Browse the repository at this point in the history
  • Loading branch information
ntorresalberto committed Apr 26, 2024
1 parent 30ab150 commit 487bd29
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
32 changes: 23 additions & 9 deletions assets/createUser.sh.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env bash
set -e

echo "- container image OS:"
grep PRETTY_NAME /etc/os-release

echo "- create groups if necessary..."

{{.createGroups}}
Expand All @@ -10,16 +13,27 @@ echo "- create groups if necessary..."
# echo "-------------------------------"

echo "- creating user..."
existing_user_by_uid=`getent passwd "1000" | cut -f1 -d: || true`
if [ -n "${existing_user_by_uid}" ]; then userdel -r "${existing_user_by_uid}"; fi

existing_user_by_name=`getent passwd "{{.username}}" | cut -f1 -d: || true`
existing_user_uid=`getent passwd "{{.username}}" | cut -f3 -d: || true`
if [ -n "${existing_user_by_name}" ]; then find / -uid ${existing_user_uid} -exec chown -h {{.uid}} {} + || true ; find / -gid ${existing_user_uid} -exec chgrp -h {{.ugid}} {} + || true ; fi
if [ -n "${existing_user_by_name}" ]; then userdel -r "${existing_user_by_name}"; fi
existing_user_by_uid=`getent passwd "{{.uid}}" | cut -f1 -d: || true`
# echo "existing_user_by_uid ({{.uid}}): ${existing_user_by_uid}"
if [ -n "${existing_user_by_uid}" ]; then
echo "WARNING: host uid ({{.uid}}) exists inside container (as ${existing_user_by_uid})," \
&& echo " deleting it to create host user and group ({{.username}})..." \
&& userdel -rf "${existing_user_by_uid}"; fi

# existing_user_by_name=`getent passwd "{{.username}}" | cut -f1 -d: || true`
# existing_user_uid=`getent passwd "{{.username}}" | cut -f3 -d: || true`
# echo "existing_user_by_name:${existing_user_by_name}"
# echo "existing_user_uid:${existing_user_uid}"
# if [ -n "${existing_user_by_name}" ]; then find / -uid ${existing_user_uid} -exec chown -h {{.uid}} {} + || true ; find / -gid ${existing_user_uid} -exec chgrp -h {{.ugid}} {} + || true ; fi
# if [ -n "${existing_user_by_name}" ]; then userdel -rf "${existing_user_by_name}"; fi

existing_group_by_gid=`getent group "{{.ugid}}" | cut -f1 -d: || true`
# echo "existing_group_by_gid:${existing_group_by_gid}"
if [ -z "${existing_group_by_gid}" ]; then
echo "group gid: host user gid ({{.ugid}}) not found inside container," \
&& echo " will create host user group ({{.username}}) inside container..." \
&& groupadd -g "{{.ugid}}" "{{.username}}"; fi

# existing_group_by_gid=`getent group "1000" | cut -f1 -d: || true`
# if [ -z "${existing_group_by_gid}" ]; then groupadd -g "{{.ugid}}" "{{.username}}"; fi

useradd --no-log-init --no-create-home --uid "{{.uid}}" -s "/bin/bash" -c "{{.Name}}" -g "{{.ugid}}" -G "{{.gnames}}" -d "{{.homedir}}" "{{.username}}"

Expand Down
19 changes: 10 additions & 9 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ group_exists=0
echo " . check gid {{.outside_gid}} is valid..."
inside_gid_bygid=$(getent group "{{.outside_gid}}" | cut -f3 -d: || true)
inside_gid_bygname=$(getent group "{{.outside_gname}}" | cut -f3 -d: || true)
# echo " inside_gid_bygid:${inside_gid_bygid}"
# echo " inside_gid_bygname:${inside_gid_bygname}"
# echo " inside_gid_bygid: ${inside_gid_bygid}"
# echo " inside_gid_bygname: ${inside_gid_bygname}"
echo -n " - gid (by gid): "
herewarn=0
Expand All @@ -367,7 +367,7 @@ if [ "${inside_gid_bygid}" ]; then
if [ "${inside_gid_bygid}" != "{{.outside_gid}}" ]; then
echo "WARNING"
echo " -> gid (by gid): exists inside container exists and differs from outside:"
echo " -> inside_gid_bygid:${inside_gid_bygid}, outside container: {{.outside_gid}}"
echo " -> inside_gid_bygid: ${inside_gid_bygid}, outside container: {{.outside_gid}}"
warnings=1
herewarn=1
fi
Expand All @@ -383,7 +383,7 @@ if [ "${inside_gid_bygname}" ]; then
if [ "${inside_gid_bygname}" != "{{.outside_gid}}" ]; then
echo "WARNING"
echo " -> gid (by gname) inside container exists and differs from outside:"
echo " -> inside_gid_bygname:${inside_gid_bygname}, outside container: {{.outside_gid}}"
echo " -> inside_gid_bygname: ${inside_gid_bygname}, outside container: {{.outside_gid}}"
warnings=1
herewarn=1
fi
Expand All @@ -396,8 +396,8 @@ fi
echo " . check group name {{.outside_gname}} is valid..."
inside_gname_bygid=$(getent group "{{.outside_gid}}" | cut -f1 -d: || true)
inside_gname_bygname=$(getent group "{{.outside_gname}}" | cut -f1 -d: || true)
# echo " inside_gname_bygid:${inside_gname_bygid}"
# echo " inside_gname_bygname:${inside_gname_bygname}"
# echo " inside_gname_bygid: ${inside_gname_bygid}"
# echo " inside_gname_bygname: ${inside_gname_bygname}"
echo -n " - groupname (by gid): "
herewarn=0
Expand All @@ -406,7 +406,7 @@ if [ "${inside_gname_bygid}" ]; then
if [ "${inside_gname_bygid}" != "{{.outside_gname}}" ]; then
echo "WARNING"
echo " -> groupname (by gid) exists inside container exists and differs from outside:"
echo " -> inside_gname_bygid:${inside_gname_bygid}, outside container: {{.outside_gname}}"
echo " -> inside_gname_bygid: ${inside_gname_bygid}, outside container: {{.outside_gname}}"
warnings=1
herewarn=1
fi
Expand All @@ -422,7 +422,7 @@ if [ "${inside_gname_bygname}" ]; then
if [ "${inside_gname_bygname}" != "{{.outside_gname}}" ]; then
echo "WARNING"
echo " -> groupname (by gname) exists inside container exists and differs from outside:"
echo " -> inside_gname_bygname:${inside_gname_bygname}, outside container: {{.outside_gname}}"
echo " -> inside_gname_bygname: ${inside_gname_bygname}, outside container: {{.outside_gname}}"
warnings=1
herewarn=1
fi
Expand All @@ -444,7 +444,8 @@ else
echo " ---------------------------------"
echo " Warning: there were some issues with group {{.outside_gname}} ({{.outside_gid}}),"
echo " check log above but very often this does not pose a problem"
echo " (if it does create an issue with the running log output above)."
echo " (if it does create an issue with the running log output)."
echo " https://github.com/ntorresalberto/dogi/issues"
echo " ---------------------------------"
# exit 1
fi
Expand Down

0 comments on commit 487bd29

Please sign in to comment.