-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathset-user-group-home
73 lines (68 loc) · 2.48 KB
/
set-user-group-home
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/sh
# The goal of this script is to allow mapping of host user (the one running
# docker), to the desired container user, as to enable the use of more
# restrictive file permission (700 or 600)
# does a group with name = EGROUP already exist ?
EXISTING_GID=$( getent group $EGROUP | cut -f3 -d ':' )
if [ ! -z $EXISTING_GID ]; then
if [ $EXISTING_GID != $EGID ]; then
# change id of the existing group
groupmod -g $EGID $EGROUP
fi
else
# create new group with id = EGID
addgroup -g $EGID $EGROUP
fi
# does a user with name = EUSER already exist ?
EXISTING_UID=$( getent passwd $EUSER | cut -f3 -d ':' )
if [ ! -z $EXISTING_UID ]; then
if [ $EXISTING_UID != $EUID ]; then
if [ ! -z $EHOME ]; then
if [ $ENOLOGIN = "yes" ]; then
# update existing user, set shell = nologin, id = EUID,
# group = EGROUP, and home directory = EHOME
usermod -s /sbin/nologin -u $EUID -g $EGROUP -d $EHOME $EUSER
else
# update existing user, set shell = sh, id = EUID, group = EGROUP,
# and home directory = EHOME
usermod -s /bin/sh -u $EUID -g $EGROUP -d $EHOME $EUSER
fi
else
if [ $ENOLOGIN = "yes" ]; then
# update existing user, set shell = nologin, id = EUID
# and group = EGROUP
usermod -s /sbin/nologin -u $EUID -g $EGROUP $EUSER
else
# update existing user, set shell = sh, id = EUID
# and group = EGROUP
usermod -s /bin/sh -u $EUID -g $EGROUP $EUSER
fi
fi
fi
else
if [ ! -z $EHOME ]; then
if [ $ENOLOGIN = "yes" ]; then
# create new user with nologin shell, id = EUID, group = EGROUP
# and home directory = EHOME
adduser -s /sbin/nologin -u $EUID -G $EGROUP -h $EHOME -D $EUSER
else
# create new user with sh shell, id = EUID, group = EGROUP
# and home directory = EHOME,
adduser -s /bin/sh -u $EUID -G $EGROUP -h $EHOME -D $EUSER
fi
else
if [ $ENOLOGIN = "yes" ]; then
# create new user with nologin shell, id = EUID and group = EGROUP
adduser -s /sbin/nologin -u $EUID -G $EGROUP -D $EUSER
else
# create new user with sh shell, id = EUID and group = EGROUP
adduser -s /bin/sh -u $EUID -G $EGROUP -D $EUSER
fi
fi
fi
if [ ! -z $EHOME ]; then
if [ $ECHOWNHOME = "yes" ]; then
# change ownership of home directory
chown $EUSER:$EGROUP $EHOME
fi
fi