Browse code

bash_profile (heron) - v2.0 - Behavior improved & updates

Improvements of PATH setup, start_agent calling and ssh multikey management, screen behavior

Fred authored on12/06/2016 23:29:13
Showing1 changed files
... ...
@@ -1,18 +1,19 @@
1 1
 # Title: .bash_profile
2 2
 # Author: Frédéric CHEVALIER <f15.chevalier@gmail.com>
3
-# Version: 1.10
3
+# Version: 2.0
4 4
 # Created in: 2012-05-25
5
-# Modified in: 2015-08-17
5
+# Modified in: 2016-06-12
6 6
 
7 7
 
8 8
 #==========#
9 9
 # Versions #
10 10
 #==========#
11 11
 
12
+# v2.0 - 2016-06-12: PATH setup improved / start_agent with multikey management / start_agent calling improved / screen behaviour added / welcome message improved / alias updated
12 13
 # v1.10 - 2015-08-17: Python lib adapted to the current version of Python / Consed env variable added / plocate updated to handle several db / pypm alias added / library path updated
13 14
 # v1.9 - 2015-04-20: Python env variable added / alias updated
14 15
 # v1.8 - 2014-12-02: proxy-display added (resolve $DISPLAY problem with screen)
15
-# v1.7 - 2014-10-22: alias added / conditional modification of PATH and Ld_LIBRARY_PATH to be able to use eog and evince on other server (crow, ...)
16
+# v1.7 - 2014-10-22: alias added / conditional modification of PATH and LD_LIBRARY_PATH to be able to use eog and evince on other server (crow, ...)
16 17
 # v1.6 - 2014-10-15: alias added / LC* added / LS_COLORS removed / PATH updated / LD_LIBRARY_PATH updated
17 18
 # v1.5 - 2014-09-30: improve screen session detection to print welcome message at server connection even if screen session is running elsewhere
18 19
 # v1.4 - 2014-08-14: adapt behavior of the start screen regarding the screen program
... ...
@@ -45,11 +46,11 @@ alias pqrsh='qrsh -V -cwd -pty y bash -li'
45 46
 alias plocate='locate -d "$mlocate_db"'
46 47
 alias xterm='xterm -bg black -fg white -rightbar -geometry 200x35'
47 48
 
48
-alias medusa='ssh -Y medusa'
49
-alias medusa2='ssh -Y medusa2'
50
-alias mendel='ssh -Y mendel'
51
-alias crow='ssh -Y crow'
52
-alias bulmer='ssh -Y bulmer'
49
+alias medusa='ssh medusa'
50
+alias medusa2='ssh medusa2'
51
+alias mendel='ssh mendel'
52
+alias crow='ssh crow'
53
+alias bulmer='ssh bulmer'
53 54
 
54 55
 alias pypm="pypm -g"    # Default parameter for pypm which is a package manager for python
55 56
 alias model_script_sh='cp $HOME/Templates/script.sh $1'
... ...
@@ -78,9 +79,25 @@ LC_ALL=
78 79
 #-------#
79 80
 
80 81
 # Path variable
81
-export PATH=:$HOME/local/bin:$HOME/local/share:$HOME/local/usr/local/bin:$PATH     # Personal path
82
+export PATH=$HOME/local/bin:$HOME/local/share:$HOME/local/usr/local/bin:$PATH     # Personal path
82 83
 
