Guest User

Untitled

a guest
Nov 18th, 2025
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.34 KB | None | 0 0
  1. #!/bin/bash
  2. #SBATCH --cpus-per-task=4
  3. #SBATCH --mem=8G
  4. #SBATCH --time=12:00:00
  5. #SBATCH --job-name="cryosparc"
  6.  
  7. # Clean up old session sockets
  8. rm $(find /tmp -maxdepth 1 -name "cryosparc-supervisor-*" -user $(whoami))
  9.  
  10. set -x
  11.  
  12. if [ ! -d ~/.local/usr/opt/cryosparc ]; then
  13.     PORT=$(shuf -i 1-1000 -n 1)
  14.     PORT=$((PORT + 61000))
  15.     mkdir -p ~/.local/usr/opt/cryosparc/
  16.     mkdir -p ~/.local/db/cryosparc
  17.     LICENSE_ID=$(cat ~/cs-license)
  18.  
  19.     # Download CryoSPARC
  20.     mkdir -p ~/.tmp/cryosparc-download
  21.     cd ~/.tmp/cryosparc-download
  22.     if [ ! -f ./cryosparc_master.tar.gz ]; then
  23.         curl -L https://get.cryosparc.com/download/master-latest/$LICENSE_ID -o ./cryosparc_master.tar.gz
  24.     fi
  25.     if [ ! -f ./cryosparc_worker.tar.gz ]; then
  26.         curl -L https://get.cryosparc.com/download/worker-latest/$LICENSE_ID -o ./cryosparc_worker.tar.gz
  27.     fi
  28.  
  29.     if [ ! -d ~/.local/usr/opt/cryosparc/cryosparc_master ]; then
  30.         tar -xvf ./cryosparc_master.tar.gz -C ~/.local/usr/opt/cryosparc/
  31.     fi
  32.     if [ ! -d ~/.local/usr/opt/cryosparc/cryosparc_worker ]; then
  33.         tar -xvf ./cryosparc_worker.tar.gz -C ~/.local/usr/opt/cryosparc/
  34.     fi
  35.  
  36.     # Install master
  37.     cd ~/.local/usr/opt/cryosparc/cryosparc_master
  38.     mkdir -p ~/.local/db/cryosparc
  39.     ./install.sh --license $LICENSE_ID \
  40.         --hostname cryosparc.discworld.analytical.unsw.edu.au \
  41.         --dbpath ${HOME}/.local/db/cryosparc \
  42.         --port $PORT
  43.  
  44.     mkdir -p ~/.config/cryosparc
  45.     CRYOSPARC_PASSWORD=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 48; echo)
  46.     # Will break with last names like "Bowes Lyon"
  47.     FIRST_NAME=$(getent passwd $(whoami) | cut -d':' -f5 | cut -d' ' -f1)
  48.     LAST_NAME=$(getent passwd $(whoami) | cut -d':' -f5 | cut -d' ' -f2)
  49.     CRYOSPARC_USERNAME=$(whoami)
  50.     CRYOSPARC_EMAIL="$(whoami)@ad.unsw.edu.au"
  51.     CRYOSPARC_PORT="${PORT}"
  52.  
  53.     cat > ~/.config/cryosparc/creds << EOF
  54. CRYOSPARC_USERNAME=$(whoami)
  55. CRYOSPARC_EMAIL=$(whoami)@ad.unsw.edu.au
  56. CRYOSPARC_PASSWORD=${CRYOSPARC_PASSWORD}
  57. FIRST_NAME=${FIRST_NAME}
  58. LAST_NAME=${LAST_NAME}
  59. CRYOSPARC_PORT=${PORT}
  60. EOF
  61.     cd ~/.local/usr/opt/cryosparc/cryosparc_master
  62.     source ~/.config/cryosparc/creds
  63.     ./bin/cryosparcm start
  64.     ./bin/cryosparcm stop
  65.     echo "CRYOSPARC_FORCE_HOSTNAME=true" >> ./config.sh
  66.     sed -i '/CRYOSPARC_DB_CONNECTION_TIMEOUT_MS/c\export CRYOSPARC_DB_CONNECTION_TIMEOUT_MS=20000000' ./config.sh
  67.     sed -i '/CRYOSPARC_MASTER_HOSTNAME/c\export CRYOSPARC_MASTER_HOSTNAME=localhost' ./config.sh
  68.     ./bin/cryosparcm start
  69.     ./bin/cryosparcm createuser --email ${CRYOSPARC_EMAIL} \
  70.         --password ${CRYOSPARC_PASSWORD} \
  71.         --username ${CRYOSPARC_USERNAME} \
  72.         --firstname ${FIRST_NAME} \
  73.         --lastname ${LAST_NAME}
  74. fi
  75.  
  76. source ~/.config/cryosparc/creds
  77.  
  78. $_HOST=$(hostname --long)
  79. cd ~/.local/usr/opt/cryosparc/cryosparc_master
  80. sed -i '/CRYOSPARC_DB_CONNECTION_TIMEOUT_MS/c\export CRYOSPARC_DB_CONNECTION_TIMEOUT_MS=200000' ./config.sh
  81. sed -i '/CRYOSPARC_MASTER_HOSTNAME/c\export CRYOSPARC_MASTER_HOSTNAME=${_HOST}' ./config.sh
  82. ./bin/cryosparcm start
  83.  
  84. # Authenticate and get the cookie to skip CryoSPARC login portal
  85. PASSWORD_HASH=$(echo -n ${CRYOSPARC_PASSWORD} | sha256sum | cut -d' ' -f1)
  86. curl -X POST http://localhost:${CRYOSPARC_PORT}/api/auth/login -H "Content-Type: application/json" -d "{\"email\": \"${CRYOSPARC_EMAIL}\", \"password\": \"${PASSWORD_HASH}\"}" -c cookies.txt
  87. COOKIE_NAME=$(cat cookies.txt | tail -n 1 | cut -d' ' -f6)
  88. COOKIE_VALUE=$(cat cookies.txt | tail -n 1 | cut -d'    ' -f7)
Advertisement
Add Comment
Please, Sign In to add comment