User:Kutschke

From Mu2eWiki
Revision as of 19:16, 29 April 2024 by Kutschke (talk | contribs) (Created page with "Mu2e uses the '''bash''' linux shell exclusively for the interactive command line and shell scripting. In general, this is the most powerful shell and the professional's choi...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Mu2e uses the bash linux shell exclusively for the interactive command line and shell scripting. In general, this is the most powerful shell and the professional's choice.

Setup scripts

These are also known as login scripts.

If you are a bash expert and want to roll your own, read this section and make your own decisions. See also #Expert Only, below. If you are not a bash expert, follow the steps described here. We also suggest that you familiarize your self with the information in the section #How Bash Startup Scripts Run.

When you first get a Mu2e computing account, we recommend that you copy two example files, .bash_login and .bashrc, to your home directory. The funcationality provided by these scripts is described below.

First, check to see if you have already have existing versions of these files:

> cd ~
> ls .bash_profile .bashrc
.bash_profile .bashrc

If you have these files, make backup copies because the next steps will overwrite them:

> cd ~
> mv .bash_profile .bash_profile.sav  # only if needed
> mv .bashrc .bashrc.sav              # only if needed
> curl -O https://github.com/kutschke/Bootstrap/blob/retireUPS/dotFiles/.bash_profile
> curl -O https://github.com/kutschke/Bootstrap/blob/retireUPS/dotFiles/.bashrc

In the above, the option argument to curl is a capital letter O, not the numeral zero. You can also click on the links to look at the files before your download them.

Here are some comments about each of these files.

  • Example ~/.bash_profile
    • This file is executed by the system at the start of each login shell.
    • If ~/.bashrc file exists, it sources ~/.bashrc. This ensures that a login shell has all of the functionality of a non-login shell. For all Mu2e computing work this is what you want.
    • If you wish to supply your own customizations to ~/.bash_profile we suggest that you create a file named ~/.my_bash_profile and add your content to that file. The example .bash_profile looks for ~/.my_bash_profile and, if it exists, sources it. We recommend this so that you keep your customizations separate from the recommended basic .bash_profile. This will simplify future evolution of the recommended base .bash_profile.
    • If you had a previously existing .bash_profile, read the section #Obsolete setup patterns and then merge the still-useful content of your old .bash_profile into .my_bash_profile. Be careful not to needlessly duplicate content already present in your new .bash_profile.
  • Example ~/.bashrc
    • It defines the environment variable BASH_ENV to ensure that subshells have the same configuration as non-login shells.
    • It defines the alias, mu2einit. When you run the command mu2einit, it create the Mu2e computing environment in your current shell.
    • It sources /etc/bashrc which is needed to make some Fermilab provided software available in your shell.
    • It enables two strongly recommended safety features. This also serves as an example of how to configure your environment differently for interactive and non-interactive shells.
    • As for .bash_profile, we recommend that you put personal configuration in .my_bashrc.
    • If you had a previously existing .bashrc, read the section #Obsolete setup patterns and then merge the still-useful content of your old .bashrc into .my_bashrc. Be careful not to needlessly duplicate content in your new .bashrc.
    • .my_bashrc is the file in which to put things like setting your prompt, defining aliases etc

We strongly recommend that you not run mu2einit in your login scripts. This is particularly important if you work on more than one Fermilab experiment. Experience has shown that you should keep your login scripts generic and define aliases, or functions, like mu2einit that you can

We strongly recommend you not setup UPS packages (other than UPS itself) in your login scripts. Experience has shown that this will sometimes interfere with the correct operation of Mu2e software. In particular, if your login scripts source login/setup scripts from other experiments you should remove them from your login scripts. The recommended pattern is to keep your login scripts free of experiment specific code and to maintain separate per-experiment scripts that you source by hand after logging in; you should only source one of these scripts in any given shell.


Other notes:

  1. The Fermilab maintained systems execute /etc/profile.d/*.sh for login shells and /etc/bashrc for non-login shells. This may be different on other machines.
  2. We recommend that you not use ~/.login, ~/.profile, ~/.shrc or ~/.cshrc . There is no reason for them to be present in a Mu2e environment.

Verify that Your Login Scripts Work Correctly

To verify that the login scripts have correctly setup UPS, logout and log in again. Then do:

> printenv PRODUCTS
/cvmfs/fermilab.opensciencegrid.org/products/common/db
> type setup
setup is a function
setup () 
{ 
    . `/cvmfs/mu2e.opensciencegrid.org/artexternals/ups/v6_1_1/Linux64bit+3.10-2.17/bin/ups setup "$@"`
}
> ups active
Active ups products:
ups               v6_0_7          -f Linux64bit+3.10-2.17                    -z /cvmfs/fermilab.opensciencegrid.org/products/common/db

If everything matches, modulo version numbers, it worked correctly.

Obsolete setup patterns

It is common to find that you have inherited an old .bash_profile with setup patterns like these

pa=/grid/fermiapp/products/common/etc 
if [  -r "$pa/setups.sh" ]
then
  . "$pa/setups.sh"
  if ups exist login
  then
      setup login
  fi
fi
if [  -f "/afs/fnal.gov/ups/etc/setups.sh" ]
then 
    . "/afs/fnal.gov/ups/etc/setups.sh"
    if ups exist login
    then
        setup login
    fi
fi

These are obsolete and should be updated as described above.

Expert Only

If you choose that your login scripts will not setup UPS as described above, you will need to remember to do the following: everywhere that the Mu2e instructions tell you to

> setup mu2e

you should instead:

> source /cvmfs/mu2e.opensciencegrid.org/setupmu2e-art.sh