83
-# Perl variables
84
+# Use of personal /lib* if recent OS
85
+if [[ $HOSTNAME != heron* && $(lsb_release -r | cut -f 2) > 6.4 ]]
86
+then
87
+    # Location of bamtools lib (source: http://www.vcru.wisc.edu/simonlab/bioinformatics/programs/install/bamtools.htm)
88
+    export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$HOME/local/lib:$HOME/local/lib64"
89
+fi
90
+
91
+# Special paths for medusa and nodes
92
+if [[ $HOSTNAME =~ medusa* || $HOSTNAME =~ compute.* ]]
93
+then
94
+    # System path
95
+    export PATH=$PATH:/opt/openmpi/bin:/opt/bio/ncbi/bin:/opt/bio/mpiblast/bin:/opt/bio/hmmer/bin:/opt/bio/EMBOSS/bin:/opt/bio/clustalw/bin:/opt/bio/tcoffee/bin:/opt/bio/phylip/exe:/opt/bio/mrbayes:/opt/bio/fasta:/opt/bio/glimmer/bin:/opt/bio/glimmer/scripts:/opt/bio/gromacs/bin:/opt/bio/gmap/bin:/opt/bio/tigr/bin:/opt/bio/autodocksuite/bin:/opt/bio/wgs/bin:/opt/eclipse:/opt/ganglia/bin:/opt/ganglia/sbin:/opt/rocks/bin:/opt/rocks/sbin:/opt/condor/bin:/opt/condor/sbin:/opt/gridengine/bin/lx26-amd64:/usr/bin:/usr/local/bin:/bin:/usr/java/latest/bin
96
+    # Grid Engine path
97
+    export PATH=$PATH:/opt/gridengine/bin/linux-x64
98
+fi
99
+
100
+# Perl
84 101
 export PERL5LIB=~/local/lib/perl5/site_perl/5.18.2/x86_64-linux/auto:~/local/lib/perl5/5.18.2:~/local/lib/perl5/site_perl:~/local/lib/perl5/site_perl/5.18.2:~/local/lib/perl5/site_perl/5.18.2/x86_64-linux:~/local/lib/perl5/5.18.2/x86_64-linux:/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi:/usr/lib/perl5/site_perl/5.8.8:/usr/lib/perl5/site_perl:/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi:/usr/lib/perl5/vendor_perl/5.8.8:/usr/lib/perl5/vendor_perl:/usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi:/usr/lib/perl5/5.8.8
85 102
 
86 103
 # Python
... ...
@@ -89,18 +106,6 @@ export PYTHONPATH=$HOME/local/lib/python${python_version}/site-packages
89 106
 export PYTHONIOENCODING=utf-8
90 107
 unset python_version
91 108
 
92
-# Special paths for medusa and nodes
93
-if [[ $HOSTNAME =~ medusa* || $HOSTNAME =~ compute.* ]]
94
-then
95
-    # Path variable
96
-    export PATH=$HOME/local/bin:$HOME/local/share:$HOME/local/usr/local/bin     # Personal path
97
-    export PATH=$PATH:/opt/openmpi/bin:/opt/bio/ncbi/bin:/opt/bio/mpiblast/bin:/opt/bio/hmmer/bin:/opt/bio/EMBOSS/bin:/opt/bio/clustalw/bin:/opt/bio/tcoffee/bin:/opt/bio/phylip/exe:/opt/bio/mrbayes:/opt/bio/fasta:/opt/bio/glimmer/bin:/opt/bio/glimmer/scripts:/opt/bio/gromacs/bin:/opt/bio/gmap/bin:/opt/bio/tigr/bin:/opt/bio/autodocksuite/bin:/opt/bio/wgs/bin:/opt/eclipse:/opt/ganglia/bin:/opt/ganglia/sbin:/opt/rocks/bin:/opt/rocks/sbin:/opt/condor/bin:/opt/condor/sbin:/opt/gridengine/bin/lx26-amd64:/usr/bin:/usr/local/bin:/bin:/usr/java/latest/bin # System path
98
-    export PATH=$PATH:/opt/gridengine/bin/linux-x64 # System path needed for the new medusa
99
-
100
-    # Location of bamtools lib (source: http://www.vcru.wisc.edu/simonlab/bioinformatics/programs/install/bamtools.htm)
101
-    export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$HOME/local/lib:$HOME/local/lib64" # Otherwise pb with heron  #:$LD_LIBRARY_PATH"
102
-fi
103
-
104 109
 
105 110
 #----------#
106 111
 # Programs #
... ...
@@ -127,18 +132,27 @@ fi
127 132
 export R_LIBS="${R_LIBS_HOME}/${R_version}"
128 133
 
129 134
 # SSH environment setup
135
+SSH_KEY_LIST="$HOME/.ssh/key_list"  # File with full path of keys (one per line) to load with start_agent
136
+[[ -f "$SSH_KEY_LIST" ]] && SSH_KEYS=($(cat $SSH_KEY_LIST))
137
+lifetime=259200 # seconds => 3 days
138
+
130 139
 if [[ ! $HOSTNAME =~ compute.* ]]
131 140
 then
132 141
     if [[ -n "$SSH_CONNECTION" ]]
133 142
     then
134 143
         # Source SSH settings, if applicable
