User:Kutschke/Draft Shells

From Mu2eWiki
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.

When you first get a Mu2e computing account, we recommend that you copy two example files, .bash_login and .bashrc, to your home directory. First, check to see if you have already have existing versions of these files:

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

In the above, type everything to the right of "> " at the command prompt. The lines without a leading "> " are example ouput. 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

Next, copy in the recommended files:

> 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.

~/.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.

~/.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 creates the base Mu2e computing environment in your current shell.
  • It sources /etc/bashrc which is needed to make available some Fermilab provided software.
  • It enables two strongly recommended safety features, noclobber and ignoreeof. 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 create one experiment-specific environment. If you mix experiment-specific or project-specific environments, you will often get an inconsistent software configuration.


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. If they are not required by another project that you work on, we recommend you delete them.

Verify that Your Login Scripts Work Correctly

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

> mu2einit
> type muse
 muse is a function
 muse () 
 { 
     source ${MUSE_DIR}/bin/muse
 }
 

If you see the example output, the your login scripts are working correctly.

Pro Tip: you only need to type mu2ei followed by a tab and the command will auto-complete.

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
upsfile="/cvmfs/fermilab.opensciencegrid.org/products/common/etc/setups.sh"
if [  -r "${upsfile}" ]; then
    . "${upsfile}"
fi
unset upsfile

These are obsolete and should be removed.

Expert Only

If you choose that your login scripts will not define mu2einit, then everywhere that the Mu2e instructions tell you to

> setup mu2e

you should instead:

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

Retirement of UPS

During the spring of 2024 Mu2e will retire our use of UPS and will replace it with Spack. To update your login scripts to prepare for this change, follow the instructions at #Setup scripts. Once you have done this, you will need to change setup mu2e to mu2einit everywhere that you normally type it. Be sure to check your scripts as well.

Early in the transition mu2einit will continue to use UPS as did setup mu2e but as the transition proceeds the use of UPS will be phased out in the background. Follow announcements on the Mu2e slack channel "computing-and-software" to keep up to date with developments.