]> arthur.barton.de Git - ConfigScripts.git/blob - sys/profile
sys/profile: Only call "tset" when it is available
[ConfigScripts.git] / sys / profile
1 #
2 # /etc/profile: system-wide profile for the Bourne shell (sh(1)) and
3 # Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
4 # Written 2003-2012 by Alexander Barton (alex@barton.de)
5 #
6
7 [ -e ~/.ConfigScripts.debug ] && echo " >> /etc/profile ..."
8
9 PROFILEREAD="true"
10 export PROFILEREAD
11
12 # Make sure UID is set
13 [ -n "$UID" ] || UID=`id -u`
14 export UID
15
16 # Indicates LC_CTYPE an UTF-8 terminal?
17 if [ -n "$LC_CTYPE" ]; then
18         LC_encoding="${LC_CTYPE#*.}"
19 else
20         case "$TERM" in
21                 "xterm-"*)
22                         LC_encoding="UTF-8"; ;;
23                 *)
24                         LC_encoding="ISO8859-1"
25         esac
26 fi
27 # Set locale if it is not set or doesn't contain a dot:
28 [ "$LANG" = "${LANG#*.}" -a "$LANG" != "C" ] \
29         && export LANG="${LANG:-de_DE}.${LC_encoding}"
30 # All system messages should still be in "native" ("C") language for
31 # non-X11 sessions:
32 [ -z "$GDMSESSION" -a -z "$XDG_SESSION_COOKIE" ] \
33         && export LC_MESSAGES="C"
34 # Clean up ...
35 unset LC_CTYPE LC_encoding 2>/dev/null
36
37 # Initialize PATH variable
38 if [ -x /usr/libexec/path_helper ]; then
39         eval `/usr/libexec/path_helper -s \
40                 | sed "s|:/usr/local/bin||" | sed "s|:/usr/local/sbin||"`
41         [[ "$PATH" == *sbin* ]] \
42                 && PATH="/usr/local/bin:/usr/local/sbin:$PATH" \
43                 || PATH="/usr/local/bin:$PATH"
44 else
45         PATH="/usr/local/bin:/usr/bin:/bin"
46         [ "$UID" -eq 0 ] && PATH="/usr/local/sbin:/usr/sbin:/sbin:$PATH"
47         export PATH
48 fi
49 # prepend optional directories to PATH ...
50 path=""
51 for d in /Developer/usr/bin /usr/pkg/bin /usr/ucb /usr/lib/ccache /opt/*/bin; do
52         [ -d "$d" -o -h "$d" ] && path="$path$d:"
53 done
54 [ -n "$path" ] && PATH="$path$PATH"
55 if [ "$UID" -eq 0 ]; then
56         path=""
57         for d in /usr/pkg/sbin /opt/*/sbin; do
58                 [ -d "$d" -o -h "$d" ] && path="$path$d:"
59         done
60         [ -n "$path" ] && PATH="$path$PATH"
61 fi
62 # append optional directories to PATH ...
63 for d in /usr/bin/X11 /usr/games /usr/share/php/bin; do
64         [ -d "$d" -o -h "$d" ] && PATH="$PATH:$d"
65 done
66 # set PATH so it includes user's private executables
67 [ -d ~/Applications ] && PATH=~/Applications:"${PATH}"
68 [ -d ~/bin ] && PATH=~/bin:"${PATH}"
69 [ -d ~/sbin ] && PATH=~/sbin:"${PATH}"
70
71 # Setup MANPATH, if manpath(1) isn't available
72 if [ ! "$(type manpath 2>/dev/null)" ]; then
73         [ -z "$MANPATH" ] \
74                 && MANPATH="/usr/local/share/man:/usr/share/man:/usr/man"
75         path=""
76         for d in /usr/pkg/share/man /usr/pkg/man /opt/*/share/man /opt/*/man; do
77                 [ -d "$d" -o -h "$d" ] && path="$path$d:"
78         done
79         [ -n "$path" ] && MANPATH="$path$MANPATH"
80         [ -d ~/share/man ] && MANPATH=~/share/man:"${MANPATH}"
81         [ -d ~/man ] && MANPATH=~/man:"${MANPATH}"
82 fi
83
84 # set variable identifying the chroot you work in
85 [ -r /etc/debian_chroot ] && chroot_name=$(cat /etc/debian_chroot)
86 [ -r /etc/chroot_name ] && chroot_name=$(cat /etc/chroot_name)
87
88 # make sure $UID and $USER is set
89 [ -z "$UID" ] && UID=`id -u`
90 [ -z "$USER" ] && USER=`id -un`
91 export UID USER
92
93 # get my own hostname
94 ME=`hostname 2>/dev/null`
95 export ME
96
97 # Move Xauthority file to local storage, so that sudo et all work
98 if [ -z "$XAUTHORITY" -a -r ~/.Xauthority ]; then
99         cp ~/.Xauthority /tmp/Xauthority-$USER
100         chmod 600 /tmp/Xauthority-$USER
101         export XAUTHORITY="/tmp/Xauthority-$USER"
102 fi
103
104 # read profile additions
105 if [ -d /etc/profile.d -o -d /usr/local/etc/profile.d ]; then
106         for f in /etc/profile.d/* /usr/local/etc/profile.d/*; do
107                 [ -r "$f" ] || continue
108                 case "$f" in
109                         *.csh)
110                                 ;;
111                         *)
112                                 [ -e ~/.ConfigScripts.debug ] \
113                                         && echo " >> $f ..."
114                                 . "$f"
115                 esac
116         done
117 fi
118
119 # read local profile, if available
120 [ -r "/var/lib/${ME}/profile" ] && . /var/lib/${ME}/profile
121
122 # Setup some directories to use local storage (no NFS)
123 [ -d "/usr/local/home/$USER" ] \
124         || ( mkdir /usr/local/home; mkdir "/usr/local/home/$USER" ) >/dev/null 2>&1
125 if [ -w "/usr/local/home/$USER" ]; then
126         export LOCAL_HOME="/usr/local/home/$USER"
127         export CCACHE_DIR="$LOCAL_HOME/.ccache"
128         export XDG_CACHE_HOME="$LOCAL_HOME/.cache"
129 fi
130
131 # interactive shell?
132 [ "$PS1" ] || return
133
134 # validate terminal definition
135 type -p tset >/dev/null 2>&1
136 [ $? -eq 0 ] && eval `tset -s -Q`
137
138 # generic shell prompt
139 [ "$UID" -eq 0 ] \
140         && PS1="<$ME> # " \
141         || PS1="<$ME> \$ "
142
143 # icalBuddy(1)
144 type -p icalBuddy >/dev/null 2>&1
145 if [ $? -eq 0 -a "$UID" -ne 0 ]; then
146         case "$LANG" in
147                 *.UTF*) BUL="•"; SEP="»"; ;;
148                 *)      BUL="*"; SEP=">"; ;;
149         esac
150         icalBuddy -f -n -npn -nc -b " $BUL " -ps "/ $SEP /" -eep "url,notes" \
151                 eventsToday+1 2>/dev/null | grep "$BUL"
152         [ $? -eq 0 ] && echo
153 else
154         # remind(1)
155         type -p remind >/dev/null 2>&1
156         if [ $? -eq 0 -a -r ~/.remind ]; then
157                 remind -h -g -t5 ~/.remind | \
158                         grep -v '^Reminders for ' | grep -v '^$'
159                 [ $? -eq 0 ] && echo
160         fi
161 fi
162
163 # bash-specific initialization
164 [ "$BASH" -a -z "$BASHRCREAD" -a -r /etc/bash.bashrc ] \
165         && source /etc/bash.bashrc
166 [ "$BASH" -a -z "$BASHRCREAD" -a -r /etc/bashrc ] \
167         && source /etc/bashrc
168
169 # ksh-specific initialization
170 [ "$KSH_VERSION" -a -z "$KSHRCREAD" -a -r /etc/ksh.kshrc ] \
171         && . /etc/ksh.kshrc
172
173 # Check filesystem quotas
174 mount 2>/dev/null | grep quota >/dev/null 2>&1
175 if [ $? -eq 0 ]; then
176         which quota >/dev/null 2>&1
177         [ $? -eq 0 ] && quota -q
178 fi
179
180 # -eof-