]> arthur.barton.de Git - ConfigScripts.git/blob - sys/profile
Only add optional paths to PATH if .not_in_path does not exist
[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         if [ -d "$d" -o -h "$d" ]; then
53                 [ -e "$d/.not_in_path" ] || path="$path$d:"
54         fi
55 done
56 [ -n "$path" ] && PATH="$path$PATH"
57 if [ "$UID" -eq 0 ]; then
58         path=""
59         for d in /usr/pkg/sbin /opt/*/sbin; do
60                 if [ -d "$d" -o -h "$d" ]; then
61                         [ -e "$d/.not_in_path" ] || path="$path$d:"
62                 fi
63         done
64         [ -n "$path" ] && PATH="$path$PATH"
65 fi
66 # append optional directories to PATH ...
67 for d in /usr/bin/X11 /usr/games /usr/share/php/bin; do
68         if [ -d "$d" -o -h "$d" ]; then
69                 [ -e "$d/.not_in_path" ] || PATH="$PATH:$d"
70         fi
71 done
72 # set PATH so it includes user's private executables
73 [ -d ~/Applications -a ! -e ~/Applications/.not_in_path ] \
74         && PATH=~/Applications:"${PATH}"
75 [ -d ~/bin -a ! -e ~/bin/.not_in_path ] \
76         && PATH=~/bin:"${PATH}"
77 [ -d ~/sbin -a ! -e ~/sbin/.not_in_path ] \
78         && PATH=~/sbin:"${PATH}"
79
80 # Setup MANPATH, if manpath(1) isn't available
81 if [ ! "$(type manpath 2>/dev/null)" ]; then
82         [ -z "$MANPATH" ] \
83                 && MANPATH="/usr/local/share/man:/usr/share/man:/usr/man"
84         path=""
85         for d in /usr/pkg/share/man /usr/pkg/man /opt/*/share/man /opt/*/man; do
86                 [ -d "$d" -o -h "$d" ] && path="$path$d:"
87         done
88         [ -n "$path" ] && MANPATH="$path$MANPATH"
89         [ -d ~/share/man ] && MANPATH=~/share/man:"${MANPATH}"
90         [ -d ~/man ] && MANPATH=~/man:"${MANPATH}"
91 fi
92
93 # set variable identifying the chroot you work in
94 [ -r /etc/debian_chroot ] && chroot_name=$(cat /etc/debian_chroot)
95 [ -r /etc/chroot_name ] && chroot_name=$(cat /etc/chroot_name)
96
97 # make sure $UID and $USER is set
98 [ -z "$UID" ] && UID=`id -u`
99 [ -z "$USER" ] && USER=`id -un`
100 export UID USER
101
102 # get my own hostname
103 ME=`hostname 2>/dev/null`
104 export ME
105
106 # Move Xauthority file to local storage, so that sudo et all work
107 if [ -z "$XAUTHORITY" -a -r ~/.Xauthority ]; then
108         cp ~/.Xauthority /tmp/Xauthority-$USER
109         chmod 600 /tmp/Xauthority-$USER
110         export XAUTHORITY="/tmp/Xauthority-$USER"
111 fi
112
113 # read profile additions
114 if [ -d /etc/profile.d -o -d /usr/local/etc/profile.d ]; then
115         for f in /etc/profile.d/* /usr/local/etc/profile.d/*; do
116                 [ -r "$f" ] || continue
117                 case "$f" in
118                         *.csh)
119                                 ;;
120                         *)
121                                 [ -e ~/.ConfigScripts.debug ] \
122                                         && echo " >> $f ..."
123                                 . "$f"
124                 esac
125         done
126 fi
127
128 # read local profile, if available
129 [ -r "/var/lib/${ME}/profile" ] && . /var/lib/${ME}/profile
130
131 # Setup some directories to use local storage (no NFS)
132 [ -d "/usr/local/home/$USER" ] \
133         || ( mkdir /usr/local/home; mkdir "/usr/local/home/$USER" ) >/dev/null 2>&1
134 if [ -w "/usr/local/home/$USER" ]; then
135         export LOCAL_HOME="/usr/local/home/$USER"
136         export CCACHE_DIR="$LOCAL_HOME/.ccache"
137         export XDG_CACHE_HOME="$LOCAL_HOME/.cache"
138 fi
139
140 # interactive shell?
141 [ "$PS1" ] || return
142
143 # validate terminal definition
144 type -p tset >/dev/null 2>&1
145 [ $? -eq 0 ] && eval `tset -s -Q`
146
147 # generic shell prompt
148 [ "$UID" -eq 0 ] \
149         && PS1="<$ME> # " \
150         || PS1="<$ME> \$ "
151
152 # icalBuddy(1)
153 type -p icalBuddy >/dev/null 2>&1
154 if [ $? -eq 0 -a "$UID" -ne 0 ]; then
155         case "$LANG" in
156                 *.UTF*) BUL="•"; SEP="»"; ;;
157                 *)      BUL="*"; SEP=">"; ;;
158         esac
159         icalBuddy -f -n -npn -nc -b " $BUL " -ps "/ $SEP /" -eep "url,notes" \
160                 eventsToday+1 2>/dev/null | grep "$BUL"
161         [ $? -eq 0 ] && echo
162 else
163         # remind(1)
164         type -p remind >/dev/null 2>&1
165         if [ $? -eq 0 -a -r ~/.remind ]; then
166                 remind -h -g -t5 ~/.remind | \
167                         grep -v '^Reminders for ' | grep -v '^$'
168                 [ $? -eq 0 ] && echo
169         fi
170 fi
171
172 # bash-specific initialization
173 [ "$BASH" -a -z "$BASHRCREAD" -a -r /etc/bash.bashrc ] \
174         && source /etc/bash.bashrc
175 [ "$BASH" -a -z "$BASHRCREAD" -a -r /etc/bashrc ] \
176         && source /etc/bashrc
177
178 # ksh-specific initialization
179 [ "$KSH_VERSION" -a -z "$KSHRCREAD" -a -r /etc/ksh.kshrc ] \
180         && . /etc/ksh.kshrc
181
182 # Check filesystem quotas
183 mount 2>/dev/null | grep quota >/dev/null 2>&1
184 if [ $? -eq 0 ]; then
185         which quota >/dev/null 2>&1
186         [ $? -eq 0 ] && quota -q
187 fi
188
189 # -eof-