-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev.sh
executable file
·59 lines (46 loc) · 1.68 KB
/
dev.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
# Check for the --clean argument
for arg in "$@"; do
if [[ "$arg" == "--clean" ]]; then
CLEAN=true
fi
done
# Exit immediately if a command exits with a non-zero status,
# treat unset variables as an error, and prevent errors in a pipeline from being masked
set -euo pipefail
# Set the home directory
export HOME_DIR=${HOME}
# This requires the passwd file to be mapped into the container
# export DEFAULT_USER=${DEFAULT_USER:-$USER}
# Set the default user to 'vscode'
export DEFAULT_USER=vscode
# Set the directory for DDT mounts and create it if it doesn't exist
export DDT_MOUNTS="/n/fdshome/${USER}/.allinea"
mkdir -p $DDT_MOUNTS/
# Check if HOME_MNT is set, if so, use it and set HOME_DIR accordingly
# Otherwise, set HOME_MNT to a default value
if [ -n "${HOME_MNT:-}" ]; then
export HOME_MNT="${HOME_MNT}"
export HOME_DIR=/home/${DEFAULT_USER}
else
export HOME_MNT="/n/fdshome/${USER}"
fi
export GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
export CONTAINER_NAME=${LOGNAME}-ompi-${GIT_BRANCH}
# Get the directory of the current script
workspace_dir=$(dirname $0)
# If CLEAN is set, run the specified command and exit
if [ "${CLEAN:-}" = true ]; then
echo "Cleaning dev container..."
if docker ps -a --format '{{.Names}}' | grep -Eq "^${CONTAINER_NAME}\$"; then
echo "Docker container exists, running cleanup command..."
docker kill ${CONTAINER_NAME}
docker rm ${CONTAINER_NAME}
else
echo "Container does not exist, skipping cleanup."
fi
fi
# Start the devcontainer with the specified workspace folder
devcontainer up --workspace-folder "${workspace_dir}"
# Execute a bash shell in the devcontainer
exec devcontainer exec --workspace-folder "${workspace_dir}" bash -l