]> arthur.barton.de Git - ConfigScripts.git/blob - sys/profile
45732280531d70e767c6c4b81a8a24dc1438f4d5
[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-2015 by Alexander Barton (alex@barton.de)
5 #
6
7 [ -e ~/.ConfigScripts.debug ] && echo " .. /etc/profile ..."
8
9 PROFILEREAD="true"
10 export PROFILEREAD
11
12 [ -e ~/.ConfigScripts.debug ] && echo " >> /etc/profile ..."
13
14 # Setup locale and encoding
15 if [ -e ~/.ConfigScripts.debug ]; then
16         echo "     - TERM=\"$TERM\""
17         echo "     - LANG=\"$LANG\""
18         echo "     - LC_CTYPE=\"$LC_CTYPE\""
19 fi
20 # Does LC_CTYPE or LANG indicate an UTF-8 terminal?
21 LC_encoding=""
22 if [ -n "$LC_CTYPE" ]; then
23         LC_encoding=`echo "$LC_CTYPE" | cut -d. -f2- -s`
24 elif [ -n "$LANG" ]; then
25         LC_encoding=`echo "$LANG" | cut -d. -f2- -s`
26 fi
27 if [ -z "$LC_encoding" ]; then
28         case "$TERM" in
29                 "xterm-"*)
30                         LC_encoding="UTF-8"; ;;
31                 *)
32                         LC_encoding="ISO8859-1"
33         esac
34 fi
35 [ -e ~/.ConfigScripts.debug ] && echo "     - LC_encoding=\"$LC_encoding\" (temp)"
36 # Set locale if it is not set or doesn't contain a dot:
37 [ "$LANG" = "${LANG#*.}" -a "$LANG" != "C" ] \
38         && export LANG="${LANG:-de_DE}.${LC_encoding}"
39 [ -e ~/.ConfigScripts.debug ] && echo "     - LANG=\"$LANG\" (new)"
40 # Clean up ...
41 unset LC_CTYPE LC_encoding 2>/dev/null
42
43 # Fix TERM:
44 # Use "xterm-256color" for xterm's (and the like) when it is available
45 [ "$TERM" = "xterm" -a -r "/usr/share/terminfo/x/xterm+256color" ] \
46         && export TERM="xterm-256color"
47 # Don't use "xterm-256color" when it is not available
48 [ "$TERM" = "xterm-256color" -a -r "/usr/share/terminfo/x/xterm+256color" ] \
49         || export TERM="xterm"
50
51 # Initialize PATH variable
52 if [ -x /usr/libexec/path_helper ]; then
53         eval `/usr/libexec/path_helper -s \
54                 | sed "s|:/usr/local/bin||" | sed "s|:/usr/local/sbin||"`
55         [[ "$PATH" == *sbin* ]] \
56                 && PATH="/usr/local/bin:/usr/local/sbin:$PATH" \
57                 || PATH="/usr/local/bin:$PATH"
58 else
59         PATH="/usr/local/bin:/usr/bin:/bin"
60         [ "$LOGNAME" = "root" ] && PATH="/usr/local/sbin:/usr/sbin:/sbin:$PATH"
61         export PATH
62 fi
63 # prepend optional directories to PATH ...
64 unset path
65 for d in \
66   /usr/local/opt/ccache/libexec \
67   /Developer/usr/bin \
68   /usr/pkg/bin \
69   /usr/ucb \
70   /usr/lib/ccache \
71   /opt/*/bin
72 do
73         if [ -d "$d" -o -h "$d" ]; then
74                 [ -e "$d/.not_in_path" ] || path="$path$d:"
75         fi
76 done
77 [ -n "$path" ] && PATH="$path$PATH"
78 unset path
79 if [ "$LOGNAME" = "root" ]; then
80         for d in \
81           /usr/pkg/sbin \
82           /opt/*/sbin
83         do
84                 if [ -d "$d" -o -h "$d" ]; then
85                         [ -e "$d/.not_in_path" ] || path="$path$d:"
86                 fi
87         done
88         [ -n "$path" ] && PATH="$path$PATH"
89         unset path
90 fi
91 # append optional directories to PATH ...
92 for d in \
93   /usr/bin/X11 \
94   /usr/games \
95   /usr/share/php/bin
96 do
97         if [ -d "$d" -o -h "$d" ]; then
98                 [ -e "$d/.not_in_path" ] || PATH="$PATH:$d"
99         fi
100 done
101 unset d
102 # set PATH so it includes user's private executables
103 [ -d ~/Applications -a ! -e ~/Applications/.not_in_path ] \
104         && PATH=~/Applications:"${PATH}"
105 [ -d ~/bin -a ! -e ~/bin/.not_in_path ] \
106         && PATH=~/bin:"${PATH}"
107 [ -d ~/sbin -a ! -e ~/sbin/.not_in_path ] \
108         && PATH=~/sbin:"${PATH}"
109
110 # Setup MANPATH, if manpath(1) isn't available
111 if [ ! "$(type -t manpath 2>/dev/null)" ]; then
112         [ -z "$MANPATH" ] \
113                 && MANPATH="/usr/local/share/man:/usr/share/man:/usr/man"
114         path=""
115         for d in \
116           /usr/pkg/share/man \
117           /usr/pkg/man \
118           /opt/*/share/man \
119           /opt/*/man
120         do
121                 [ -d "$d" -o -h "$d" ] && path="$path$d:"
122         done
123         [ -n "$path" ] && MANPATH="$path$MANPATH"
124         [ -d ~/share/man ] && MANPATH=~/share/man:"${MANPATH}"
125         [ -d ~/man ] && MANPATH=~/man:"${MANPATH}"
126         unset path d
127 fi
128
129 # set variable identifying the chroot you work in
130 [ -r /etc/debian_chroot ] && chroot_name=$(cat /etc/debian_chroot)
131 [ -r /etc/chroot_name ] && chroot_name=$(cat /etc/chroot_name)
132
133 # get my own hostname
134 [ -n "$HOSTNAME" ] || HOSTNAME=`hostname 2>/dev/null`
135 export HOSTNAME
136
137 # Setup local home directory, when available
138 [ -d "/usr/local/home" -a ! -d "/usr/local/home/$LOGNAME" ] \
139         && mkdir "/usr/local/home/$LOGNAME" >/dev/null 2>&1
140 [ -w "/usr/local/home/$LOGNAME" ] \
141         && export LOCAL_HOME="/usr/local/home/$LOGNAME" \
142         || export LOCAL_HOME="$HOME"
143
144 # Source "~/.profile.user-1st", when available
145 [ -r ~/.profile.user-1st ] && . ~/.profile.user-1st
146
147 # Setup environment to use local storage (no NFS, if possible!)
148 export XDG_CACHE_HOME="$LOCAL_HOME/.cache"
149
150 # Setup environment for ccache, if installed
151 type -t ccache >/dev/null && export CCACHE_DIR="$XDG_CACHE_HOME/ccache"
152
153 # Setup environment for Python "pip", if installed
154 if [ "$(type -t pip 2>/dev/null)" ]; then
155         export PIP_REQUIRE_VIRTUALENV=true
156         export PIP_DOWNLOAD_CACHE="$XDG_CACHE_HOME/pip"
157 fi
158
159 # Move Xauthority file to local storage, so that sudo et all work
160 if [ -z "$XAUTHORITY" -a -r ~/.Xauthority ]; then
161         cp ~/.Xauthority /tmp/Xauthority-$LOGNAME
162         chmod 600 /tmp/Xauthority-$LOGNAME
163         export XAUTHORITY="/tmp/Xauthority-$LOGNAME"
164 fi
165
166 # read profile additions
167 if [ -d /etc/profile.d -o -d /usr/local/etc/profile.d ]; then
168         for f in \
169           /etc/profile.d/* \
170           /usr/local/etc/profile.d/*
171         do
172                 [ -r "$f" ] || continue
173                 case "$f" in
174                         *.csh)
175                                 ;;
176                         *)
177                                 [ -e ~/.ConfigScripts.debug ] \
178                                         && echo " >> $f ..."
179                                 . "$f"
180                 esac
181         done
182         unset f
183 fi
184
185 # read local profile, if available
186 [ -r "/var/lib/${HOSTNAME}/profile" ] && . /var/lib/${HOSTNAME}/profile
187
188 # interactive shell?
189 case "$-" in
190         *i*) ;;
191         *) return ;;
192 esac
193
194 # validate terminal definition
195 type -t tset >/dev/null && eval `tset -s -Q`
196
197 # generic shell prompt
198 [ "$LOGNAME" = "root" ] \
199         && PS1="<$HOSTNAME> # " \
200         || PS1="<$HOSTNAME> \$ "
201
202 # Reminders (once every 60 minutes)
203 if [ -z `find ~/.last_reminder -mmin -60 2>/dev/null` ]; then
204         [ -e ~/.ConfigScripts.debug ] && echo "     - Reminders ..."
205         if [ "$(type -t icalBuddy >/dev/null)" -a "$LOGNAME" != "root" ]; then
206                 # icalBuddy(1)
207                 case "$LANG" in
208                         *.UTF*) bul="•"; bul_imp="!"; sep="»"; ;;
209                         *)      bul="*"; bul_imp="!"; sep=">"; ;;
210                 esac
211                 icalBuddy -f -n -b " $bul " -ab " $bul_imp " -ps "/ $sep /" \
212                         -nc -npn -iep "title,due" -stda \
213                         tasksDueBefore:today 2>/dev/null
214                 icalBuddy -f -n -b " $bul " -ab " $bul_imp " -ps "/ $sep /" \
215                         -nc -npn -iep "title,datetime" \
216                         eventsToday+1 2>/dev/null
217                 [ $? -eq 0 ] && echo
218                 unset bul bul_imp sep
219         else
220                 # remind(1)
221                 if [ "$(type -t remind >/dev/null)" -a -r ~/.remind ]; then
222                         remind -h -g -t5 ~/.remind | \
223                                 grep -v '^Reminders for ' | grep -v '^$'
224                         [ $? -eq 0 ] && echo
225                 fi
226         fi
227         [ -w ~/ ] && touch ~/.last_reminder
228 fi
229
230 # bash-specific initialization
231 [ "$BASH" -a -z "$BASHRCREAD" -a -r /etc/bash.bashrc ] \
232         && source /etc/bash.bashrc
233 [ "$BASH" -a -z "$BASHRCREAD" -a -r /etc/bashrc ] \
234         && source /etc/bashrc
235
236 # ksh-specific initialization
237 [ "$KSH_VERSION" -a -z "$KSHRCREAD" -a -r /etc/ksh.kshrc ] \
238         && . /etc/ksh.kshrc
239
240 # Check filesystem quotas
241 mount 2>/dev/null | grep quota >/dev/null 2>&1
242 if [ $? -eq 0 ]; then
243         type -t quota >/dev/null && quota -q
244 fi
245
246 # -eof-