Bug 25752 - Current directory not kept when using koha-shell
Summary: Current directory not kept when using koha-shell
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Command-line Utilities (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low major (vote)
Assignee: Jonathan Druart
QA Contact: Tomás Cohen Arazi
URL:
Keywords:
Depends on: 25538
Blocks:
  Show dependency treegraph
 
Reported: 2020-06-15 14:11 UTC by Jonathan Druart
Modified: 2021-12-13 21:08 UTC (History)
7 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
20.11.00, 20.05.02, 19.11.13


Attachments
Bug 25752: Stay in cwd after koha-shell (1.47 KB, patch)
2020-06-15 14:13 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 25752: Stay in cwd after koha-shell (1.53 KB, patch)
2020-06-29 09:53 UTC, Martin Renvoize
Details | Diff | Splinter Review
Bug 25752: Stay in cwd after koha-shell (1.59 KB, patch)
2020-07-03 14:04 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Druart 2020-06-15 14:11:33 UTC
After bug 25538, after a koha-shell we are not longer in the current directory:

root@cec7bffd8100:koha(master)$ pwd                                                                                                                                                                     
/kohadevbox/koha                                                                                                                                                                                                  
root@cec7bffd8100:koha(master)$ sudo koha-shell kohadev                                                                                                                                                 
kohadev-koha@cec7bffd8100:~$ pwd                                                                                                                                                                                  
/var/lib/koha/kohadev
Comment 1 Jonathan Druart 2020-06-15 14:13:39 UTC
Created attachment 105884 [details] [review]
Bug 25752: Stay in cwd after koha-shell

After bug 25538, after a koha-shell we are not longer in the current directory:

root@cec7bffd8100:koha(master)$ pwd
/kohadevbox/koha
root@cec7bffd8100:koha(master)$ sudo koha-shell kohadev
kohadev-koha@cec7bffd8100:~$ pwd
/var/lib/koha/kohadev

Test plan:
Repeat the commands above and confirm that with this version of the
script you get /kohadevbox/koha inside the koha-shell

Search for possible regressions
Comment 2 Martin Renvoize 2020-06-29 09:53:26 UTC
Created attachment 106386 [details] [review]
Bug 25752: Stay in cwd after koha-shell

After bug 25538, after a koha-shell we are not longer in the current directory:

root@cec7bffd8100:koha(master)$ pwd
/kohadevbox/koha
root@cec7bffd8100:koha(master)$ sudo koha-shell kohadev
kohadev-koha@cec7bffd8100:~$ pwd
/var/lib/koha/kohadev

Test plan:
Repeat the commands above and confirm that with this version of the
script you get /kohadevbox/koha inside the koha-shell

Search for possible regressions

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Comment 3 Martin Renvoize 2020-06-29 09:53:55 UTC
Works as expected, no obvious regressions.

Signing off
Comment 4 Jonathan Druart 2020-07-02 14:29:27 UTC
I need it ASAP, maybe it will fix 00-testcritic (?)
Comment 5 Jonathan Druart 2020-07-02 14:49:47 UTC
(In reply to Jonathan Druart from comment #4)
> I need it ASAP, maybe it will fix 00-testcritic (?)

Not related, forget that.
Comment 6 Julian Maurice 2020-07-03 11:18:00 UTC
With this patch,

$ koha-shell
$ pwd

and

$ koha-shell -c 'pwd'

will return different results. Is that expected ?
Comment 7 Jonathan Druart 2020-07-03 13:49:46 UTC
Looks ok for me

With sudo:
root@f62733f90b41:koha(BZ25752)$ sudo koha-shell kohadev
kohadev-koha@f62733f90b41:/kohadevbox/koha$ pwd
/kohadevbox/koha
kohadev-koha@f62733f90b41:/kohadevbox/koha$ exit
root@f62733f90b41:koha(BZ25752)$ sudo koha-shell kohadev -c pwd
/kohadevbox/koha

Without sudo:
root@f62733f90b41:koha(BZ25752)$ koha-shell kohadev
kohadev-koha@f62733f90b41:/kohadevbox/koha$ pwd
/kohadevbox/koha
root@f62733f90b41:koha(BZ25752)$ koha-shell kohadev -c pwd
/kohadevbox/koha
Comment 8 Tomás Cohen Arazi 2020-07-03 14:04:31 UTC
Created attachment 106515 [details] [review]
Bug 25752: Stay in cwd after koha-shell

After bug 25538, after a koha-shell we are not longer in the current directory:

root@cec7bffd8100:koha(master)$ pwd
/kohadevbox/koha
root@cec7bffd8100:koha(master)$ sudo koha-shell kohadev
kohadev-koha@cec7bffd8100:~$ pwd
/var/lib/koha/kohadev

Test plan:
Repeat the commands above and confirm that with this version of the
script you get /kohadevbox/koha inside the koha-shell

Search for possible regressions

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 9 Julian Maurice 2020-07-03 14:07:52 UTC
(In reply to Jonathan Druart from comment #7)
> Looks ok for me
> 
> With sudo:
> root@f62733f90b41:koha(BZ25752)$ sudo koha-shell kohadev
> kohadev-koha@f62733f90b41:/kohadevbox/koha$ pwd
> /kohadevbox/koha
> kohadev-koha@f62733f90b41:/kohadevbox/koha$ exit
> root@f62733f90b41:koha(BZ25752)$ sudo koha-shell kohadev -c pwd
> /kohadevbox/koha
> 
> Without sudo:
> root@f62733f90b41:koha(BZ25752)$ koha-shell kohadev
> kohadev-koha@f62733f90b41:/kohadevbox/koha$ pwd
> /kohadevbox/koha
> root@f62733f90b41:koha(BZ25752)$ koha-shell kohadev -c pwd
> /kohadevbox/koha

Well, of course if you are running koha-shell from the home directory of kohadev-koha, the result will be the same.
Try:
# cd /tmp
# koha-shell -c pwd
# koha-shell
# pwd
Comment 10 Julian Maurice 2020-07-03 14:08:56 UTC
Also, why are you using sudo when you are already root ?
Comment 11 Julian Maurice 2020-07-03 14:19:31 UTC
(In reply to Julian Maurice from comment #9)
> Try:
> # cd /tmp
> # koha-shell -c pwd
> # koha-shell
> # pwd

Forgot the instance name. I meant:

root@localhost# cd /tmp
root@localhost# koha-shell -c pwd kohadev
root@localhost# koha-shell kohadev
koahdev-koha@localhost$ pwd
Comment 12 Jonathan Druart 2020-07-03 16:06:34 UTC
Sorry Julian I cannot retest right now.
$HOME for kohadev-koha is /var/lib/koha/kohadev, that's why we are landing there without this patch.

I tried with sudo to test the behaviour of the 'kshell' alias.
Comment 13 Jonathan Druart 2020-07-09 10:00:03 UTC
root@615331e1369d:koha(master)$ cd /tmp
root@615331e1369d:tmp$ koha-shell -c pwd kohadev
/tmp
root@615331e1369d:tmp$ koha-shell kohadev
kohadev-koha@615331e1369d:/tmp$ pwd
/tmp
Comment 14 Jonathan Druart 2020-07-09 10:06:01 UTC
Pushed to master for 20.11, thanks to everybody involved!
Comment 15 Julian Maurice 2020-07-09 12:12:59 UTC
(In reply to Jonathan Druart from comment #13)
> root@615331e1369d:koha(master)$ cd /tmp
> root@615331e1369d:tmp$ koha-shell -c pwd kohadev
> /tmp
> root@615331e1369d:tmp$ koha-shell kohadev
> kohadev-koha@615331e1369d:/tmp$ pwd
> /tmp

Sorry, I misread the patch. The problem is with the --login option:

# cwd is /home/koha/env/master/src
# user test-koha created by hand so $HOME is different than with package install
% debian/scripts/koha-shell --login -c pwd test
/home/test-koha
% debian/scripts/koha-shell --login test       
% pwd
/home/koha/env/master/src

Compare with sudo:

# cwd is /home/koha/env/master/src
% sudo --login -u test-koha pwd
/home/test-koha
% sudo --login -u test-koha
% pwd
/home/test-koha
Comment 16 Lucas Gass 2020-07-22 17:17:04 UTC
backported to 20.05.x for 20.05.02
Comment 17 Aleisha Amohia 2020-08-03 07:27:15 UTC
I can't seem to reproduce the bug in 19.11.x so I won't backport. Let me know if it does need to be backported.
Comment 18 Victor Grousset/tuxayo 2020-12-11 16:20:32 UTC
I think I remember not having this bug in 19.11.x when I tried it once. But anyone now it's affected.

Backported to 19.11.x branch for 19.11.13