Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
## Login into the docker with proper ID/GID
## just pass -e ID="$(id)" .. and script takes care of rest
## Useful with mounting local filesystem
if [ "x$ID" = "x" ] ; then
echo "ID not passed, you get root shell"
exit 0
fi
## Extract things from this ...
##uid=1001(q) gid=10(wheel) groups=......
regex="uid=([[:digit:]]*)\(([a-z_][a-z0-9_-]*)\) gid=([[:digit:]]*)\(([a-z_][a-z0-9_-]*)\)"
if [[ $ID =~ $regex ]] ; then
UI=${BASH_REMATCH[1]}
UN=${BASH_REMATCH[2]}
GI=${BASH_REMATCH[3]}
GN=${BASH_REMATCH[4]}
getent group $GN || groupadd -g $GI $GN
id $UN || useradd -g $GN -u $UI $UN
echo $UN: | chpasswd
login -f $UN
else
echo bad ID
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.