source: trunk/debathena/debathena/dotfiles/bashrc @ 25097

Revision 25097, 4.8 KB checked in by jdreed, 13 years ago (diff)
In dotfiles: * Suppress stdout/stderr for sftp sessions (Trac #512)
Line 
1# Global bashrc file
2#
3# $Id: bashrc,v 1.39 2006-07-17 23:14:07 rbasch Exp $
4
5# This file is sourced by default user file ~/.bashrc
6
7initdir=/usr/lib/init
8
9# Determine if we're in an sftp or scp session and if so, be quiet
10SILENT=no
11case "$BASH_EXECUTION_STRING" in
12    /usr/lib/openssh/sftp-server)
13        SILENT=yes
14        ;;
15    scp*)
16        SILENT=yes
17        ;;
18esac
19
20# *******************   ENVIRONMENT SETUP   *******************
21
22# Set up standard system/user environment configuration (including setup of
23# environment variables, attachment of lockers, and setting of search path)
24
25# If we see ENV_SET set to empty, we could be a tcsh user who has
26# decided to run bash, or we could be a bash user suffering from the
27# misfeature that the standard xsession script runs the tcsh dotfiles
28# for all users.  Running the environment setup for the former
29# category of user would be unfriendly (it resets the homedir and
30# changes the path), so for now, only run environment setup for bash
31# users.  If the xsession problem is ever fixed, change this
32# conditional to check for '"${ENV_SET+set}" != set' and eliminate the
33# shell check.
34if [ "${ENV_SET:+set}" != set -a "${SHELL##*/}" = bash ]; then
35
36        export ENV_SET=t                        # Avoid unnecessary repeat
37        export HOSTTYPE="`/bin/machtype`"
38
39        # Ensure user's homedir is attached, for legacy things
40        # that care about attachtab
41        # Only attach if running as an Athena user, not e.g. using sudo.
42        if [ "$DEBATHENA_HOME_TYPE" = afs ]; then
43                /bin/attach -h -q "${ATHENA_USER:-$USER}"
44        fi
45
46        if [ -r "$HOME/.generation" ]; then
47                export ATHENA_DOTFILE_GENERATION=`cat "$HOME/.generation"`
48        else
49                export ATHENA_DOTFILE_GENERATION=0
50        fi
51
52        ulimit -S -c 0                          # Don't allow coredumps
53        export EDITOR=emacs                     # Set default editor
54        export MM_CHARSET=iso-8859-1
55
56        export EMAIL="$USER@mit.edu"            # Set default email address
57
58        export MORE=-s
59
60        export ATHENA_SYS=`/bin/machtype -S`
61        export ATHENA_SYS_COMPAT=`/bin/machtype -C`
62
63        if [ -z "$ATHENA_SYS" ]; then
64                export ATHENA_SYS=@sys
65        fi
66
67        if [ "${PRINTER+set}" != set \
68          -a -e /var/run/athena-clusterinfo.csh ]; then
69                PRINTER=`awk '/LPR/ { print $3 }' \
70                  /var/run/athena-clusterinfo.csh`
71                if [ -n "$PRINTER" ]; then export PRINTER; fi
72        fi
73
74        # Reset the HOME variable to correspond to the actual location
75        # of the user's home directory.  This will avoid having long
76        # pathnames being printed when /mit/<user> is a symlink to a
77        # path within AFS.
78
79        x=`(cd && /bin/pwd) 2>/dev/null`
80        if [ -n "$x" ]; then
81                export HOME=$x
82                if [ "$x" = "`/bin/pwd`" ]; then
83                        cd "$HOME"
84                fi
85        fi
86        unset x
87
88        # Run user environment customizations identified in your
89        # ~/.bash_environment file.  This is the place to include your
90        # own environment variables, attach commands, and other system
91        # wide setup commands.  You can also cancel default behaviors
92        # listed above.
93        # ~/.bash_environment is not sourced if NOCALLS is set (i.e.,
94        # if you selected the xlogin "Ignore your customizations"
95        # option when you logged in).q
96
97        if [ "${NOCALLS+set}" != set -a -r ~/.bash_environment ]; then
98            if [ "$SILENT" = "yes" ]; then
99                exec 6>&1                # Save STDOUT
100                exec 7>&2                # Save STDERR
101                exec > /dev/null 2>&1
102            fi
103            . ~/.bash_environment
104            if [ "$SILENT" = "yes" ]; then
105                exec 1>&6 6>&-           # Restore STDOUT
106                exec 2>&7 7>&-           # Restore STDERR
107            fi
108        fi
109
110        # If the user has a bindir in $HOME, put it in front of the path.
111        athena_home_bin=$( /usr/bin/athdir "$HOME" )
112        PATH=${athena_home_bin:+$athena_home_bin:}$PATH
113        unset athena_home_bin
114
115fi
116
117
118# *******************  BASH SETUP   *******************
119
120# Set up standard bash shell initializations
121
122if [ "${XSESSION+set}" = set ]; then
123        logout () { gnome-session-save --kill --silent; exit; } # logout for X
124fi
125
126#   aliases dealing with adding locker programs
127
128setup_tty () {(export SUBJECT="$@"; $SHELL)}
129setup_X () {(export SUBJECT="$@"; xterm -title "$@" &)}
130
131if [ -n "$XSESSION" ]; then
132   alias setup=setup_X
133else
134   alias setup=setup_tty
135fi
136
137remove () { export SUBJECT="$@";
138            source $initdir/env_remove.bash;
139            unset SUBJECT; }
140
141if [ -n "$SUBJECT" -a -r $initdir/env_setup.bash ]; then
142        source $initdir/env_setup.bash
143fi
144
145
146# All of the bash initializing commands above can be overridden by using
147# "unset" or "unalias" commands (or by changing things using "set" or
148# "alias" again) in your ~/.bashrc.mine file, which is sourced here.
149# ~/.bashsrc.mine is not sourced if the xlogin "Ignore your customizations"
150# option was selected to begin the session.
151
152if [ "${NOCALLS+set}" != set -a -r ~/.bashrc.mine ]; then
153    if [ "$SILENT" = "yes" ]; then
154        exec 6>&1                # Save STDOUT
155        exec 7>&2                # Save STDERR
156        exec > /dev/null 2>&1
157    fi
158    . ~/.bashrc.mine
159    if [ "$SILENT" = "yes" ]; then
160        exec 1>&6 6>&-           # Restore STDOUT
161        exec 2>&7 7>&-           # Restore STDERR
162    fi
163fi
Note: See TracBrowser for help on using the repository browser.