]> arthur.barton.de Git - ConfigScripts.git/blob - sys/profile
Reminders: only create "~/.last_reminder" when "~" is writable
[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-2014 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 # Setup environment to use local storage (no NFS, if possible!)
118 export XDG_CACHE_HOME="$LOCAL_HOME/.cache"
119
120 # Setup environment for ccache, if installed
121 type -t ccache >/dev/null && export CCACHE_DIR="$XDG_CACHE_HOME/ccache"
122
123 # Setup environment for Python "pip", if installed
124 if [ "$(type -t pip 2>/dev/null)" ]; then
125         export PIP_REQUIRE_VIRTUALENV=true
126         export PIP_DOWNLOAD_CACHE="$XDG_CACHE_HOME/pip"
127 fi
128
129 # Move Xauthority file to local storage, so that sudo et all work
130 if [ -z "$XAUTHORITY" -a -r ~/.Xauthority ]; then
131         cp ~/.Xauthority /tmp/Xauthority-$LOGNAME
132         chmod 600 /tmp/Xauthority-$LOGNAME
133         export XAUTHORITY="/tmp/Xauthority-$LOGNAME"
134 fi
135
136 # read profile additions
137 if [ -d /etc/profile.d -o -d /usr/local/etc/profile.d ]; then
138         for f in /etc/profile.d/* /usr/local/etc/profile.d/*; do
139                 [ -r "$f" ] || continue
140                 case "$f" in
141                         *.csh)
142                                 ;;
143                         *)
144                                 [ -e ~/.ConfigScripts.debug ] \
145                                         && echo " >> $f ..."
146                                 . "$f"
147                 esac
148         done
149         unset f
150 fi
151
152 # read local profile, if available
153 [ -r "/var/lib/${HOSTNAME}/profile" ] && . /var/lib/${HOSTNAME}/profile
154
155 # interactive shell?
156 [ "$PS1" ] || return
157
158 # validate terminal definition
159 type -t tset >/dev/null && eval `tset -s -Q`
160
161 # generic shell prompt
162 [ "$LOGNAME" = "root" ] \
163         && PS1="<$HOSTNAME> # " \
164         || PS1="<$HOSTNAME> \$ "
165
166 # Reminders (once every 60 minutes)
167 if [ -z `find ~/.last_reminder -mmin -60 2>/dev/null` ]; then
168         [ -e ~/.ConfigScripts.debug ] && echo " - Reminders ..."
169         if [ "$(type -t icalBuddy >/dev/null)" -a "$LOGNAME" != "root" ]; then
170                 # icalBuddy(1)
171                 case "$LANG" in
172                         *.UTF*) bul="•"; bul_imp="!"; sep="»"; ;;
173                         *)      bul="*"; bul_imp="!"; sep=">"; ;;
174                 esac
175                 icalBuddy -f -n -b " $bul " -ab " $bul_imp " -ps "/ $sep /" \
176                         -nc -npn -iep "title,due" -stda \
177                         tasksDueBefore:today 2>/dev/null
178                 icalBuddy -f -n -b " $bul " -ab " $bul_imp " -ps "/ $sep /" \
179                         -nc -npn -iep "title,datetime" \
180                         eventsToday+1 2>/dev/null
181                 [ $? -eq 0 ] && echo
182                 unset bul bul_imp sep
183         else
184                 # remind(1)
185                 if [ "$(type -t remind >/dev/null)" -a -r ~/.remind ]; then
186                         remind -h -g -t5 ~/.remind | \
187                                 grep -v '^Reminders for ' | grep -v '^$'
188                         [ $? -eq 0 ] && echo
189                 fi
190         fi
191         [ -w ~/ ] && touch ~/.last_reminder
192 fi
193
194 # bash-specific initialization
195 [ "$BASH" -a -z "$BASHRCREAD" -a -r /etc/bash.bashrc ] \
196         && source /etc/bash.bashrc
197 [ "$BASH" -a -z "$BASHRCREAD" -a -r /etc/bashrc ] \
198         && source /etc/bashrc
199
200 # ksh-specific initialization
201 [ "$KSH_VERSION" -a -z "$KSHRCREAD" -a -r /etc/ksh.kshrc ] \
202         && . /etc/ksh.kshrc
203
204 # Check filesystem quotas
205 mount 2>/dev/null | grep quota >/dev/null 2>&1
206 if [ $? -eq 0 ]; then
207         type -t quota >/dev/null && quota -q
208 fi
209
210 # -eof-