-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart-shell
executable file
·76 lines (57 loc) · 1.65 KB
/
start-shell
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
################################################################################
# prepare and start the interactive shell environment
################################################################################
# change to project directory
cd /src
# source doshie rc
DOSHIE_PROJECT_NAME=doshie
if [[ -f .doshie.rc ]]; then
. .doshie.rc
fi
# resolve user
doshie_user=doshie_$DOSHIE_UID
if [[ "$doshie_user" == "doshie_0" ]]; then
doshie_user=root
fi
# set environment vars
cat <<! >/etc/profile.d/doshie.sh
export PS1="$DOSHIE_PROJECT_NAME> "
cd /src
export PATH="/src/.doshie/bin:$PATH"
export DOSHIE_USER=$doshie_user
!
if [[ ! -z "$DOSHIE_CMD_PATH" ]]; then
cat <<! >>/etc/profile.d/doshie.sh
export PATH="\$( readlink -f $DOSHIE_CMD_PATH ):\$PATH"
!
fi
chmod +x /etc/profile.d/doshie.sh
. /etc/profile.d/doshie.sh
cat .doshie/logo >&2
update
# create group to match host group
doshie_group="$( cat /etc/group | awk -F: '$3 == '$DOSHIE_GID' { print $1 }' )"
if [[ -z "$doshie_group" ]]; then
echo "creating group doshie_grp_$DOSHIE_GID" >&2
groupadd -g $DOSHIE_UID doshie_grp_$DOSHIE_GID
fi
# create user to match host user
if ! id -u "$DOSHIE_UID" >/dev/null 2>&1; then
echo "creating user doshie_$DOSHIE_UID" >&2
useradd -u $DOSHIE_UID -g $DOSHIE_GID doshie_$DOSHIE_UID
echo "doshie_$DOSHIE_UID ALL = NOPASSWD: ALL" >> /etc/sudoers
sed -i '/secure_path/d' /etc/sudoers
fi
# mark the system as ready
touch .doshie/.ready
if [[ "$DOSHIE_UID" == "0" ]]; then
doshie_user=root
fi
# start the interactive shell
if [[ -z "$DOSHIE_CMD" ]]; then
su - $doshie_user
else
# ..or run the command
su - $doshie_user -c "$DOSHIE_CMD"
fi