-
Notifications
You must be signed in to change notification settings - Fork 32
/
entrypoint.sh
53 lines (42 loc) · 1.61 KB
/
entrypoint.sh
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
#!/bin/bash
# -*- mode: shell-script; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
#
# Copyright (C) 2019 coldnew
# Authored-by: Yen-Chin, Lee <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# first check if environment variable be set or not
if [ -z "${USER}" ]; then
echo "ERROR: We need USER to be set!"; exit 100
fi
if [ -z "${HOST_UID}" ]; then
echo "ERROR: We need HOST_UID be set" ; exit 100
fi
if [ -z "${HOST_GID}" ]; then
echo "ERROR: We need HOST_GID be set" ; exit 100
fi
# reset user_?id to either new id or if empty old (still one of above
# might not be set)
USER_UID=${HOST_UID:=$UID}
USER_GID=${HOST_GID:=$GID}
# Create Group
groupadd ${USER} --gid ${USER_GID} > /dev/null 2>&1
# Create user
useradd ${USER} --shell /bin/bash --create-home \
--uid ${USER_UID} --gid ${USER_GID} > /dev/null 2>&1
echo 'ALL ALL = (ALL) NOPASSWD: ALL' >> /etc/sudoers
chown -R ${USER_UID}:${USER_GID} /home/${USER} > /dev/null 2>&1
# switch to current user
su "${USER}"
# enter to shell
exec /bin/bash