11#! /usr/bin/env bash
2+ DEFAULT_UID=10000
3+ DEFAULT_GID=10000
4+
25set -e
36
47if [[ -v DEBUG ]]
@@ -23,10 +26,10 @@ create_user_and_group() {
2326 echo " Please recreate the container with the updated gid" >&2
2427 exit 1
2528 fi
26- echo " Group '$groupname ' already exists with correct GID $gid "
29+ echo " Group '$groupname ' already exists with correct GID $gid " >&2
2730 else
2831 # Group doesn't exist, create it
29- echo " Creating group '$groupname ' with GID $gid "
32+ echo " Creating group '$groupname ' with GID $gid " >&2
3033 groupadd -g " $gid " " $groupname "
3134 fi
3235 fi
@@ -51,14 +54,14 @@ create_user_and_group() {
5154 fi
5255 fi
5356
54- echo " User '$username ' already exists with correct UID $uid "
57+ echo " User '$username ' already exists with correct UID $uid " >&2
5558 else
5659 # User doesn't exist, create it
5760 if [ -n " $gid " ]; then
58- echo " Creating user '$username ' with UID $uid and GID $gid "
61+ echo " Creating user '$username ' with UID $uid and GID $gid " >&2
5962 useradd -M -u " $uid " -g " $gid " " $username "
6063 else
61- echo " Creating user '$username ' with UID $uid "
64+ echo " Creating user '$username ' with UID $uid " >&2
6265 useradd -M -u " $uid " " $username "
6366 fi
6467 fi
8285fi
8386
8487# set up privilege dropping to user and group
85- PRIVDROP=
86- if [ -n " $RUNAS_UID " ]
87- then
88- PRIVDROP=$( create_user_and_group " $RUNAS_UID " " $RUNAS_GID " )
89- echo " Dropping privileges to $( $PRIVDROP id -u) :$( $PRIVDROP id -g) "
90- fi
88+ PRIVDROP=$( create_user_and_group " ${RUNAS_UID:- $DEFAULT_UID } " " ${RUNAS_GID:- $DEFAULT_GID } " )
89+ echo " Dropping privileges to $( $PRIVDROP id -u) :$( $PRIVDROP id -g) "
9190
9291# run custom scripts before dropping privileges
9392echo " Running custom scripts in /container-init as root"
0 commit comments