rpmbuildlocal: +Workaround recent rpm bug of stale ./BUILDROOT
[nethome.git] / .bashrc
1 # $Id$
2
3
4 if [ -n "$_home_short_dotbashrc_norc" -o "${TERM#norc-}" != "$TERM" ];then
5         # We could get executed twice:
6         export _home_short_dotbashrc_norc=true
7         # Do not use $TZ as Solaris sshd(8) does not propagate it.
8         # Be aware you must use 'ssh -t' to propagate $TERM otherwise '=dumb'.
9         export TERM="${TERM#norc-}"
10         export _home_short_dotbashrc=true
11 fi
12
13 # "$PS1" for interactive shells detection.
14 if [ -n "$PS1" -a -z "$_home_short_dotbashrc" ];then
15         # We permit later reinitialization by unsetting it.
16         # During our execution we forbid spawning to prevent deadlock by:
17         #       source /etc/bashrc
18         #       . /etc/profile.d/lang.sh
19         #       unicode_start iso02.08
20         export _home_short_dotbashrc=true
21         # $TERM gets restored to its 'norc-' state after ~/.bashrc
22         # alias norc='TERM="norc-$TERM" ssh -t -o 'NoHostAuthenticationForLocalhost yes' $USER@localhost "cd $PWD; TERM=$TERM;"'
23         function norc { TERM="norc-$TERM" ssh -t -o 'NoHostAuthenticationForLocalhost yes' $USER@localhost "cd $PWD; TERM=$TERM;" "$@"; }
24
25 # Fix $USER and $LOGNAME (not $MAIL) for /etc/passwd line:
26 # root-lace:x:0:0:root for Jan Kratochvil:/home/root-lace:/bin/bash
27 if [ "$UID" -eq 0 -a "$USER" = "root" -a "$HOME" != "${HOME#*/root-}" ];then
28         USER="${HOME##*/}"
29         LOGNAME="$USER"
30 fi
31
32 if [ -f /etc/bashrc ];then source /etc/bashrc;fi
33
34 _bash_profile_addpath_fini=""
35 function _bash_profile_addpath  # <variablename>,<dirpathname>
36 {
37         local _varname _varval _varvalold _dirpathname _opt_f _opt_s
38         _opt_f=0;_opt_s=0
39         unset -v OPTIND
40         while getopts fs got;do
41                 case "$got" in
42                         [fs]) eval "_opt_$got=1" ;;
43                         *) return 1 ;;
44                         esac
45                 done
46         eval "_varname=\"\$$[$OPTIND+0]\""
47         eval "_dirpathname=\"\$$[$OPTIND+1]\""
48         if [ $_opt_f = 0 -a '!' -d "$_dirpathname" ];then return;fi
49         if [ $_opt_s = 1 -o -z "`eval "echo \\${$_varname}"`" ];then
50                 eval "$_varname='$_dirpathname'"
51         else
52                 # We want to prevent duplicates due to .bashrc reentrancy across fork(2)s. It is array!
53                 _bash_profile_addpath_fini="$_bash_profile_addpath_fini $_varname"
54                 # We want to override any original directories, place dirpathname first!
55                 eval "$_varname=\"$_dirpathname:\${$_varname}\""
56         fi
57         export "$_varname"
58 }
59 function _bash_profile_addpath_fini
60 {
61         local _varname
62         for _varname in `echo "$_bash_profile_addpath_fini"|tr ' ' '\n'|sort -u`;do
63                 eval "$_varname=\"`eval $(echo "echo \"\\$$_varname\"")|awk -v RS=':' '/[^\n]/{if (!x[$0]++) e=e":"$0;}END{print substr(e,2)}'`\""
64                 done
65         unset -v _bash_profile_addpath_fini
66 }
67
68 # Use reverse order of preferred directories:
69 # gid(1) dependency on: /opt/sfw/bin
70 # EUID="`id -u 2>/dev/null || /usr/xpg4/bin/id -u 2>/dev/null || gid -u`"
71 _bash_profile_addpath -f PATH            "/sbin"
72 _bash_profile_addpath -f PATH            "/usr/sbin"
73 [ $EUID -eq 0 ] && _bash_profile_addpath -f PATH "/usr/local/sbin"
74 _bash_profile_addpath -f PATH            "/usr/local/bin"
75 _bash_profile_addpath -f MANPATH         "/usr/X11R6/man"
76 _bash_profile_addpath -f MANPATH         "/usr/share/man"
77 _bash_profile_addpath -f MANPATH         "/usr/local/man"
78 _bash_profile_addpath -s JAVA_HOME       "/usr/java"
79 _bash_profile_addpath -s JAVA_HOME       "/usr/local/java"
80 uname_p="`uname -p 2>/dev/null || uname -m`"
81 for family in $HOME;do
82         for arch in $family $family/$uname_p;do
83                 # Do not "-f": We use /net !
84                 _bash_profile_addpath PATH            "$arch/bin"
85                 _bash_profile_addpath -s JAVA_HOME    "$arch/java"
86                 [ $EUID -eq 0 ] && _bash_profile_addpath PATH "$arch/sbin"
87                 _bash_profile_addpath LD_LIBRARY_PATH "$arch/lib64"
88                 _bash_profile_addpath LD_LIBRARY_PATH "$arch/lib"
89                 _bash_profile_addpath MANPATH         "$arch/man"
90                 done
91         done
92 _bash_profile_addpath -f -s CVSROOT ":pserver:pserver:@cvs.jankratochvil.net/cvs"       # default
93 [ -n "$JAVA_HOME" ] && _bash_profile_addpath PATH "$JAVA_HOME/bin"
94 _bash_profile_addpath    -s CVSROOT "$HOME/pserver/cvs"
95 _bash_profile_addpath    -s CVSROOT "$HOME/cvs"
96 _bash_profile_addpath    -s ANT_HOME "/usr/local/ant"
97
98 # /share/perl for Debian
99 # /lib/perl for Debian
100 # /lib/perl5 for Fedora Core
101 mkdir -p $HOME/lib{64,}/perl5   # otherwise CPAN will install to "$HOME/lib{64,}/site_perl" etc.
102 _perlpatt="$(perl -MConfig -e 'print "{,/".$Config{$_}."}" for qw(version archname);')"
103 for _perldir in $(eval "echo {/usr,$HOME}{/lib{64,}/perl{,5},/share/perl}{,/site_perl}$_perlpatt");do
104         # $PERL5LIB overrides $PERLLIB and it is being used by: /etc/profile.d/atrpms.*
105         _bash_profile_addpath -f PERL5LIB "$_perldir"
106         done
107 unset _perldir
108
109 unset -f _bash_profile_addpath
110 _bash_profile_addpath_fini
111 unset -f _bash_profile_addpath_fini
112
113 # '2>/dev/null' to prevent: unalias: x: not found
114 # It must be run before `function's below as otherwise it would get embedded.
115 unalias 2>/dev/null cp  # -i
116 unalias 2>/dev/null mv  # -i
117 unalias 2>/dev/null rm  # -i
118 unalias 2>/dev/null df  # -h
119 unalias 2>/dev/null du  # -h
120 unalias 2>/dev/null ls  # --color=auto
121 unalias 2>/dev/null l.  # ls -d .* --color=auto
122 unalias 2>/dev/null ll  # ls -l --color=auto
123
124 # Aliases would get processed during the parsing of this script file!
125 eval '
126         function grep {(unset grep; ( ulimitme; grep "$@"; ); );}
127
128         function ls {(unset ls; ( ls -bF "$@"; ); );}
129         function l { ls -lbF "$@"; }
130         if which vim &>/dev/null;then
131                 alias vi="vim"
132         else
133                 echo >&2 "WARNING: No vim(1)."
134         fi
135         function grepb { grep --binary-files=binary "$@"; }
136         function L { lynx "$@"; }
137         function chown {(unset chown; ( chown --no-dereference "$@"; ); );}
138         function chgrp {(unset chgrp; ( chgrp --no-dereference "$@"; ); );}
139         function hexedit {(unset hexedit; ( hexedit -s "$@"; ); );}
140         function cvs2cl {(unset cvs2cl; ( cvs2cl --window 3600 --separate-header --no-wrap "$@"; ); );}
141         function cvsfiles { cvsutil --files --print "$@"; }
142         function cvsignores { cvsutil --ignores --print "$@"; }
143         function cvsignoresall { cvsutil --ignores --workings --print "$@"; }
144         function cvsignoresrm { cvsutil --ignores --rm "$@"; }
145         function cvsignoresrmall { cvsutil --ignores --workings --rm "$@"; }
146         function cvsignoresallrm { cvsutil --ignores --workings --rm "$@"; }
147         function svnignoresall { svn status |sed -n "s/^[?]      //p" "$@"; }
148         function svnignoresallrm { svn status |sed -n "s/^[?]      //p"|tr "\n" "\0"|xargs -0 rm -rf "$@"; }
149         function disass { objdump -D --target=binary --architecture=i386 "$@"; }
150         function cal {(unset cal; ( cal -m "$@"; ); );}
151         function vncreadonly { vncviewer -FullColor -Shared -ViewOnly "$@"; }
152         function diff {(unset diff; ( diff -up "$@"; ); );}
153         function rpmbuildlocal { nice rpmbuild --define "_topdir $PWD" --define "_builddir $PWD" --define "_rpmdir $PWD" --define "_sourcedir $PWD" --define "_specdir $PWD" --define "_srcrpmdir $PWD" --define "_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" "$@"; rmdir &>/dev/null BUILDROOT; }
154         function gdbn { gdb -nx --command=~/.gdbinit "$@"; }
155         function hd { od -Ax -tx1; }
156 '
157
158 export IGNOREEOF=10
159 # '2>/dev/null' to prevent: TMOUT: readonly variable
160 [ -n "$SSH_TTY" ] && export TMOUT=900 2>/dev/null
161 export EDITOR='vim'
162 [ -x /bin/less ] && export PAGER='/bin/less -MMh5cis'
163 export PERL_MM_OPT="PERL=$HOME/bin/perlilib"
164 [ "$UID" -ne 0 ] && export PERL_MM_OPT="$PERL_MM_OPT PREFIX=$HOME"
165 for file in $HOME/.bookmarks.html;do
166         export WWW_HOME="file://$HOME/"
167         [ -r $file ] && export WWW_HOME="file://$file"
168         done
169 export GREP_OPTIONS="--binary-files=without-match --directories=skip"
170 if echo x|GREP_OPTIONS="--exclude=y" grep -q x 2>/dev/null;then
171         export GREP_OPTIONS="$GREP_OPTIONS --exclude=tags --exclude=TAGS --exclude=CVS --exclude=ChangeLog* --exclude=*.svn-base"
172         # FIXME: grep(1) ignores subdirectories for --exclude.
173         #export GREP_OPTIONS="$GREP_OPTIONS --exclude=testsuite --exclude=.pc --exclude=.svn"
174 fi
175 if [ -n "$PS1" ];then   # set only in interactive sessions
176         export PS1='[bash]${LOGNAME}@${HOSTNAME}:${PWD}# '
177         export PS1='\[\017\]'"$PS1"     # \017=std charmap
178         export PS1='\[\033%G\]'"$PS1"   # \033%G=utf-8
179         # Do not: kbd_mode -u # utf-8
180         # as it breaks keyboard state in X and it is not permitted for non-root.
181         fi
182 export MINICOM="-m -c on"       # metakeys+color
183 export HISTSIZE=100000
184 export HISTFILESIZE="$HISTSIZE"
185 export GDBHISTFILE="$HOME/.gdb_history"
186 export CVS_RSH="ssh"
187 export TZ=":/usr/share/zoneinfo/Europe/Prague"
188 # Do not: grep -w "$TERM" /etc/termcap >/dev/null || export TERM=vt220
189 # as Sun workaround as Debian misses: /etc/termcap
190 # expects: $uname_p
191 [ "$TERM" = vt220 -a "${uname_p%86}" != "$uname_p" ] && export TERM=linux
192 if grep 2>/dev/null -q '^..............:0C38 00000000:0000 0A ' /proc/net/tcp;then
193         export  http_proxy=http://127.0.0.1:3128/
194         export https_proxy=http://127.0.0.1:3128/
195         export   ftp_proxy=http://127.0.0.1:3128/
196 fi
197 _selfabs=
198 [ "$_selfabs" = "${_selfabs#/}" ] && _selfabs="$BASH_SOURCE"
199 [ "$_selfabs" = "${_selfabs#/}" ] && _selfabs="$PWD/.bashrc"
200 [ -r "$_selfabs" ] || unset _selfabs
201 [ -n "$_selfabs" ] && export VIMINIT="source `echo "$_selfabs"|sed 's/[.]bashrc$/.vimrc/'`"
202
203 # Force English.
204 unset LANG LANGUAGE `set|sed -n 's/^\(LC_[^=]*\)=.*$/\1/p'`
205 export LANG=en_US.UTF-8
206 # Force strcoll() to sort case-sensitively! (empty/undef doesn't work)
207 export LC_COLLATE=C
208 # Do not: # Prevent: perl: warning: Setting locale failed.
209 #         # due to LC_COLLATE=C and LC_ALL=(unset)
210 #         export LC_ALL=C
211 # as it breaks Mutt "utf-8" and somehow it is no longer needed.
212
213 function wclines { awk '{x[$0]++}END{for (i in x) print x[i]"\t"i}'; }
214 # SunOS does not support "-m"
215 export ULIMITME_OPTS=""
216 for i in "-m 100000" "-d 150000" "-v 200000";do
217         (ulimit $i 2>/dev/null) && ULIMITME_OPTS="$ULIMITME_OPTS $i"
218         done
219 # Prevent: ulimit:  -m 100000 -d 150000 -v 200000: invalid number
220 # by forcing our known $IFS value; eval(1) is needed to take $IFS to effect:
221 function ulimitme { IFS=" " eval "ulimit $ULIMITME_OPTS"; }
222 function grep {(unset grep; ( ulimitme; grep "$@"; ); );}
223 function finame { find . -false `
224         awk </dev/null 'BEGIN{ for (i=1;i<ARGC;i++) print " -o -iname *"ARGV[i]"*"; }' "$@"
225         `; }
226 function mkcd { mkdir -p "$1"; cd "$1"; }
227 function pushdmk { mkdir -p "$1"; pushd "$1"; }
228 function rsync {(unset rsync; nice -n20 rsync -v -e ssh --progress --stats --partial --rsync-path='nice -n20 rsync' "$@"; );}
229 function tohex { od -An -txC|tr -d '\n '|tr 'a-f' 'A-F';echo; }
230 function edall {
231         find -type f|while read -r i;do
232                 (awk </dev/null 'BEGIN{ for (i=1;i<ARGC;i++) print ARGV[i]; }' "$@";echo -e 'w\nq')|ed -s "$i"
233                 done
234         }
235 function mi { (
236         set -ex;cd "$1";while true;do test "$PWD" != "/";if [ -e configure.in -o -e Makefile.PL ];then break;fi;cd ..;done;make install
237         ); }
238 function ctags {(unset ctags
239         if [ $# -ne 0 -a '(' $# -ne 1 -o "$1" '!=' "--c-types=+px" ')' ];then ctags "$@";else
240                 find -name testsuite -prune -o -name .pc -prune -o -name .svn -prune -o \
241                                 -type f -a '!' -name tags -a '!' -name TAGS -a '(' -false \
242                                                 -o -name "*.[chC]" \
243                                                 -o -name "*.cc"    \
244                                                 -o -name "*.cxx"   \
245                                                 -o -name "*.java"  \
246                                                 -o -name "*.p[lm]" \
247                                                 -o -name "*.py" \
248                                                 -o -name "*.exp" \
249                                                 ')' \
250                                 |ctags --file-tags -L - --langmap=Tcl:+.exp "$@"
251         fi; );}
252 function ctagsh { ctags "--c-types=+px"; }
253 function cpan {(unset cpan; if [ $# = 0 ];then cpan;else perl -MCPAN -e "install qw($*);";fi; );}
254 function exx { cd "`unset exx;exx "$@"|tee /proc/self/fd/2|tail -n1|sed -n 's/^extdir=//p'`"; }
255 function revlines { perl -e 'print reverse <>;'; }
256 function debuginfo { if test -n "$*";then echo "$*";else cat;fi \
257         |xargs rpm -qf|xargs rpmquery --qf '%{SOURCERPM}\n'|sed 's/-[^-]*-[^-]*[.]src[.]rpm$/-debuginfo/'|sort -u; }
258 function ipcsrmall { ipcs|awk '/- Shared Memory/{x="-m"}/- Semaphore/{x="-s"}/^0x/{print "ipcrm "x" "$2}'; }
259 function eog {(unset eog; touch /tmp/eog.$$;eog "$@" {,,,,,,,,,}/tmp/eog.$$;rm -f /tmp/eog.$$; );}
260 function diffc { diff -up "$@"|grep -v '^\(Only in \|Binary files\)'; }
261 function diffi { diffc -X ~/.diffi.list "$@" | diffdecvs; }
262 function cvs {(unset cvs
263         local _opts _opts_d _now _line _o
264         _opts_d="-d"
265         if grep -iw '\(sources.redhat.com\|sourceware.org\):/cvs/src' CVS/Root &>/dev/null;then _opts_d="";fi
266         if grep '^tests/kernel/syscalls/ptrace' CVS/Repository &>/dev/null;then _opts_d="";fi
267         _now=false
268         _line=""
269         _opts=""
270         while [ $# != 0 ];do
271                 _o="$1"
272                 shift
273                 _line="$_line $_o"
274                 if [ "$_o" = "--" ] && ! $_now;then _now=true;continue;fi
275                 if [ "${_o#-}" != "$_o" ] && ! $_now;then continue;fi
276                 if [ "$_o" = update -o "$_o" = upd -o "$_o" = up ];then _opts="$_opts_d";fi
277                 break
278                 done
279         cvs $_line $_opts "$@"
280         ); }
281 function perlrpm { repoquery -q --whatprovides $(for i in "$@";do echo "perl($i)";done|sed -e 's/\//::/g' -e 's/[.]pm//g'); }
282 # `-u' limits the search to $UID.
283 function pidof
284 {(unset pidof
285   if [ "$1" = "-u" ];then
286     shift
287     local r="$(pidof "$@")"
288     local space=""
289     local p
290     for p in $r;do
291       if grep -q "$(echo -e "^Uid:\t$UID\t")" "/proc/$p/status";then
292         echo -n "${space}$p"
293         space=" "
294       fi
295     done
296     echo
297   else
298     pidof "$@"
299   fi
300 )}
301
302 ulimit -S -c 0
303 set +H
304 shopt -s mailwarn
305 unset OPTIND
306 umask 022
307
308 if [ -f "$HOME/.bashrc.local" ];then source "$HOME/.bashrc.local";fi
309
310 # Interactive part:
311 for key in $HOME/.ssh/id_dsa;do
312         [ -r "$key" ] || continue
313         # Do not: [ -n "$SSH_TTY" ] && continue
314         # as we may want foreign SSH keys too.
315
316         agenteval=/tmp/.$USER.ssh-agent.eval
317         if lockfile -1 -r 3 -l 10 -s 1 $agenteval.lock;then
318                 test -f $agenteval -a -O $agenteval -a -G $agenteval &&
319                                 # ">/dev/null" to prevent: echo Agent pid 31074
320                                 source $agenteval >/dev/null
321                 if [ "ssh-agent" != "`(xargs -0 </proc/"$SSH_AGENT_PID"/cmdline sh -c 'echo "$0"') 2>/dev/null `" ];then
322                         rm -f $agenteval
323                         (test ! -e $agenteval && ssh-agent -s >$agenteval) || echo >&2 'Failing ssh-agent!'
324                         # ">/dev/null" to prevent: echo Agent pid 31074
325                         source $agenteval >/dev/null
326                 fi
327                 rm -f $agenteval.lock
328         fi
329
330         # Prevent gdm(8) lockups on non-interactive consoles.
331         tty -s || continue
332         (ssh-add -l|grep -qw "$key") && continue
333         if lockfile -! -1 -r 0 $agenteval.input.lock 2>/dev/null;then
334                 echo >&2 -n "Locking: $agenteval.input.lock ... "
335                 lockfile -1 -r -1 $agenteval.input.lock
336                 echo >&2 "locked"
337         fi
338         # Recheck identity existence after the lock acquire
339         if ssh-add -l|grep -qw "$key";then
340                 echo >&2 "Identity $key already appended in the meantime."
341         else
342                 # "2>/dev/null" to prevent: Identity added: .ssh/id_dsa (.ssh/id_dsa)
343                 ssh-add "$key" 2>/dev/null
344         fi
345         rm -f $agenteval.input.lock
346         echo >&2 "$agenteval.input.lock unlocked."
347 done
348 unset agenteval
349
350         unset _home_short_dotbashrc     # permit later reinitializations
351 fi      # _home_short_dotbashrc
352
353 true    # Prevent crash in '-e' mode