Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #SBATCH --cpus-per-task=4
- #SBATCH --mem=8G
- #SBATCH --time=12:00:00
- #SBATCH --job-name="cryosparc"
- # Clean up old session sockets
- rm $(find /tmp -maxdepth 1 -name "cryosparc-supervisor-*" -user $(whoami))
- set -x
- if [ ! -d ~/.local/usr/opt/cryosparc ]; then
- PORT=$(shuf -i 1-1000 -n 1)
- PORT=$((PORT + 61000))
- mkdir -p ~/.local/usr/opt/cryosparc/
- mkdir -p ~/.local/db/cryosparc
- LICENSE_ID=$(cat ~/cs-license)
- # Download CryoSPARC
- mkdir -p ~/.tmp/cryosparc-download
- cd ~/.tmp/cryosparc-download
- if [ ! -f ./cryosparc_master.tar.gz ]; then
- curl -L https://get.cryosparc.com/download/master-latest/$LICENSE_ID -o ./cryosparc_master.tar.gz
- fi
- if [ ! -f ./cryosparc_worker.tar.gz ]; then
- curl -L https://get.cryosparc.com/download/worker-latest/$LICENSE_ID -o ./cryosparc_worker.tar.gz
- fi
- if [ ! -d ~/.local/usr/opt/cryosparc/cryosparc_master ]; then
- tar -xvf ./cryosparc_master.tar.gz -C ~/.local/usr/opt/cryosparc/
- fi
- if [ ! -d ~/.local/usr/opt/cryosparc/cryosparc_worker ]; then
- tar -xvf ./cryosparc_worker.tar.gz -C ~/.local/usr/opt/cryosparc/
- fi
- # Install master
- cd ~/.local/usr/opt/cryosparc/cryosparc_master
- mkdir -p ~/.local/db/cryosparc
- ./install.sh --license $LICENSE_ID \
- --hostname cryosparc.discworld.analytical.unsw.edu.au \
- --dbpath ${HOME}/.local/db/cryosparc \
- --port $PORT
- mkdir -p ~/.config/cryosparc
- CRYOSPARC_PASSWORD=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 48; echo)
- # Will break with last names like "Bowes Lyon"
- FIRST_NAME=$(getent passwd $(whoami) | cut -d':' -f5 | cut -d' ' -f1)
- LAST_NAME=$(getent passwd $(whoami) | cut -d':' -f5 | cut -d' ' -f2)
- CRYOSPARC_USERNAME=$(whoami)
- CRYOSPARC_EMAIL="$(whoami)@ad.unsw.edu.au"
- CRYOSPARC_PORT="${PORT}"
- cat > ~/.config/cryosparc/creds << EOF
- CRYOSPARC_USERNAME=$(whoami)
- CRYOSPARC_EMAIL=$(whoami)@ad.unsw.edu.au
- CRYOSPARC_PASSWORD=${CRYOSPARC_PASSWORD}
- FIRST_NAME=${FIRST_NAME}
- LAST_NAME=${LAST_NAME}
- CRYOSPARC_PORT=${PORT}
- EOF
- cd ~/.local/usr/opt/cryosparc/cryosparc_master
- source ~/.config/cryosparc/creds
- ./bin/cryosparcm start
- ./bin/cryosparcm stop
- echo "CRYOSPARC_FORCE_HOSTNAME=true" >> ./config.sh
- sed -i '/CRYOSPARC_DB_CONNECTION_TIMEOUT_MS/c\export CRYOSPARC_DB_CONNECTION_TIMEOUT_MS=20000000' ./config.sh
- sed -i '/CRYOSPARC_MASTER_HOSTNAME/c\export CRYOSPARC_MASTER_HOSTNAME=localhost' ./config.sh
- ./bin/cryosparcm start
- ./bin/cryosparcm createuser --email ${CRYOSPARC_EMAIL} \
- --password ${CRYOSPARC_PASSWORD} \
- --username ${CRYOSPARC_USERNAME} \
- --firstname ${FIRST_NAME} \
- --lastname ${LAST_NAME}
- fi
- source ~/.config/cryosparc/creds
- $_HOST=$(hostname --long)
- cd ~/.local/usr/opt/cryosparc/cryosparc_master
- sed -i '/CRYOSPARC_DB_CONNECTION_TIMEOUT_MS/c\export CRYOSPARC_DB_CONNECTION_TIMEOUT_MS=200000' ./config.sh
- sed -i '/CRYOSPARC_MASTER_HOSTNAME/c\export CRYOSPARC_MASTER_HOSTNAME=${_HOST}' ./config.sh
- ./bin/cryosparcm start
- # Authenticate and get the cookie to skip CryoSPARC login portal
- PASSWORD_HASH=$(echo -n ${CRYOSPARC_PASSWORD} | sha256sum | cut -d' ' -f1)
- 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
- COOKIE_NAME=$(cat cookies.txt | tail -n 1 | cut -d' ' -f6)
- COOKIE_VALUE=$(cat cookies.txt | tail -n 1 | cut -d' ' -f7)
Advertisement
Add Comment
Please, Sign In to add comment