]> arthur.barton.de Git - ConfigScripts.git/blobdiff - sys/profile
Use "type" to test for tools
[ConfigScripts.git] / sys / profile
index f1ffada04e1ef518a4708ad24655342ffd09cdbb..191cf2964b694d49dcd345e44b975b7ffe758666 100644 (file)
@@ -1,7 +1,7 @@
 #
 # /etc/profile: system-wide profile for the Bourne shell (sh(1)) and
 # Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
-# Written 2003-2009 by Alexander Barton (alex@barton.de)
+# Written 2003-2014 by Alexander Barton (alex@barton.de)
 #
 
 [ -e ~/.ConfigScripts.debug ] && echo " >> /etc/profile ..."
@@ -9,48 +9,80 @@
 PROFILEREAD="true"
 export PROFILEREAD
 
-# Make sure UID is set
-[ -n "$UID" ] || UID=`id -u`
-export UID
-
-# Set locale if it is not set or doesn't contain a dot;
-# but all system messages should still be in "native" ("C") language.
+# Setup locale and encoding
+if [ -e ~/.ConfigScripts.debug ]; then
+       echo " - TERM=\"$TERM\""
+       echo " - LANG=\"$LANG\""
+       echo " - LC_CTYPE=\"$LC_CTYPE\""
+fi
+# Does LC_CTYPE or LANG indicate an UTF-8 terminal?
+LC_encoding=""
+if [ -n "$LC_CTYPE" ]; then
+       LC_encoding="${LC_CTYPE#*.}"
+elif [ -n "$LANG" ]; then
+       LC_encoding="${LANG#*.}"
+fi
+if [ -z "$LC_encoding" ]; then
+       case "$TERM" in
+               "xterm-"*)
+                       LC_encoding="UTF-8"; ;;
+               *)
+                       LC_encoding="ISO8859-1"
+       esac
+fi
+[ -e ~/.ConfigScripts.debug ] && echo " - LC_encoding=\"$LC_encoding\" (temp)"
+# Set locale if it is not set or doesn't contain a dot:
 [ "$LANG" = "${LANG#*.}" -a "$LANG" != "C" ] \
-       && export LANG="${LANG:-de_DE}.ISO8859-1"
-export LC_MESSAGES="C"
+       && export LANG="${LANG:-de_DE}.${LC_encoding}"
+[ -e ~/.ConfigScripts.debug ] && echo " - LANG=\"$LANG\" (new)"
+# Clean up ...
+unset LC_CTYPE LC_encoding 2>/dev/null
 
 # Initialize PATH variable
 if [ -x /usr/libexec/path_helper ]; then
-       eval `/usr/libexec/path_helper -s`
+       eval `/usr/libexec/path_helper -s \
+               | sed "s|:/usr/local/bin||" | sed "s|:/usr/local/sbin||"`
+       [[ "$PATH" == *sbin* ]] \
+               && PATH="/usr/local/bin:/usr/local/sbin:$PATH" \
+               || PATH="/usr/local/bin:$PATH"
 else
        PATH="/usr/local/bin:/usr/bin:/bin"
-       [ "$UID" -eq 0 ] && PATH="/usr/local/sbin:/usr/sbin:/sbin:$PATH"
+       [ "$LOGNAME" = "root" ] && PATH="/usr/local/sbin:/usr/sbin:/sbin:$PATH"
        export PATH
 fi
 # prepend optional directories to PATH ...
 path=""
-for d in /Developer/usr/bin /usr/pkg/bin /opt/*/bin; do
-       [ -d "$d" -o -h "$d" ] && path="$path$d:"
+for d in /Developer/usr/bin /usr/pkg/bin /usr/ucb /usr/lib/ccache /opt/*/bin; do
+       if [ -d "$d" -o -h "$d" ]; then
+               [ -e "$d/.not_in_path" ] || path="$path$d:"
+       fi
 done
 [ -n "$path" ] && PATH="$path$PATH"
