zshenv, zshrc: add fallback to uname for HOSTNAME
[grml-etc-core.git] / etc / zsh / zshenv
1 # Filename:      zshenv
2 # Purpose:       system-wide .zshenv file for zsh(1)
3 # Authors:       grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
4 # Bug-Reports:   see http://grml.org/bugs/
5 # License:       This file is licensed under the GPL v2.
6 ################################################################################
7 # This file is sourced on all invocations of the shell.
8 # It is the 1st file zsh reads; it's read for every shell,
9 # even if started with -f (setopt NO_RCS), all other
10 # initialization files are skipped.
11 #
12 # This file should contain commands to set the command
13 # search path, plus other important environment variables.
14 # This file should not contain commands that produce
15 # output or assume the shell is attached to a tty.
16 #
17 # Notice: .zshenv is the same, execpt that it's not read
18 # if zsh is started with -f
19 #
20 # Global Order: zshenv, zprofile, zshrc, zlogin
21 ################################################################################
22
23 # language settings (read in /etc/environment before /etc/default/locale as
24 # the latter one is the default on Debian nowadays)
25 # no xsource() here because it's only created in zshrc! (which is good)
26 [[ -r /etc/environment ]] && source /etc/environment
27
28 # set environment variables (important for autologin on tty)
29 if [ -n "${HOSTNAME}" ] ; then
30   export HOSTNAME="${HOSTNAME}"
31 elif [[ -x $(which hostname) ]] ; then
32   export HOSTNAME="$(hostname)"
33 elif [[ -x $(which hostnamectl) ]] ; then
34   export HOSTNAME="$(hostnamectl --static)"
35 else
36   export HOSTNAME="$(uname -n)"
37 fi
38
39 # make sure /usr/bin/id is available
40 if [[ -x /usr/bin/id ]] ; then
41     [[ -z "$USER" ]]          && export USER=$(/usr/bin/id -un)
42     [[ $LOGNAME == LOGIN ]] && LOGNAME=$(/usr/bin/id -un)
43 fi
44
45 # workaround for live-cd mode as $HOME is not set via rungetty
46 if [[ -f /etc/grml_cd ]] ; then
47     if (( EUID == 0 )); then
48         export HOME=/root
49     else
50         export HOME=/home/$USER
51     fi
52 fi
53
54 ## set $PATH
55 # gentoo users have to source /etc/profile.env
56 if [[ -r /etc/gentoo-release ]] ; then
57     [[ -r /etc/profile.env ]] && source /etc/profile.env
58 fi
59
60 # support extra scripts/software in special directory outside of squashfs environment in live mode
61 if [[ -f /etc/grml_cd ]] ; then
62   [[ -r /run/live/medium/scripts ]] && ADDONS='/run/live/medium/scripts'
63   [[ -r /etc/grml/my_path ]] && ADDONS="$(cat /etc/grml/my_path)"
64 fi
65
66 # Solaris
67 case $(uname 2>/dev/null) in
68   SunOS)
69     path=(
70       /usr/bin
71       /usr/sbin
72       /usr/ccs/bin
73       /opt/SUNWspro/bin
74       /usr/ucb
75       /usr/sfw/bin
76       /usr/gnu/bin
77       /usr/openwin/bin
78       /opt/csw/bin
79       /sbin
80       ~/bin
81     )
82 esac
83
84 # generic $PATH handling
85 if (( EUID != 0 )); then
86   path=(
87     $HOME/bin
88     /usr/local/bin
89     /usr/bin
90     /bin
91     /usr/local/sbin
92     /usr/sbin
93     /sbin
94     /usr/local/games
95     /usr/games
96     "${ADDONS}"
97     "${path[@]}"
98   )
99 else
100   path=(
101     $HOME/bin
102     /usr/local/sbin
103     /usr/local/bin
104     /sbin
105     /bin
106     /usr/sbin
107     /usr/bin
108     "${ADDONS}"
109     "${path[@]}"
110   )
111 fi
112
113 # remove empty components to avoid '::' ending up + resulting in './' being in $PATH
114 path=( "${path[@]:#}" )
115
116 typeset -U path
117
118 # less (:=pager) options:
119 #  export LESS=C
120 typeset -a lp; lp=( ${^path}/lesspipe(N) )
121 if (( $#lp > 0 )) && [[ -x $lp[1] ]] ; then
122     export LESSOPEN="|lesspipe %s"
123 elif [[ -x /usr/bin/lesspipe.sh ]] ; then
124     export LESSOPEN="|lesspipe.sh %s"
125 fi
126 unset lp
127
128 export READNULLCMD=${PAGER:-/usr/bin/pager}
129
130 # allow zeroconf for distcc
131 export DISTCC_HOSTS="+zeroconf"
132
133 # MAKEDEV should be usable on udev as well by default:
134 export WRITE_ON_UDEV=yes
135
136 ## END OF FILE #################################################################
137 # vim:filetype=zsh foldmethod=marker autoindent expandtab shiftwidth=4