144
+        # Loading keys
135 145
         if [[ -f "${SSH_ENV}" ]]
136 146
         then
137
-            source "${SSH_ENV}" > /dev/null
138
-            #ps ${SSH_AGENT_PID} doesn't work under cywgin
139
-            ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || start_agent
140
-        else    
141
-            start_agent
147
+            source "$SSH_ENV"
148
+            # Check if the ssh key is still stored
149
+            if [[ $(ssh-add -l &> /dev/null; echo $?) != 0 ]]
150
+            then
151
+                pkill -u $USER ssh-agent
152
+                eval start_agent -t $lifetime ${SSH_KEYS[@]}
153
+            fi
154
+        else
155
+            eval start_agent -t $lifetime ${SSH_KEYS[@]}
142 156
         fi
143 157
     fi
144 158
 fi
... ...
@@ -150,6 +164,34 @@ then
150 164
     proxy-display :99
151 165
 fi
152 166
 
167
+# Improvement of screen usage (prevent screen session withing screen session)
168
+if [[ -n $STY || -f /tmp/${USER}_sty.lock ]]
169
+then
170
+    # Create a screen lock with level of screen
171
+    if [[ -f /tmp/${USER}_sty.lock ]]
172
+    then
173
+        export LC_STY=$(($(cat /tmp/${USER}_sty.lock) + 1))
174
+    else
175
+        export LC_STY=1
176
+    fi
177
+
178
+    # ssh function to change the behaviour of ssh
179
+    function ssh {
180
+        /usr/bin/ssh $@ "echo $LC_STY > /tmp/${USER}_sty.lock" &&
181
+        /usr/bin/ssh -t $@ "cd \"$PWD\" && exec $SHELL -l"
182
+    }
183
+
184
+    # Alias updated
185
+    for i in $(alias | grep "screen" | cut -d " " -f 2 | cut -d "=" -f 1)
186
+    do
187
+        eval "alias $i=\"echo You are already running in a screen session.\""
188
+    done
189
+
190
+    [[ $LC_STY -gt 1 ]] && function screen { echo -e "This would start a within screen session. This is not recommanded. But if you need it, call $(which screen)." ; }
191
+
192
+    [[ -f /tmp/${USER}_sty.lock ]] && rm /tmp/${USER}_sty.lock
193
+fi
194
+
153 195
 
154 196
 
155 197
 #=================#
... ...
@@ -159,17 +201,29 @@ fi
159 201
 name=${HOSTNAME%%.*}
160 202
 nb=$(printf "%${#name}s\n" "" | sed "s/ /=/g")
161 203
 
162
-if [[ ! $HOSTNAME =~ compute.* &&  -z $STY ]]
204
+# Server message
205
+if [[ ! $HOSTNAME =~ compute.* && -z $STY && -z $LC_STY ]]
163 206
 then
164 207
     nb=$nb=======
165 208
     echo -e "\n\n"
166 209
     cat .welcome.msg | sed "s/HOSTNAME/$(echo $name Server | sed "s/^[m,h]/\U&/")/" | sed "s/=\*/$nb/g"
167
-    echo -e "\n\n"
168
-
210
+    echo -e "\n"
211
+fi
169 212
 
170
-    if [[ $(echo $name) == "medusa" || $(echo $name) == "medusa2" ]]
213
+# Info on disk space and cores
214
+if [[ $name != "heron" && (-z $LC_STY || $LC_STY != 1) ]]
215
+then
216
+    mydisk="/master /data"
217
+    echo ""
218
+    for i in $mydisk
219
+    do
220
+        [[ ! $(df -h 2> /dev/null | grep "$i ") ]] && continue
221
+        echo -e "\033[33mSpace available on $i [%/Total/free]:\033[00m $(df -h 2> /dev/null | grep "$i " | awk '{print $5" / "$2" / "$4}')"
222
+    done
223
+    echo ""
224
+
225
+    if [[ ($name == "medusa" || $name == "medusa2") && (-z $LC_STY || $LC_STY != 1) ]]
171 226
     then
172
-        echo -e "\033[33mSpace available on /master [%/Total/free]:\033[00m $(df -h | grep "/master " | awk '{print $5" / "$2" / "$4}')\n"
173 227
         echo -e "\033[33mCores available:\033[00m\n"
174 228
         qstat -g c
175 229
         echo -e "\n"