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