-if [ "$UID" -eq 0 ]; then
+if [ "$LOGNAME" = "root" ]; then
        path=""
        for d in /usr/pkg/sbin /opt/*/sbin; do
-               [ -d "$d" -o -h "$d" ] && path="$path$d:"
+               if [ -d "$d" -o -h "$d" ]; then
+                       [ -e "$d/.not_in_path" ] || path="$path$d:"
+               fi
        done
        [ -n "$path" ] && PATH="$path$PATH"
 fi
 # append optional directories to PATH ...
-for d in /usr/bin/X11 /usr/games; do
-       [ -d "$d" -o -h "$d" ] && PATH="$PATH:$d"
+for d in /usr/bin/X11 /usr/games /usr/share/php/bin; do
+       if [ -d "$d" -o -h "$d" ]; then
+               [ -e "$d/.not_in_path" ] || PATH="$PATH:$d"
+       fi
 done
 # set PATH so it includes user's private executables
-[ -d ~/Applications ] && PATH=~/Applications:"${PATH}"
-[ -d ~/bin ] && PATH=~/bin:"${PATH}"
-[ -d ~/sbin ] && PATH=~/sbin:"${PATH}"
+[ -d ~/Applications -a ! -e ~/Applications/.not_in_path ] \
+       && PATH=~/Applications:"${PATH}"
+[ -d ~/bin -a ! -e ~/bin/.not_in_path ] \
+       && PATH=~/bin:"${PATH}"
+[ -d ~/sbin -a ! -e ~/sbin/.not_in_path ] \
+       && PATH=~/sbin:"${PATH}"
 
 # Setup MANPATH, if manpath(1) isn't available
-if [ ! "$(type manpath)" ]; then
+if [ ! "$(type manpath 2>/dev/null)" ]; then
        [ -z "$MANPATH" ] \
                && MANPATH="/usr/local/share/man:/usr/share/man:/usr/man"
        path=""
@@ -66,28 +98,20 @@ fi
 [ -r /etc/debian_chroot ] && chroot_name=$(cat /etc/debian_chroot)
 [ -r /etc/chroot_name ] && chroot_name=$(cat /etc/chroot_name)
 
-# validate terminal definition
-[ -z "$TERM" ] && eval `tset -s -Q`
-
-# make sure $UID and $USER is set
-[ -z "$UID" ] && UID=`id -u`
-[ -z "$USER" ] && USER=`id -un`
-export UID USER
-
 # get my own hostname
-ME=`hostname -s`
+ME=`hostname 2>/dev/null`
 export ME
 
 # Move Xauthority file to local storage, so that sudo et all work
 if [ -z "$XAUTHORITY" -a -r ~/.Xauthority ]; then
-       cp ~/.Xauthority /tmp/Xauthority-$USER
-       chmod 600 /tmp/Xauthority-$USER
-       export XAUTHORITY="/tmp/Xauthority-$USER"
+       cp ~/.Xauthority /tmp/Xauthority-$LOGNAME
+       chmod 600 /tmp/Xauthority-$LOGNAME
+       export XAUTHORITY="/tmp/Xauthority-$LOGNAME"
 fi
 
 # read profile additions
-if [ -d /etc/profile.d ]; then
-       for f in /etc/profile.d/*; do
+if [ -d /etc/profile.d -o -d /usr/local/etc/profile.d ]; then
+       for f in /etc/profile.d/* /usr/local/etc/profile.d/*; do
                [ -r "$f" ] || continue
                case "$f" in
                        *.csh)
@@ -103,29 +127,47 @@ fi
 # read local profile, if available
 [ -r "/var/lib/${ME}/profile" ] && . /var/lib/${ME}/profile
 
+# Setup some directories to use local storage (no NFS)
+[ -d "/usr/local/home/$LOGNAME" ] \
+       || ( mkdir /usr/local/home; mkdir "/usr/local/home/$LOGNAME" ) >/dev/null 2>&1
+if [ -w "/usr/local/home/$LOGNAME" ]; then
+       export LOCAL_HOME="/usr/local/home/$LOGNAME"
+       export CCACHE_DIR="$LOCAL_HOME/.ccache"
+       export XDG_CACHE_HOME="$LOCAL_HOME/.cache"
+fi
+
 # interactive shell?
 [ "$PS1" ] || return
 
+# validate terminal definition
+type tset >/dev/null 2>&1 && eval `tset -s -Q`
+
 # generic shell prompt
-[ "$UID" -eq 0 ] \
+[ "$LOGNAME" = "root" ] \
        && PS1="<$ME> # " \
        || PS1="<$ME> \$ "
 
 # icalBuddy(1)
 type -p icalBuddy >/dev/null 2>&1
-if [ $? -eq 0 -a "$UID" -ne 0 ]; then
+if [ $? -eq 0 -a "$LOGNAME" != "root" ]; then
        case "$LANG" in
-               *.UTF*) BUL="•"; SEP="»"; ;;
-               *)      BUL="*"; SEP=">"; ;;
+               *.UTF*) bul="•"; bul_imp="!"; sep="»"; ;;
+               *)      bul="*"; bul_imp="!"; sep=">"; ;;
        esac
-       icalBuddy -f -n -npn -nc -b " $BUL " -ps "/ $SEP /" -eep "url,notes" \
-               eventsToday+1 | grep "$BUL"
+       icalBuddy -f -n -b " $bul " -ab " $bul_imp " -ps "/ $sep /" \
+               -nc -npn -iep "title,due" -stda \
+               tasksDueBefore:today 2>/dev/null
+       icalBuddy -f -n -b " $bul " -ab " $bul_imp " -ps "/ $sep /" \
+               -nc -npn -iep "title,datetime" \
+               eventsToday+1 2>/dev/null
        [ $? -eq 0 ] && echo
+       unset bul bul_imp sep
 else
        # remind(1)
        type -p remind >/dev/null 2>&1
        if [ $? -eq 0 -a -r ~/.remind ]; then
-               remind -h -g -t5 .remind | grep "^[0-9]"
+               remind -h -g -t5 ~/.remind | \
+                       grep -v '^Reminders for ' | grep -v '^$'
                [ $? -eq 0 ] && echo
        fi
 fi
@@ -141,10 +183,9 @@ fi
        && . /etc/ksh.kshrc
 
 # Check filesystem quotas
-mount | grep quota >/dev/null 2>&1
+mount 2>/dev/null | grep quota >/dev/null 2>&1
 if [ $? -eq 0 ]; then
-       which quota >/dev/null 2>&1
-       [ $? -eq 0 ] && quota -q
+       type quota >/dev/null 2>&1 && quota -q
 fi
 
 # -eof-