* Change directory on invocation of zsh
@ 2004-10-16 21:39 Michael Prokop
2004-10-17 3:56 ` Bart Schaefer
0 siblings, 1 reply; 5+ messages in thread
From: Michael Prokop @ 2004-10-16 21:39 UTC (permalink / raw)
To: zsh-users
Hello,
I'm using the latest zsh version of debian unstable (4.2.1).
I'm using rungetty on one of my systems.
My /etc/inittab looks like this:
1:12345:respawn:/bin/zsh --login -c "/usr/bin/grml-start ; /usr/bin/grml-screen" >/dev/tty1 2>&1 </dev/tty1
[...]
5:2345:respawn:/sbin/rungetty tty5 -u grml -g grml --autologin grml /bin/zsh
So I'm able to use autologin without doing login stuff.
My problem: when starting zsh my working directory is '/'.
Not just as user root but also as user 'grml'.
AFAIK the pam_env module is responsible for doing some basic
enviroment handling. Because I don't use the PAM system I've a
little wrapper in my zsh config:
,---- [ /etc/zsh/zshrc ]
| if [[ -z "$HOME" || "$HOME" == "/" ]] ; then
| if [[ `id -un` == "root" ]] ; then
| export HOME=/root
| else
| export HOME=/home/`id -un`
| fi
| fi
`----
Of course running 'cd' or 'cd $HOME' or 'cd ~' changes into my
homedirectory. But I'd like to change path already on login.
Doing something like '[ $SECONDS == "0" ] && cd $HOME' is a
workaround but changes the working directory to $HOME any time I'm
starting a new zsh. Am I on the wrong way?
Any ideas or any hints? Thanks!
thx && regards,
(-: Michael
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Change directory on invocation of zsh
2004-10-16 21:39 Change directory on invocation of zsh Michael Prokop
@ 2004-10-17 3:56 ` Bart Schaefer
2004-10-17 14:45 ` Michael Prokop
0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2004-10-17 3:56 UTC (permalink / raw)
To: Michael Prokop; +Cc: zsh-users
On Sat, 16 Oct 2004, Michael Prokop wrote:
> little wrapper in my zsh config:
>
> ,---- [ /etc/zsh/zshrc ]
Why zshrc rather than zshenv? The wrong ~/.zshenv will be loaded if $HOME
is not set correctly before the end of the global zshenv.
> | if [[ -z "$HOME" || "$HOME" == "/" ]] ; then
> | if [[ `id -un` == "root" ]] ; then
> | export HOME=/root
> | else
> | export HOME=/home/`id -un`
> | fi
> | fi
> `----
Using `id -un` there, particularly twice, should not be necessary. E.g.,
if (( EUID == 0 )); then
export HOME=/root
else
export HOME=/home/$LOGNAME
fi
> Of course running 'cd' or 'cd $HOME' or 'cd ~' changes into my
> homedirectory. But I'd like to change path already on login.
So whether HOME is set correctly (before executing the above snippet) has
nothing to do with whether the current directory is "/" ? I would expect
the two conditions to be related, e.g.,
if [[ -z "$HOME" || "$HOME" == "/" ]] ; then
# ... export $HOME correctly, then ...
cd
fi
Or is there some reason you don't want to have the "cd" in the global
config?
> Doing something like '[ $SECONDS == "0" ] && cd $HOME' is a
> workaround but changes the working directory to $HOME any time I'm
> starting a new zsh. Am I on the wrong way?
How about something like
if [[ -z "$ALREADY_DID_CD_HOME" ]]; then
export ALREADY_DID_CD_HOME=$HOME
cd
fi
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Change directory on invocation of zsh
2004-10-17 3:56 ` Bart Schaefer
@ 2004-10-17 14:45 ` Michael Prokop
2004-10-17 16:26 ` Bart Schaefer
0 siblings, 1 reply; 5+ messages in thread
From: Michael Prokop @ 2004-10-17 14:45 UTC (permalink / raw)
To: zsh-users
Bart, thanks a lot for your fast reply!
* Bart Schaefer <schaefer@brasslantern.com> [20041017 10:13]:
> On Sat, 16 Oct 2004, Michael Prokop wrote:
> > little wrapper in my zsh config:
> > ,---- [ /etc/zsh/zshrc ]
> Why zshrc rather than zshenv? The wrong ~/.zshenv will be loaded if $HOME
> is not set correctly before the end of the global zshenv.
Upps. Corrected, thanks.
> > | if [[ -z "$HOME" || "$HOME" == "/" ]] ; then
> > | if [[ `id -un` == "root" ]] ; then
> > | export HOME=/root
> > | else
> > | export HOME=/home/`id -un`
> > | fi
> > | fi
> > `----
> Using `id -un` there, particularly twice, should not be necessary. E.g.,
> if (( EUID == 0 )); then
> export HOME=/root
> else
> export HOME=/home/$LOGNAME
> fi
Thanks.
It seems to work on the "last tty", but on the other ones I'm getting:
/etc/zsh/zshrc:cd:22: no such file or directory: /home/LOGIN
$ echo $LOGNAME
LOGIN
$ whoami
grml
$ id -un
grml
I can't find the reason for this behaviour (inittab entries are the
same and behaviour seems to change when booting system serveral
times), but using `id -un` instead of $LOGNAME seems to fix it.
> > Of course running 'cd' or 'cd $HOME' or 'cd ~' changes into my
> > homedirectory. But I'd like to change path already on login.
> So whether HOME is set correctly (before executing the above snippet) has
> nothing to do with whether the current directory is "/" ? I would expect
> the two conditions to be related, e.g.,
> if [[ -z "$HOME" || "$HOME" == "/" ]] ; then
> # ... export $HOME correctly, then ...
> cd
> fi
> Or is there some reason you don't want to have the "cd" in the global
> config?
Ah, ok - I see what you mean. Yes, seems to be related.
> > Doing something like '[ $SECONDS == "0" ] && cd $HOME' is a
> > workaround but changes the working directory to $HOME any time I'm
> > starting a new zsh. Am I on the wrong way?
> How about something like
> if [[ -z "$ALREADY_DID_CD_HOME" ]]; then
> export ALREADY_DID_CD_HOME=$HOME
> cd
> fi
Oh, my thinking was too complicated. :)
Thanks Bart, works like a charme!
thx && regards,
(-: Michael
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Change directory on invocation of zsh
2004-10-17 14:45 ` Michael Prokop
@ 2004-10-17 16:26 ` Bart Schaefer
2004-10-17 18:55 ` Michael Prokop
0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2004-10-17 16:26 UTC (permalink / raw)
To: Michael Prokop; +Cc: zsh-users
On Sun, 17 Oct 2004, Michael Prokop wrote:
> * Bart Schaefer <schaefer@brasslantern.com> [20041017 10:13]:
> > if (( EUID == 0 )); then
> > export HOME=/root
> > else
> > export HOME=/home/$LOGNAME
> > fi
>
> /etc/zsh/zshrc:cd:22: no such file or directory: /home/LOGIN
> $ echo $LOGNAME
> LOGIN
Hm. This means that one of the following occurred:
- getlogin() returned "LOGIN"
- getlogin() returned empty or null, and getpwuid() returned an entry for
the user named "LOGIN"
I'd have to guess this is a side-effect of autologin? Does it run as the
user "LOGIN"?
> I can't find the reason for this behaviour (inittab entries are the
> same and behaviour seems to change when booting system serveral
> times), but using `id -un` instead of $LOGNAME seems to fix it.
If you can't figure out how to get it to be consistent, I'd suggest adding
to /etc/zsh/zshenv this snippet:
[[ $LOGNAME == LOGIN ]] && LOGNAME=$(id -un)
Do that before the EUID/HOME snippet. Other things may be depending on
LOGNAME being set correctly, too.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Change directory on invocation of zsh
2004-10-17 16:26 ` Bart Schaefer
@ 2004-10-17 18:55 ` Michael Prokop
0 siblings, 0 replies; 5+ messages in thread
From: Michael Prokop @ 2004-10-17 18:55 UTC (permalink / raw)
To: zsh-users
* Bart Schaefer <schaefer@brasslantern.com> [20041017 18:28]:
> On Sun, 17 Oct 2004, Michael Prokop wrote:
> > * Bart Schaefer <schaefer@brasslantern.com> [20041017 10:13]:
> > > if (( EUID == 0 )); then
> > > export HOME=/root
> > > else
> > > export HOME=/home/$LOGNAME
> > > fi
> > /etc/zsh/zshrc:cd:22: no such file or directory: /home/LOGIN
> > $ echo $LOGNAME
> > LOGIN
> Hm. This means that one of the following occurred:
> - getlogin() returned "LOGIN"
> - getlogin() returned empty or null, and getpwuid() returned an entry for
> the user named "LOGIN"
[.../rungetty-1.2]$ grep LOGIN rungetty.c
#ifndef _PATH_LOGIN
#define _PATH_LOGIN "/bin/login"
#define LOGIN " login: " /* login prompt */
strncpy (ut.ut_user, "LOGIN", sizeof (ut.ut_user));
ut.ut_type = LOGIN_PROCESS;
write (1, LOGIN, sizeof (LOGIN) - 1);
execl (_PATH_LOGIN, _PATH_LOGIN, "-f", autologin_name, NULL);
execl (_PATH_LOGIN, _PATH_LOGIN, "--", logname, NULL);
error ("%s: can't exec " _PATH_LOGIN ": %s", tty, sys_errlist[errno]);
[.../rungetty-1.2]$
> I'd have to guess this is a side-effect of autologin? Does it run as the
> user "LOGIN"?
This seems to be a side-effect of rungetty's autologin, yes.
rungetty should run as user root or as the user specified in
/etc/inittab, in my case this is user 'grml':
4:2345:respawn:/sbin/rungetty tty4 -u grml -g grml --autologin grml /bin/zsh
I'm in contact with the debian maintainer of the rungetty-package.
> > I can't find the reason for this behaviour (inittab entries are the
> > same and behaviour seems to change when booting system serveral
> > times), but using `id -un` instead of $LOGNAME seems to fix it.
> If you can't figure out how to get it to be consistent, I'd suggest adding
> to /etc/zsh/zshenv this snippet:
> [[ $LOGNAME == LOGIN ]] && LOGNAME=$(id -un)
> Do that before the EUID/HOME snippet. Other things may be depending on
> LOGNAME being set correctly, too.
Thanks, works like a charme!
regards,
(-: Michael
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-10-17 19:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-16 21:39 Change directory on invocation of zsh Michael Prokop
2004-10-17 3:56 ` Bart Schaefer
2004-10-17 14:45 ` Michael Prokop
2004-10-17 16:26 ` Bart Schaefer
2004-10-17 18:55 ` Michael Prokop
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).