-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint
executable file
·56 lines (44 loc) · 1.05 KB
/
entrypoint
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
#!/bin/sh
set -e
createUser()
{
USER=$1
if ! id $USER > /dev/null 2>&1; then
adduser -D $USER
passwd -u $USER > /dev/null 2>&1
fi
mkdir -p /home/$USER/.ssh
chmod 700 /home/$USER/.ssh
chown $USER:$USER /home/$USER/.ssh
}
writeAuthorizedKeys()
{
USER=$1
AUTHORIZED_KEYS=$2
echo "$AUTHORIZED_KEYS" > /home/$USER/.ssh/authorized_keys
chown $USER:$USER /home/$USER/.ssh/authorized_keys
}
readEnvironment()
{
for KEY in $(env | grep '^AUTHORIZED_KEYS_' | awk -F '\n' '{ print substr($0, 0, index($0, "=") - 1) }');
do
USER=$(echo $KEY | awk '{ gsub("AUTHORIZED_KEYS_", "", $1); print tolower($1) }')
AUTHORIZED_KEYS=$(eval "echo \"\$$KEY\"")
createUser $USER
writeAuthorizedKeys $USER "$AUTHORIZED_KEYS"
done
}
readFile()
{
for KEY in /authorized_keys_*;
do
[ -e $KEY ] || break
USER=$(echo $KEY | awk '{ gsub("/authorized_keys_", "", $1); print tolower($1) }')
AUTHORIZED_KEYS=$(cat $KEY)
createUser $USER
writeAuthorizedKeys $USER "$AUTHORIZED_KEYS"
done
}
readFile
readEnvironment
exec "$@"