-
Notifications
You must be signed in to change notification settings - Fork 10
/
INCL-USER-ENV.sh
executable file
·59 lines (49 loc) · 2.09 KB
/
INCL-USER-ENV.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
#!/bin/bash
################################################################################
# Install the SSH deploy key of the GitLab repository.
mkdir -p ~/.ssh/
chmod 700 ~/.ssh/
cp ./.ssh/o2as-id_rsa ~/.ssh/
chmod 600 ~/.ssh/o2as-id_rsa
if grep -E -q '^Host gitlab\.com' ~/.ssh/config; then
echo "SSH configuration for 'gitlab.com' is already included in '~/.ssh/config'."
echo "Manually add 'IdentityFile ~/.ssh/o2as-id_rsa' under 'gitlab.com' if the connection is refused."
else
echo "Add new SSH configuration for 'gitlab.com' in '~/.ssh/config'.";
cat <<'EOF' >> ~/.ssh/config;
Host gitlab.com
Hostname gitlab.com
IdentityFile ~/.ssh/o2as-id_rsa
StrictHostKeyChecking no
User git
EOF
fi
################################################################################
# Modify the HTTPS URL of the Git remote origin to use SSH:
# Enable authentication by using '~/.ssh/o2as-id_rsa' instead of a GitLab account.
GIT_HTTPS_URL=`git config --get remote.origin.url`
GIT_SSH_URL=`echo ${GIT_HTTPS_URL} | sed -e 's/^https\{0,1\}:/ssh:/'`
if [ "${GIT_HTTPS_URL}" != "${GIT_SSH_URL}" ]; then
echo "Update the Git remote origin from '${GIT_HTTPS_URL}' to '${GIT_SSH_URL}'."
echo "Execute 'git config --get remote.origin.url' to manually confirm if needed."
git remote set-url origin ${GIT_SSH_URL}
fi
################################################################################
# Download and initialize all the Git submodules recursively.
# https://git-scm.com/book/en/v2/Git-Tools-Submodules
git submodule update --init --recursive
################################################################################
# Setup the Bash shell environment with '.bashrc'.
# Set default Docker runtime to use in './docker/docker-compose.yml'.
if ! grep -q "export DOCKER_RUNTIME" ~/.bashrc; then
if [ -e /proc/driver/nvidia/version ]; then
DOCKER_RUNTIME=nvidia
else
DOCKER_RUNTIME=runc
fi
cat <<EOF >> ~/.bashrc
# Set default Docker runtime to use in '~/ur-o2as/docker/docker-compose.yml':
# 'runc' (Docker default) or 'nvidia' (Nvidia Docker 2).
export DOCKER_RUNTIME=${DOCKER_RUNTIME}
EOF
fi