Skip to content

Commit fbb6e69

Browse files
authored
Merge pull request #4 from StatFunGen/refactor
refactor
2 parents c8ec7d6 + 1ebdd5a commit fbb6e69

7 files changed

Lines changed: 965 additions & 1065 deletions

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
# mmcloud
1+
# mmcloud
2+
3+
Please find our tips using MemVerge with AWS cloud on the following pages:
4+
5+
- https://wanggroup.org/productivity_tips/memverge-aws

src/bind_mount.sh

Lines changed: 79 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,103 @@
11
#!/bin/bash
22
username=$(whoami)
3-
cd /home/$username
3+
cd "/home/${username}"
44

55
link_paths() {
6-
efs_path=$1
7-
local_path=$2
8-
paths=$3
9-
10-
# Do not symlink if paths is none (only for oem_packages)
11-
if [[ ${paths} != "none" ]]; then
12-
ln -s ${efs_path}/.pixi ${local_path}/.pixi
13-
ln -s ${efs_path}/micromamba ${local_path}/micromamba
6+
efs_path=$1
7+
local_path=$2
148

159
# To link .bashrc and .profile, need to remove the original (not for oem_packages)
16-
rm ${local_path}/.bashrc ${local_path}/.profile
17-
ln -s ${efs_path}/.bashrc ${local_path}/.bashrc
18-
ln -s ${efs_path}/.profile ${local_path}/.profile
19-
fi
10+
rm "${local_path}/.bashrc" "${local_path}/.profile"
11+
ln -s "${efs_path}/.bashrc" "${local_path}/.bashrc"
12+
ln -s "${efs_path}/.profile" "${local_path}/.profile"
2013

21-
# If we are mountng "full" paths, link all of the directories with config files
22-
# This is for mount_packages and oem_mount_packages
23-
if [[ ${paths} == "full" ]]; then
24-
# We probably don't need this first line any more - need to check
25-
echo 'default_channels = ["dnachun", "conda-forge", "bioconda"]' > ${local_path}/.pixi/config.toml
26-
ln -s ${efs_path}/.config ${local_path}/.config
27-
ln -s ${efs_path}/.cache ${local_path}/.cache
28-
ln -s ${efs_path}/.conda ${local_path}/.conda
29-
ln -s ${efs_path}/.condarc ${local_path}/.condarc
30-
ln -s ${efs_path}/.ipython ${local_path}/.ipython
31-
ln -s ${efs_path}/.jupyter ${local_path}/.jupyter
32-
ln -s ${efs_path}/.mamba ${local_path}/.mamba
33-
ln -s ${efs_path}/.local ${local_path}/.local
34-
ln -s ${efs_path}/.mambarc ${local_path}/.mambarc
35-
ln -s ${efs_path}/ghq ${local_path}/ghq
36-
fi
14+
# conda config files
15+
ln -s "${efs_path}/.condarc" "${local_path}/.condarc"
16+
ln -s "${efs_path}/.mambarc" "${local_path}/.mambarc"
17+
18+
# jupyter config files
19+
ln -s "${efs_path}/.jupyter" "${local_path}/.jupyter"
20+
21+
# code-server config files
22+
mkdir -p "${local_path}/.local/share"
23+
ln -s "${efs_path}/.local/share/code-server" "${local_path}/.local/share/code-server"
24+
25+
# other config files
26+
ln -s "${efs_path}/.config" "${local_path}/.config"
3727

38-
# After installing pixi, it adds the local dir to the PATH through the .bashrc
39-
# Because we do not want multiple $HOME to front of PATH
40-
# We need to make a new .bashrc every time.
41-
echo -e "Making new .bashrc...\n"
42-
tee ${efs_path}/.bashrc << EOF
28+
# Only link these directories when not in oem_packages mode
29+
if [[ ${MODE} != "oem_packages" ]]; then
30+
# Software folders
31+
ln -s "${efs_path}/.pixi" "${local_path}/.pixi"
32+
ln -s "${efs_path}/micromamba" "${local_path}/micromamba"
33+
34+
# Ipython folder
35+
ln -s "${efs_path}/.ipython" "${local_path}/.ipython"
36+
37+
# Cache
38+
ln -s "${efs_path}/.cache" "${local_path}/.cache"
39+
40+
# After installing pixi, it adds the local dir to the PATH through the .bashrc
41+
# Because we do not want multiple $HOME to front of PATH
42+
# We need to make a new .bashrc and .profile every time.
43+
echo -e "Making new .bashrc...\n"
44+
tee "${efs_path}/.bashrc" << EOF
4345
source \$HOME/.set_paths
4446
unset PYTHONPATH
45-
export PYDEVD_DISABLE_FILE_VALIDATION=1
4647
EOF
48+
echo -e "Making new .profile...\n"
49+
tee "${efs_path}/.profile" << EOF
50+
# if running bash
51+
if [ -n "\$BASH_VERSION" ]; then
52+
# include .bashrc if it exists
53+
if [ -f "\$HOME/.bashrc" ]; then
54+
. "\$HOME/.bashrc"
55+
fi
56+
fi
57+
EOF
58+
fi
59+
60+
if [[ ${MODE} != "oem_packages" ]]; then
61+
# Git repositories
62+
ln -s "${efs_path}/ghq" "${local_path}/ghq"
63+
fi
64+
65+
# ln -s ${efs_path}/.mamba ${local_path}/.mamba
66+
# ln -s ${efs_path}/.conda ${local_path}/.conda
67+
4768
}
4869

