Page MenuHomec4science

create_user.sh
No OneTemporary

File Metadata

Created
Tue, Apr 16, 08:44

create_user.sh

#!/bin/bash
set -euo pipefail
# Script made from the page
# https://docs.ycrc.yale.edu/clusters-at-yale/guides/cryosparc/
script_path=$(dirname "$0") # relative
script_path=$(cd "${script_path}" && pwd) # absolutized and normalized
install_path="$HOME"/cryosparc
# Usage
usage () {
echo "Usage:"
echo " -p install path : prefix for installation [${install_path}] "
echo " -v : be verbose"
echo " -h : print this notice"
echo ""
}
VERBOSE=false
def_user_name=$(whoami)
read -p "Enter user name for the account [${def_user_name}]: " user_name
user_name=${user_name:-${def_user_name}}
def_mail=$(ldapsearch -x -LLL -h scoldap.epfl.ch -b "o=epfl,c=ch" uid=${user_name} mail | grep mail | awk '{ print $2 }')
def_firstname=$(ldapsearch -x -LLL -h scoldap.epfl.ch -b "o=epfl,c=ch" uid=${user_name} givenName | grep givenName | awk '{ print $2 }')
def_lastname=$(ldapsearch -x -LLL -h scoldap.epfl.ch -b "o=epfl,c=ch" uid=${user_name} sn | grep sn | awk '{ print $2 }')
read -p "Enter your first name [${def_firstname}]: " firstname
firstname=${firstname:-${def_firstname}}
read -p "Enter your last name [${def_lastname}]: " lastname
lastname=${lastname:-${def_lastname}}
read -p "Enter your email address [$def_mail]: " mail
mail=${mail:-${def_mail}}
read -p "Enter password for the account: " password
# Parse options
while getopts ":p:vh" opt; do
case $opt in
p)
install_path="${OPTARG}"
;;
v)
VERBOSE=true
;;
h)
usage
OPTIND=1
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
OPTIND=1
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
usage
OPTIND=1
exit 1
;;
esac
done
# Reset OPTIND to allow the next invocation to work
OPTIND=1
message() {
if $VERBOSE
then
echo "${1}"
fi
}
echo "[Info] Starting the master if needed"
if [ $(${script_path}/cryosparcm.sh status | grep -c "CryoSPARC is not running") -eq 1 ]; then
${script_path}/cryosparcm.sh start
fi
if [ "x$password" != "x" ]; then
${script_path}/cryosparcm.sh createuser --email "${mail}" --firstname "${firstname}" --lastname "${lastname}" --username "${user_name}" --password "${password}"
fi

Event Timeline