forked from JAremko/docker-emacs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasEnvUser
executable file
·76 lines (63 loc) · 2.2 KB
/
asEnvUser
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
74
75
76
#!/bin/bash -x
## Create(if needed) this user and run command as the user:
# ENV UNAME="emacser" \
# GNAME="emacs" \
# UHOME="/home/emacs" \
# UID="1000" \
# GID="1000" \
# WORKSPACE="/mnt/workspace" \
# SHELL="/bin/bash"
## NOTE: ^^^^ Those are default values only in docker-emacs
## NOTE: The user will have "no password" sudo privilege
service ssh start
## Create user if it doesn't exists
if ! id "${UNAME}" >/dev/null 2>&1; then
## Prepend the user to /etc/passwd to ensure that it will
## override already existing users with the same IDs
echo -e "${UNAME}:x:${UID}:${GID}:${UNAME},,,:${UHOME}:${SHELL}\n$(cat /etc/passwd)" > /etc/passwd
echo "${UNAME}::17032:0:99999:7:::" >> /etc/shadow
fi
## Make sure that user is sudoer
if [ ! -f "/etc/sudoers.d/${UNAME}" ]; then
echo "${UNAME} ALL=(ALL) NOPASSWD: ALL" > "/etc/sudoers.d/${UNAME}"
chmod 0440 "/etc/sudoers.d/${UNAME}"
fi
## Create user's group if it doesn't exists
u_group=$(egrep -i "^${GNAME}" /etc/group)
if [ $? -ne 0 ]; then
echo "${GNAME}:x:${GID}:${UNAME}" >> /etc/group
elif [[ ${u_group} != *"${UNAME}"* ]]; then
sed -i -e "s/${u_group}/${u_group},${UNAME}/g" /etc/group
fi
## Make sure that the user owns home directory
if [ -d "${UHOME}" ]
then
home_owner="$(stat -c '%U' ${UHOME})"
if ! id "${home_owner}" >/dev/null 2>&1 || [ "$(id -u ${UNAME})" -ne "$(id -u ${home_owner})" ]; then
chown "${UID}":"${GID}" -R ${UHOME}
fi
else
mkdir -p "${UHOME}"
cp /opt/emacs-instalation "${UHOME}/.emacs"
chown -R "${UID}":"${GID}" "${UHOME}"
su-exec "${UNAME}" emacs --daemon
su-exec "${UNAME}" emacsclient -e "(prepare-extensions)"
su-exec "${UNAME}" emacsclient -e "(kill-emacs)"
cp /opt/emacs "${UHOME}/.emacs"
cp -R /opt/lain "${UHOME}/.emacs.d/lain"
chown -R "${UID}":"${GID}" "${UHOME}"
fi
mkdir -p /tmp/org/
chown "${UID}":"${GID}" /tmp/org/
mkdir -p "${WORKSPACE}"
chown "${UID}":"${GID}" "${WORKSPACE}"
cd "${WORKSPACE}"
if [ "x$1" == "xbash" ]; then
exec "$@"
fi
su-exec "${UNAME}" emacs --daemon
EMACS_PID=$(ps -e -o pid,cmd | awk '/emacs --daemon/ && !/grep/{print $1}')
while [ ! -z $EMACS_PID ]; do
sleep 5
EMACS_PID=$(ps -e -o pid,cmd | awk '/emacs --daemon/ && !/grep/{print $1}')
done