blob: 53ed1a5baf94a6bc710e6df2677e5deda19a5805 (
plain) (
blame)
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
|
#!/bin/ash -- sourced
# Required vars from context:
# USER_UID
# USER_GID
# USER_NAME
# 1) Sanitize the user's home directory, stored and updated in USER_HOME
# 2) Write entry to /etc/passwd if it doesn't exist
# Fixup local home path
if [ -z "$USER_HOME" ] || [ "${USER_HOME:0:1}" = '\' ] || [ "${USER_HOME:1:1}" = ':' ]; then
USER_HOME="/home/_temp-home/$USER_NAME"
else
# Make sure it's absolute, replace spaces, '\' and ':' by '_'
USER_HOME=$(echo "$USER_HOME" | sed -r 's,^(/*)(.*)$,/\2,;s/(:|\s|\\)+/_/g')
fi
readonly USER_HOME
# Add/replace passwd entry if it doesn't exist yet
LINE_PASS="${USER_NAME}:x:${USER_UID}:${USER_GID}:${USER_NAME}@SLX:${USER_HOME}:/bin/bash"
readonly LINE_PASS
if ! grep -Fxq -- "${LINE_PASS}" /etc/passwd; then
# Make sure there's no existing line with same uid or uidNumber
sed -i -r "/^${USER_NAME}:/d;/^[^:]*:x:${USER_UID}:/d" /etc/passwd
echo "${LINE_PASS}" >> /etc/passwd
fi
|