114 lines
3.0 KiB
Bash
114 lines
3.0 KiB
Bash
#!/bin/bash
|
|
|
|
|
|
function find_my_pgroups(){
|
|
echo "You seem to have access to these pgroups:"
|
|
for d in /sf/*/data/p*/raw; do
|
|
ls $d >/dev/null 2>/dev/null && echo $d
|
|
done | cut -d\/ -f5
|
|
}
|
|
|
|
|
|
if [ "$#" -ne 2 ]; then
|
|
echo "Usage: $0 <pgroup> <human comment>"
|
|
echo "Example: $0 p17123 commisioning_spectrometer"
|
|
echo
|
|
find_my_pgroups
|
|
exit 1
|
|
fi
|
|
|
|
# Change privileges of a newly created files such the whole group (e.g. users in pgroup for an experiment) can write to them
|
|
# Add a line to ~/.bashrc if it doesn't exist already and source the file again
|
|
grep -qxF 'umask 0002' ~/.bashrc || echo 'umask 0002' >> ~/.bashrc
|
|
source ~/.bashrc
|
|
|
|
|
|
pgroup=$1
|
|
comment=$2
|
|
shortcut_folder_path="./pgroup_shortcuts"
|
|
#ppath=${pgroup::3}
|
|
timestamp=$(date "+%Y%m%d-%H%M%S")
|
|
|
|
source=/sf/cristallina/data/$pgroup
|
|
target=$shortcut_folder_path/$pgroup-$comment
|
|
|
|
# If folder pgroup_shortcuts does not exist, crate it
|
|
mkdir -p $shortcut_folder_path
|
|
|
|
if [ -d $target ]; then
|
|
echo "pgroup symlink (\"$target\") exists already."
|
|
echo "Won't create symlink."
|
|
elif [ ! -d $source ]; then
|
|
echo "pgroup folder (\"$source\") does not exist."
|
|
echo "Won't create symlink."
|
|
find_my_pgroups
|
|
else
|
|
echo "Creating symlink to pgroup $pgroup at $target..."
|
|
ln -s $source $target
|
|
fi
|
|
|
|
|
|
#echo
|
|
#pgroup_conda=$source/anaconda
|
|
#if [ -d $pgroup_conda ]; then
|
|
# echo "conda folder in pgroup $pgroup exists already."
|
|
#else
|
|
# echo "No conda installation in pgroup $pgroup yet."
|
|
# echo "Conda install may take some time..."
|
|
# set -e
|
|
|
|
# source /opt/psi/Programming/anaconda/2019.07/conda/etc/profile.d/conda.sh
|
|
# conda activate alvra-analysis
|
|
# conda env export --prefix /sf/alvra/anaconda/alvra-analysis --file packages-$timestamp.yaml
|
|
# time conda env create --prefix $pgroup_conda/alvra-analysis-$pgroup --file packages-$timestamp.yaml
|
|
# rm packages-$timestamp.yaml
|
|
# conda activate $pgroup_conda/alvra-analysis-$pgroup
|
|
# conda install --yes --channel paulscherrerinstitute alvra_tools
|
|
# conda env export --prefix $pgroup_conda/alvra-analysis-$pgroup --file $pgroup_conda/packages-$timestamp.yaml
|
|
# conda deactivate
|
|
|
|
# set +e
|
|
#fi
|
|
|
|
condarc=~/.condarc
|
|
condarc_bak=$condarc-$timestamp
|
|
|
|
if [ -f $condarc ]; then
|
|
cp $condarc $condarc_bak
|
|
fi
|
|
|
|
|
|
echo
|
|
echo "Updating .condarc:"
|
|
# later added means higher priority
|
|
#source /opt/psi/Programming/anaconda/2019.07/conda/etc/profile.d/conda.sh
|
|
#conda config --add envs_dirs /sf/alvra/anaconda
|
|
#conda config --add envs_dirs $pgroup_conda
|
|
#conda config --add channels conda-forge
|
|
#conda config --add channels paulscherrerinstitute
|
|
miniconda=/sf/cristallina/applications/conda/envs/miniconda
|
|
source ${miniconda}/etc/profile.d/conda.sh
|
|
conda config --add envs_dirs /sf/cristallina/applications/conda/envs
|
|
conda activate analysis_edge
|
|
|
|
|
|
# delete backup if identical to updated original
|
|
if [ -f $condarc_bak ]; then
|
|
cmp --silent $condarc $condarc_bak
|
|
if [ $? -eq 0 ]; then
|
|
echo
|
|
echo ".condarc unchanged."
|
|
rm $condarc_bak
|
|
else
|
|
echo
|
|
echo "Created backup: $condarc_bak"
|
|
echo
|
|
echo "Your old .condarc:"
|
|
echo "=================="
|
|
cat $condarc_bak
|
|
fi
|
|
fi
|
|
|
|
|
|
|