.. highlight:: shell

.. _gbasf2-setup:

Setup Gbasf2
************

Currently, EL9 Linux flavors (like Alma Linux 9 or RHEL9) are supported as OS platforms to use gbasf2.
It may also work on EL8 flavors, but gbasf2 releases are not validated on them.
One should avoid using CentOS Linux 7 which reached end of life (EOL).


Before starting, please make sure you have fulfilled the :ref:`gbasf2-prerequisites`. Additionally:

* You have cvmfs mounted with the following directories::

    /cvmfs/belle.cern.ch/
    /cvmfs/belle.kek.jp/
    /cvmfs/grid.cern.ch/

* Make sure your grid certificate (both of the files ``usercert.pem`` and ``userkey.pem``) is in the directory ``~/.globus``.
  (See `Install Your Certificate <https://xwiki.desy.de/xwiki/bin/view/BI/Belle%20II%20Internal/Computing%20WebHome/Computing%20GettingStarted/#H2.Installyourcertificate>`_
  on XWiki.)

.. note::

    Be sure that the userkey.pem has the rw permissions only for the owner and no permission for others.
    You should see ``"-rw-------"`` with ``ls -l ~/.globus/userkey.pem``

    If not, you should do the following::

        chmod 600 ~/.globus/userkey.pem



Pre-installed gbasf2 on CVMFS
=============================

To use the preinstalled gbasf2 on cvmfs, you just need to source the environment with a single command::

    source /cvmfs/belle.kek.jp/grid/gbasf2/pro/bashrc

It will request your certificate passphrase. If the command finishes without errors and you see information related
to your certificate, your proxy has been successfully set::

    Proxy generated:
    subject      : /C=JP/O=KEK/OU=CRC/CN=USERNAME
    issuer       : /C=JP/O=KEK/OU=CRC/CN=USERNAME
    identity     : /C=JP/O=KEK/OU=CRC/CN=USERNAME
    timeleft     : 23:53:58
    DIRAC group  : belle
    rfc          : True
    path         : /tmp/x100up_u0001
    username     : youruser
    properties   : NormalUser
    VOMS         : True
    VOMS fqan    : ['/belle']

    Succeed with return value:
    0

A proxy is a short-term credential that verifies your identity, allowing you to perform operations on the grid.
By default your proxy is valid for 24h. If it expires, you need to execute ``gb2_proxy_init -g belle`` again if you have
already setup gbasf2 in the same shell (terminal).

See `GBasf2 Troubleshooting <https://xwiki.desy.de/xwiki/bin/view/BI/Belle%20II%20Internal/Computing%20WebHome/DistributedComputing/Computing%20GBasf2/GBasf2%20Troubleshooting/>`_ if you see errors after the setup.


Setup for groups
~~~~~~~~~~~~~~~~

When submitting job as part of a group (like physics or performance groups, etc.), proxy must be initialised specifying the group::

    source /cvmfs/belle.kek.jp/grid/gbasf2/pro/bashrc -g <belle_group>

.. note::

    Jobs with a group may require to specify the output LPN using ``-o``::

       gbasf2 -p <project_name> -o /belle/group/<directory_name>/<project_name> etc..

    Check if any error messages during the submission to confirm.


Additional options
~~~~~~~~~~~~~~~~~~

The setup file ``bashrc`` at CVMFS provide options for specify PEM certificate and key files other than the default::

    -C <value>   : File to use as user certificate
    -K <value>   : File to use as user key



Gbasf2 check release
====================

The gb2_check_release command provides information about your version::

    $ gb2_check_release

    Your installation is up-to-date: 6.1

    Available gbasf2 releases:
    Production: 6.1
    Newer than prod: 
    Older than prod: 6.0.0, 6.0.1

    Available basf2 releases:
    light-2408-savannah
    light-2409-toyger
    light-2411-aldebaran
    light-2501-betelgeuse
    release-09-00-00
    release-08-01-05
    release-06-01-12
    release-06-01-10
    release-06-01-09
    ...

The "Available basf2 releases" are those that are accepted by gbasf2.

.. note::

    Some releases may be obsolete and no longer supported by the software team, or may require a :ref:`resource-tag-label` to run
    in an specific OS. You should check the release locally before submitting to the grid.

If a basf2 release that you need for your analysis is not available on the grid,
you can contact the `users forum <comp-users-forum@belle2.org>`_. The release will be
validated and enabled shortly after.