4970
set_paths() {
50-
efs_path=$1
51-
mode=$2
52-
53-
# Create a PATH script - does not need to be saved in EFS
54-
# (new every time for easy editing)
55-
if [[ ${mode} == "mount_packages" ]]; then
56-
# mount_packages will not use shared packages, so no need to add /mnt/efs/shared/.pixi/bin to PATH
57-
tee ${HOME}/.set_paths << EOF
58-
export PATH="\${HOME}/.pixi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
59-
EOF
60-
else
61-
# For all other modes, to avoid potential conflicts between user installed packages in their home folder (whether it's saved to EFS or not)
62-
# We set the HOME path before the shared path
63-
tee ${HOME}/.set_paths << EOF
64-
export PATH="\${HOME}/.pixi/bin:/mnt/efs/shared/.pixi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
71+
efs_path=$1
72+
73+
# Create a PATH script - does not need to be saved in EFS
74+
# (new every time for easy editing)
75+
tee "${HOME}/.set_paths" << EOF
76+
export PATH="${efs_path}/.pixi/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
6577
EOF
66-
fi
67-
# --- This section is mainly for updating the .bashrc ---
68-
# --- When previous versions used /opt/shared instead of /mnt/efs/shared ---
69-
# Update bashrc to remove /opt/shared and replace with /mnt/efs/shared
70-
if grep -Fxq 'export PATH="/opt/shared/.pixi/bin:${PATH}"' ~/.bashrc; then
71-
echo "/opt/shared exists in .bashrc. Updating the path..."
72-
sed -i 's|/opt/shared|/mnt/efs/shared|g' ~/.bashrc
73-
echo "Path updated to use /mnt/efs/shared."
74-
fi
75-
# ---------------------------------------------------------------------------
7678

77-
source $efs_path/.bashrc
78-
echo "PATH: $PATH"
79+
source "${efs_path}/.bashrc"
80+
echo "PATH: ${PATH}"
7981
}
8082

8183
# Link necessary dirs and files
8284
# The efs_path, or first parameter in link_paths and set_paths, is the location of their .bashrc
83-
if [[ ${MODE} == "shared_admin" ]]; then
84-
# For updating shared packages
85-
link_paths /mnt/efs/shared /home/${username} full
86-
set_paths /mnt/efs/shared shared_admin
87-
elif [[ ${MODE} == "oem_packages" ]]; then
88-
# Can access shared packages but NOT user packages. Can install packages locally
89-
link_paths /mnt/efs/shared /home/${username} none
90-
set_paths /mnt/efs/shared oem_packages
85+
if [[ ${MODE} == "oem_admin" ]] || [[ ${MODE} == "oem_packages" ]]; then
86+
# For updating shared packages
87+
link_paths /mnt/efs/shared "/home/${username}"
88+
set_paths /mnt/efs/shared
9189
elif [[ ${MODE} == "mount_packages" ]]; then
92-
# Can NOT access shared packages, but can see user packages. Can install user packages on EFS
93-
link_paths /mnt/efs/${FLOAT_USER} /home/${username} full
94-
set_paths /mnt/efs/${FLOAT_USER} mount_packages
95-
elif [[ ${MODE} == "oem_mount_packages" ]]; then
96-
# Can access shared and user packages in the EFS. Can install user packages on EFS
97-
link_paths /mnt/efs/${FLOAT_USER} /home/${username} full
98-
set_paths /mnt/efs/${FLOAT_USER} oem_mount_packages
90+
# Can NOT access shared packages, but can see user packages. Can install user packages on EFS
91+
link_paths "/mnt/efs/${FLOAT_USER}" "/home/${username}"
92+
set_paths "/mnt/efs/${FLOAT_USER}"
9993
else
100-
echo -e "ERROR: invalid mode specified - must be one of oem_admin, shared_admin or user"
101-
exit 1
102-
fi
103-
104-
# Update channel config file if it does not exist already
105-
if [ ! -d "${HOME}/.pixi" ] && [ ! -f "${HOME}/.pixi/config.toml" ]; then
106-
mkdir -p ${HOME}/.pixi && echo 'default_channels = ["dnachun", "conda-forge", "bioconda"]' > ${HOME}/.pixi/config.toml
94+
echo -e "ERROR: invalid mode specified - must be one of oem_admin, oem_packages or mount_packages"
95+
exit 1
10796
fi
10897

109-
# init.sh run after it is updated
110-
curl -O https://raw.githubusercontent.com/gaow/misc/refs/heads/master/bash/pixi/init.sh
111-
chmod +x init.sh
112-
./init.sh
113-
11498
# Run entrypoint if given
115-
if [[ ! -z "$ENTRYPOINT" ]]; then
116-
curl -fsSL ${ENTRYPOINT} | bash
99+
if [[ -n "$ENTRYPOINT" ]]; then
100+
curl -fsSL "${ENTRYPOINT}" | bash
117101
else
118102
# Else run original VMUI check
119103
is_available() {
@@ -135,10 +119,13 @@ else
135119

136120
# Check the value of VMUI and start the corresponding UI
137121
case "${VMUI}" in
122+
batch )
123+
echo "Running batch job, no IDE will be started" ;;
138124
jupyter|jupyter-lab)
139125
if is_available jupyter-lab; then
140126
echo "[$(date)]: JupyterLab is available. Starting JupyterLab ..."
141127
while true; do
128+
export JUPYTER_CONFIG_DIR=$HOME/.jupyter
142129
jupyter-lab
143130
# Check if jupyter-lab exited with a non-zero exit code
144131
if [ $? -ne 0 ]; then
@@ -187,5 +174,4 @@ else
187174
start_terminal_server
188175
;;
189176
esac
190-
191-
fi
177+
fi

0 commit comments

Comments
 (0)