forked from SamSpiri/infra-workspace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.sh
executable file
·63 lines (51 loc) · 2.16 KB
/
bootstrap.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
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
set -e
export HOME=/home/$USERNAME
# Create group for docker, respecting the GID of the docker socket
# If group is already in use and it's not docker
CUR_GROUP=$(getent group $GID_DOCKER | cut -f1 -d:)
if getent group $GID_DOCKER >/dev/null && [ "$CUR_GROUP" != "docker" ]; then
# delete user with default group set to $GID_DOCKER
# echo deleting user with default group \'$CUR_GROUP\' from the image
USER_DEL=$(getent passwd | awk -F: '$4 == '$GID_DOCKER' {print $1}')
if [ ! -z "$USER_DEL" ]; then
# echo deleting user \'$USER_DEL\' from the image
userdel $(getent passwd | awk -F: '$4 == '$GID_DOCKER' {print $1}')
fi
if getent group $GID_DOCKER >/dev/null; then
# echo deleting group \'$(getent group $GID_DOCKER | cut -f1 -d:)\' from the image
groupdel $(getent group $GID_DOCKER | cut -f1 -d:)
fi
if getent group docker >/dev/null; then
# echo deleting group docker from the image since it has wrong GID
groupdel docker
fi
# echo adding docker group with GID $GID_DOCKER
groupadd -g $GID_DOCKER docker
fi
groupadd -g $GID $USERNAME
useradd -d $HOME -M -s /bin/zsh -g $GID -u $UID $USERNAME
usermod -aG sudo $USERNAME
usermod -a -G docker $USERNAME
cd "$WORKDIR"
[[ -f "$WORKDIR/one_password_secret.sh" ]] && source "$WORKDIR/one_password_secret.sh" || echo "No one_password_secret.sh found.
File should contain:
'''
export OP_CONNECT_HOST=http://opconnect.aks.dev.bnp.it.opuscapita.com:8080
export OP_CONNECT_TOKEN=<<< find in onepassword: Andariel/bnp-one-password, field: token >>>
'''
one_password_secret.sh should be in the root of the repo: $WORKDIR/one_password_secret.sh
"
[[ ! -f "$HOME/.zshrc" && ! -f "$HOME/.start_zsh" ]] && { exec sudo -Eu $USERNAME /bin/bash; exit $?; }
bootstrap() {
cp -r /opt/zsh/.zshrc /opt/zsh/.p10k.zsh /opt/zsh/.oh-my-zsh "$HOME"/
[[ ! -f "$HOME/.histfile" ]] && cat "$HOME/.bash_history" > "$HOME/.histfile"
}
[[ ! -f "$HOME/.zshrc" ]] \
&& [[ ! -f "$HOME/.p10k.zsh" ]] \
&& [[ ! -d "$HOME/.oh-my-zsh" ]] \
&& {
bootstrap
}
[[ -f "$HOME/.start_zsh" ]] && bootstrap && rm -f "$HOME/.start_zsh"
exec sudo -Eu $USERNAME "PATH=$PATH" /bin/zsh