]> arthur.barton.de Git - ConfigScripts.git/blob - sys/profile
acd3fa6a99d1488ad9e3436dfbaa9f5025f3a8b8
[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 # Source "~/.profile.user-1st", when available
15 [ -r ~/.profile.user-1st ] && . ~/.profile.user-1st
16
17 # Setup locale and encoding
18 if [ -e ~/.ConfigScripts.debug ]; then
19         echo " - TERM=\"$TERM\""
20         echo " - LANG=\"$LANG\""
21         echo " - LC_CTYPE=\"$LC_CTYPE\""
22 fi
23 # Does LC_CTYPE or LANG indicate an UTF-8 terminal?
24 LC_encoding=""
25 if [ -n "$LC_CTYPE" ]; then
26         LC_encoding=`echo "$LC_CTYPE" | cut -d. -f2- -s`
27 elif [ -n "$LANG" ]; then
28         LC_encoding=`echo "$LANG" | cut -d. -f2- -s`
29 fi
30 if [ -z "$LC_encoding" ]; then
31         case "$TERM" in
32                 "xterm-"*)
33                         LC_encoding="UTF-8"; ;;
34                 *)
35                         LC_encoding="ISO8859-1"
36         esac
37 fi
38 [ -e ~/.ConfigScripts.debug ] && echo " - LC_encoding=\"$LC_encoding\" (temp)"
39 # Set locale if it is not set or doesn't contain a dot:
40 [ "$LANG" = "${LANG#*.}" -a "$LANG" != "C" ] \
41         && export LANG="${LANG:-de_DE}.${LC_encoding}"
42 [ -e ~/.ConfigScripts.debug ] && echo " - LANG=\"$LANG\" (new)"
43 # Clean up ...
44 unset LC_CTYPE LC_encoding 2>/dev/null
45
46 # Initialize PATH variable
47 if [ -x /usr/libexec/path_helper ]; then
48         eval `/usr/libexec/path_helper -s \
49                 | sed "s|:/usr/local/bin||" | sed "s|:/usr/local/sbin||"`
50         [[ "$PATH" == *sbin* ]] \
51                 && PATH="/usr/local/bin:/usr/local/sbin:$PATH" \
52                 || PATH="/usr/local/bin:$PATH"
53 else
54         PATH="/usr/local/bin:/usr/bin:/bin"
55         [ "$LOGNAME" = "root" ] && PATH="/usr/local/sbin:/usr/sbin:/sbin:$PATH"
56         export PATH
57 fi
58 # prepend optional directories to PATH ...
59 unset path
60 for d in /Developer/usr/bin /usr/pkg/bin /usr/ucb /usr/lib/ccache /opt/*/bin; do
61         if [ -d "$d" -o -h "$d" ]; then
62                 [ -e "$d/.not_in_path" ] || path="$path$d:"
63         fi
64 done
65 [ -n "$path" ] && PATH="$path$PATH"
66 unset path
67 if [ "$LOGNAME" = "root" ]; then
68         for d in /usr/pkg/sbin /opt/*/sbin; do
69                 if [ -d "$d" -o -h "$d" ]; then
70                         [ -e "$d/.not_in_path" ] || path="$path$d:"
71                 fi
72         done
73         [ -n "$path" ] && PATH="$path$PATH"
74         unset path
75 fi
76 # append optional directories to PATH ...
77 for d in /usr/bin/X11 /usr/games /usr/share/php/bin; do
78         if [ -d "$d" -o -h "$d" ]; then
79                 [ -e "$d/.not_in_path" ] || PATH="$PATH:$d"
80         fi
81 done
82 unset d
83 # set PATH so it includes user's private executables
84 [ -d ~/Applications -a ! -e ~/Applications/.not_in_path ] \
85         && PATH=~/Applications:"${PATH}"
86 [ -d ~/bin -a ! -e ~/bin/.not_in_path ] \
87         && PATH=~/bin:"${PATH}"
88 [ -d ~/sbin -a ! -e ~/sbin/.not_in_path ] \
89         && PATH=~/sbin:"${PATH}"
90
91 # Setup MANPATH, if manpath(1) isn't available
92 if [ ! "$(type -t manpath 2>/dev/null)" ]; then
93         [ -z "$MANPATH" ] \
94                 && MANPATH="/usr/local/share/man:/usr/share/man:/usr/man"
95         path=""
96         for d in /usr/pkg/share/man /usr/pkg/man /opt/*/share/man /opt/*/man; do
97                 [ -d "$d" -o -h "$d" ] && path="$path$d:"
98         done
99         [ -n "$path" ] && MANPATH="$path$MANPATH"
100         [ -d ~/share/man ] && MANPATH=~/share/man:"${MANPATH}"
101         [ -d ~/man ] && MANPATH=~/man:"${MANPATH}"
102         unset path d
103 fi
104
105 # set variable identifying the chroot you work in
106 [ -r /etc/debian_chroot ] && chroot_name=$(cat /etc/debian_chroot)
107 [ -r /etc/chroot_name ] && chroot_name=$(cat /etc/chroot_name)
108
109 # get my own hostname
110 [ -n "$HOSTNAME" ] || HOSTNAME=`hostname 2>/dev/null`
111 export HOSTNAME
112
113 # Setup local home directory, when available
114 [ -d "/usr/local/home" -a ! -d "/usr/local/home/$LOGNAME" ] \
115         && mkdir "/usr/local/home/$LOGNAME" >/dev/null 2>&1
116 [ -w "/usr/local/home/$LOGNAME" ] \
117         && export LOCAL_HOME="/usr/local/home/$LOGNAME" \
118         || export LOCAL_HOME="$HOME"
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-