File modified: bin/setenv.sh
Change293 at Wed May 12 19:17:41 2010 +0200 by Ivan Kanis <ivan@tao>
diff -r 5b305e5da2eb -r 8de5801e2151 bin/setenv.sh --- a/bin/setenv.sh Sat May 08 10:54:58 2010 +0200 +++ b/bin/setenv.sh Wed May 12 19:17:41 2010 +0200 @@ -1,83 +1,17 @@ #!/bin/sh -# return 0 if string is contained inside a string -# input needle haystack -match() { - # backslash forward slash - if test X${BASH} = X - then - back=$(echo $1 | sed -e 's/\//\\\\\//g') - else - back=$(echo $1 | sed -e 's/\//\\\//g') - fi - needle=$(echo $2 | sed -e 's/.*\('$back'\).*/\1/') - if [ "$1" = "$needle" ] - then - return 0 - fi - return 1 -} +local_path=${HOME}/local -os_name() { - os=$(uname -s) +name_os() { + os=`uname -s` if [ "${os}" = "SunOS" ] then - echo "solaris" - elif match CYGWIN $os - then - echo "cygwin" + printf "solaris" else - echo ${os} | tr [A-Z] [a-z] + printf ${os} | tr [A-Z] [a-z] fi } -processor() { - if [ "$(uname)" = "SunOS" ] - then - echo $(uname -p) - else - echo $(uname -m) - fi -} - -# TBD add Solaris and AIX -vendor () { - file_ubuntu=/etc/lsb-release - file_fedora=/etc/system-release-cpe - if [ -f ${file_ubuntu} ] - then - . ${file_ubuntu} - echo ${DISTRIB_ID} | tr [A-Z] [a-z] - elif [ -f ${file_fedora} ] - then - echo $(awk -F : '{print $4}' < ${file_fedora}) - elif [ -f /etc/debian_version ] - then - echo debian - fi -} - -# TBD add Solaris and AIX -version () { - file=/etc/lsb-release - file_fedora=/etc/system-release-cpe - if [ -f ${file} ] - then - . ${file} - echo ${DISTRIB_RELEASE} - elif [ -f ${file_fedora} ] - then - echo $(awk -F : '{print $5}' < ${file_fedora}) - elif [ -f /etc/debian_version ] - then - echo $(cat /etc/debian_version) - fi -} - -arch_path () { - echo "${HOME}/$(vendor)/$(os_name)/$(version)/$(processor)" -} - domain_name () { for file in /etc/domainname /etc/defaultdomain do @@ -87,217 +21,157 @@ return 0 fi done - echo "unknown" + printf "unknown" } path () { - echo "export PKG_CONFIG_PATH=${ARCH_PATH}/lib/pkgconfig" + dopath "PATH" "${PATH}" \ +"/usr/local/sbin:\ +/usr/local/bin:\ +/usr/sbin:\ +/usr/bin:\ +/bin:\ +/sbin:\ +/usr/bin/X11:\ +/usr/X11/bin:\ +${local_path}/acrobat/bin:\ +${local_path}/cxoffice/bin:\ +${local_path}/rplayer:\ +/opt/SUNWut/bin:\ +/opt/SUNWut/sbin:\ +/opt/SUNWvts/bin:\ +/opt/csw/bin:\ +/opt/csw/gcc3/bin:\ +/opt/csw/apache2/bin:\ +/opt/csw/apache2/sbin:\ +/usr/ccs/bin:\ +/usr/openwin/bin:\ +/usr/openwin/demo:\ +/usr/local/bin:\ +${local_path}/jdk/bin:\ +prepend:\ +${local_path}/bin" - # CPAN Perl library - # TBD fix hard coded version - echo "export PERL5LIB=${ARCH_PATH}/share/perl/5.8.8" + dopath "MANPATH" "${MANPATH}" \ +"${local_path}/man:\ +/usr/man:\ +/usr/share/man:\ +/usr/local/man:\ +/usr/X11R6/man:\ +/usr/openwin/man:\ +/usr/local/man:\ +/opt/csw/man:\ +/opt/csw/apache2/man:\ +/usr/perl5/man" - # Local Python library - echo "export PYTHONPATH=${ARCH_PATH}/lib/python" - dopath \ -"PATH" $PATH \ -\ -"Local package" \ -"${ARCH_PATH}/bin" \ -\ -"Home binaries" \ -"${HOME}/hg/bin" \ -"${HOME}/keep/bin" \ -\ -"basic sanity path" \ -"/bin" \ -"/usr/bin" \ -"/usr/bin/X11" \ -"/usr/X11/bin" \ -\ -"Add path not there by default" \ -"/sbin" \ -"/usr/sbin" \ -"/usr/local/sbin" \ -\ -"Acrobat reader" \ -"${ARCH_PATH}/acrobat/bin" \ -\ -"CrossOver office" \ -"${ARCH_PATH}/cxoffice/bin" \ -\ -"Real Player" \ -"${ARCH_PATH}/rplayer" \ -\ -"Solaris" \ -"/opt/SUNWut/bin" \ -"/opt/SUNWut/sbin" \ -"/opt/SUNWvts/bin" \ -\ -"BLastwave " \ -"/opt/csw/bin" \ -"/opt/csw/gcc3/bin" \ -"/opt/csw/apache2/bin" \ -"/opt/csw/apache2/sbin" \ -"/usr/ccs/bin" \ -"/usr/openwin/bin" \ -"/usr/openwin/demo" \ -\ -"Sunfreeware" \ -"/usr/local/bin" \ -\ -"Java" \ -"${ARCH_PATH}/jdk/bin" \ -\ -"Python" \ -"${ARCH_PATH}/lib/python" - - dopath \ -"MANPATH" "$MANPATH" \ -\ -"Local software" \ -"${ARCH_PATH}/man" \ -\ -"Man page" \ -"/usr/man" \ -"/usr/share/man" \ -"/usr/local/man" \ -"/usr/X11R6/man" \ -"Solaris" \ -"/usr/openwin/man" \ -\ -"Sunfreeware" \ -"/usr/local/man" \ -\ -"Blastwave man page" \ -"/opt/csw/man" \ -"/opt/csw/apache2/man/" \ -\ -"Perl" \ -"/usr/perl5/man" - - dopath \ -"LD_LIBRARY_PATH" "$LD_LIBRARY_PATH" \ -\ -"Local libraries" \ -"${ARCH_PATH}/lib" \ -\ -"Blastwave" \ -"/opt/csw/lib" - - + dopath "LD_LIBRARY_PATH" "${LD_LIBRARY_PATH}" \ +"${local_path}/lib:\ +/opt/csw/lib" } dopath () { variable=$1 - shift - value=$1 - shift - - # suppress directory that do not exist in environment - if [ -n "$value" ] - then - first=1 - for path in $(echo $value | tr ":" " ") - do - if [ -d $path ] + out_path=$2 + paths=$3 + save_ifs="$IFS" + prepend=0 + IFS=: + # add directories if they exists + for path in ${paths} + do + if test "${path}" = "prepend" + then + prepend=1 + elif test -d "${path}" && not_in_path "${path}" "${out_path}" + then + if test "X${out_path}" = "X" then - include=1 - for path2 in $out_path - do - if [ $path2 = $path ] - then - include=0 - fi - done - if [ $include -eq 1 ] - then - if [ $first -eq 1 ] - then - out_path="${path}" - first=0 - else - out_path="${out_path} ${path}" - fi - fi - fi - done - fi - - # add directories if they exists - for path in $* - do - if [ -d $path ] - then - match $path $value - if [ $? -eq 1 ] + out_path="${path}" + elif test "X${prepend}" = "X1" then - out_path="${out_path} ${path}" + out_path="${path}:${out_path}" + else + out_path="${out_path}:${path}" fi fi done - out_path=$(echo $out_path | tr " " ":") + IFS="${save_ifs}" + if test "X${out_path}" != "X" + then + printf "export ${variable}=${out_path}\n" + fi +} - echo "export ${variable}=$out_path" +# (IFS=:) +not_in_path () { + path=$1 + shift + for nip_path in $* + do + if test "${nip_path}" = "${path}" + then + return 1 + fi + done + return 0 } # Interactive settings interactive() { + name_os=`name_os` + print_alias # ccache - echo "export CCACHE_DIR=${HOME}/tmp/ccache" - - # CVS - echo "CVS_RSH=ssh" + printf "export CCACHE_DIR=${HOME}/tmp/ccache\n" # More history - echo "shopt -s histappend" - echo "export HISTFILESIZE=10000" - echo "export HISTCONTROL=ignoreboth" - echo "export HISTIGNORE=\"&:ls:[bf]g:exit\"" + printf "shopt -s histappend\n" + printf "export HISTFILESIZE=10000\n" + printf "export HISTCONTROL=ignoreboth\n" + printf "export HISTIGNORE=\"&:ls:[bf]g:exit\"\n" # Lynx configuration file - echo "export LYNX_CFG=${HOME}/.lynxrc" + printf "export LYNX_CFG=${HOME}/.lynxrc\n" # Turn off xon/xoff flow control - echo "stty -ixon" + printf "stty -ixon\n" # Don"t blank out the console - if [ "${OS_NAME}" = "linux" ] + if [ "${name_os}" = "linux" ] then - echo "setterm -blank 0" + printf "setterm -blank 0\n" fi # leave the screen alone when it quits - echo "export LESS=-X" + printf "export LESS=-X\n" # fix Solaris idea of xterm - if [ "${OS_NAME}" = "solaris" ] + if [ "${name_os}" = "solaris" ] then - echo "export TERMINFO=${HOME}/conf/terminfo" + printf "export TERMINFO=${HOME}/conf/terminfo\n" fi # Prompt - echo "export PS1='\h:\w\\$ '" + printf "export PS1='\h:\w\\$ '\n" # rsync setting - echo "export RSYNC_RSH=ssh" + printf "export RSYNC_RSH=ssh\n" # which vi to use which vim > /dev/null 2>&1 if [ $? -eq 0 ] then - echo "export EDITOR=vim" + printf "export EDITOR=vim\n" else - echo "export EDITOR=vi" + printf "export EDITOR=vi\n" fi # ls colors - echo "export LS_COLORS=\"no=00:fi=00:di=01;33:ln=01;35:\ -pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01or=40;31;01:ex=01;32:\"" + printf "export LS_COLORS=\"no=00:fi=00:di=01;33:ln=01;35:\ +pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01or=40;31;01:ex=01;32:\"\n" # man sections - echo "export MANSECT=1:1m:n:l:8:3:2:3posix:3pm:3perl:5:4:9:6:7:7d" + printf "export MANSECT=1:1m:n:l:8:3:2:3posix:3pm:3perl:5:4:9:6:7:7d\n" } print_alias() { @@ -341,15 +215,12 @@ } # main -ARCH_PATH=$(arch_path) -OS_NAME=$(os_name) -VENDOR=$(vendor) if [ "$1" = "--interactive" ] then path interactive else - echo "# This file is generated by ~/hg/bin/setenv.sh" + printf "# This file is generated by ~/hg/bin/setenv.sh\n" path fi