]> arthur.barton.de Git - ConfigScripts.git/blob - sys/profile
Better detect encoding of the terminal
[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 # Make sure UID is set
13 [ -n "$UID" ] || UID=`id -u`
14 export UID
15
16 # Setup locale and encoding
17 if [ -e ~/.ConfigScripts.debug ]; then
18         echo " - TERM=\"$TERM\""
19         echo " - LANG=\"$LANG\""
20         echo " - LC_CTYPE=\"$LC_CTYPE\""
21 fi
22 # Does LC_CTYPE or LANG indicate an UTF-8 terminal?
23 LC_encoding=""
24 if [ -n "$LC_CTYPE" ]; then
25         LC_encoding="${LC_CTYPE#*.}"
26 elif [ -n "$LANG" ]; then
27         LC_encoding="${LANG#*.}"
28 fi
29 if [ -z "$LC_encoding" ]; then
30         case "$TERM" in
31                 "xterm-"*)
32                         LC_encoding="UTF-8"; ;;
33                 *)
34                         LC_encoding="ISO8859-1"
35         esac
36 fi
37 [ -e ~/.ConfigScripts.debug ] && echo " - LC_encoding=\"$LC_encoding\" (temp)"
38 # Set locale if it is not set or doesn't contain a dot:
39 [ "$LANG" = "${LANG#*.}" -a "$LANG" != "C" ] \
40         && export LANG="${LANG:-de_DE}.${LC_encoding}"
41 [ -e ~/.ConfigScripts.debug ] && echo " - LANG=\"$LANG\" (new)"
42 # All system messages should still be in "native" ("C") language for
43 # non-X11 sessions:
44 [ -z "$GDMSESSION" -a -z "$XDG_SESSION_COOKIE" ] \
45         && export LC_MESSAGES="C"
46 # Clean up ...
47 unset LC_CTYPE LC_encoding 2>/dev/null
48
49 # Initialize PATH variable
50 if [ -x /usr/libexec/path_helper ]; then
51         eval `/usr/libexec/path_helper -s \
52                 | sed "s|:/usr/local/bin||" | sed "s|:/usr/local/sbin||"`
53         [[ "$PATH" == *sbin* ]] \
54                 && PATH="/usr/local/bin:/usr/local/sbin:$PATH" \
55                 || PATH="/usr/local/bin:$PATH"
56 else
57         PATH="/usr/local/bin:/usr/bin:/bin"
58         [ "$UID" -eq 0 ] && PATH="/usr/local/sbin:/usr/sbin:/sbin:$PATH"
59         export PATH
60 fi
61 # prepend optional directories to PATH ...
62 path=""
63 for d in /Developer/usr/bin /usr/pkg/bin /usr/ucb /usr/lib/ccache /opt/*/bin; 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 if [ "$UID" -eq 0 ]; then
70         path=""
71         for d in /usr/pkg/sbin /opt/*/sbin; do
72                 if [ -d "$d" -o -h "$d" ]; then
73                         [ -e "$d/.not_in_path" ] || path="$path$d:"
74                 fi
75         done
76         [ -n "$path" ] && PATH="$path$PATH"
77 fi
78 # append optional directories to PATH ...
79 for d in /usr/bin/X11 /usr/games /usr/share/php/bin; do
80         if [ -d "$d" -o -h "$d" ]; then
81                 [ -e "$d/.not_in_path" ] || PATH="$PATH:$d"
82         fi
83 done
84 # set PATH so it includes user's private executables
85 [ -d ~/Applications -a ! -e ~/Applications/.not_in_path ] \
86         && PATH=~/Applications:"${PATH}"
87 [ -d ~/bin -a ! -e ~/bin/.not_in_path ] \
88         && PATH=~/bin:"${PATH}"
89 [ -d ~/sbin -a ! -e ~/sbin/.not_in_path ] \
90         && PATH=~/sbin:"${PATH}"
91
92 # Setup MANPATH, if manpath(1) isn't available
93 if [ ! "$(type manpath 2>/dev/null)" ]; then
94         [ -z "$MANPATH" ] \
95                 && MANPATH="/usr/local/share/man:/usr/share/man:/usr/man"
96         path=""
97         for d in /usr/pkg/share/man /usr/pkg/man /opt/*/share/man /opt/*/man; do
98                 [ -d "$d" -o -h "$d" ] && path="$path$d:"
99         done
100         [ -n "$path" ] && MANPATH="$path$MANPATH"
101         [ -d ~/share/man ] && MANPATH=~/share/man:"${MANPATH}"
102         [ -d ~/man ] && MANPATH=~/man:"${MANPATH}"
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 # make sure $UID and $USER is set
110 [ -z "$UID" ] && UID=`id -u`
111 [ -z "$USER" ] && USER=`id -un`
112 export UID USER
113
114 # get my own hostname
115 ME=`hostname 2>/dev/null`
116 export ME
117
118 # Move Xauthority file to local storage, so that sudo et all work
119 if [ -z "$XAUTHORITY" -a -r ~/.Xauthority ]; then
120         cp ~/.Xauthority /tmp/Xauthority-$USER
121         chmod 600 /tmp/Xauthority-$USER
122         export XAUTHORITY="/tmp/Xauthority-$USER"
123 fi
124
125 # read profile additions
126 if [ -d /etc/profile.d -o -d /usr/local/etc/profile.d ]; then
127         for f in /etc/profile.d/* /usr/local/etc/profile.d/*; do
128                 [ -r "$f" ] || continue
129                 case "$f" in
130                         *.csh)
131                                 ;;
132                         *)
133                                 [ -e ~/.ConfigScripts.debug ] \
134                                         && echo " >> $f ..."
135                                 . "$f"
136                 esac
137         done
138 fi
139
140 # read local profile, if available
141 [ -r "/var/lib/${ME}/profile" ] && . /var/lib/${ME}/profile
142
143 # Setup some directories to use local storage (no NFS)
144 [ -d "/usr/local/home/$USER" ] \
145         || ( mkdir /usr/local/home; mkdir "/usr/local/home/$USER" ) >/dev/null 2>&1
146 if [ -w "/usr/local/home/$USER" ]; then
147         export LOCAL_HOME="/usr/local/home/$USER"
148         export CCACHE_DIR="$LOCAL_HOME/.ccache"
149         export XDG_CACHE_HOME="$LOCAL_HOME/.cache"
150 fi
151
152 # interactive shell?
153 [ "$PS1" ] || return
154
155 # validate terminal definition
156 type -p tset >/dev/null 2>&1
157 [ $? -eq 0 ] && eval `tset -s -Q`
158
159 # generic shell prompt
160 [ "$UID" -eq 0 ] \
161         && PS1="<$ME> # " \
162         || PS1="<$ME> \$ "
163
164 # icalBuddy(1)
165 type -p icalBuddy >/dev/null 2>&1
166 if [ $? -eq 0 -a "$UID" -ne 0 ]; then
167         case "$LANG" in
168                 *.UTF*) BUL="•"; SEP="»"; ;;
169                 *)      BUL="*"; SEP=">"; ;;
170         esac
171         icalBuddy -f -n -npn -nc -b " $BUL " -ps "/ $SEP /" -eep "url,notes" \
172                 eventsToday+1 2>/dev/null | grep "$BUL"
173         [ $? -eq 0 ] && echo
174 else
175         # remind(1)
176         type -p remind >/dev/null 2>&1
177         if [ $? -eq 0 -a -r ~/.remind ]; then
178                 remind -h -g -t5 ~/.remind | \
179                         grep -v '^Reminders for ' | grep -v '^$'
180                 [ $? -eq 0 ] && echo
181         fi
182 fi
183
184 # bash-specific initialization
185 [ "$BASH" -a -z "$BASHRCREAD" -a -r /etc/bash.bashrc ] \
186         && source /etc/bash.bashrc
187 [ "$BASH" -a -z "$BASHRCREAD" -a -r /etc/bashrc ] \
188         && source /etc/bashrc
189
190 # ksh-specific initialization
191 [ "$KSH_VERSION" -a -z "$KSHRCREAD" -a -r /etc/ksh.kshrc ] \
192         && . /etc/ksh.kshrc
193
194 # Check filesystem quotas
195 mount 2>/dev/null | grep quota >/dev/null 2>&1
196 if [ $? -eq 0 ]; then
197         which quota >/dev/null 2>&1
198         [ $? -eq 0 ] && quota -q
199 fi
200
201 # -eof-