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