fsquillace / junest

The lightweight Arch Linux based distro that runs, without root privileges, on top of any other Linux distro.
GNU General Public License v3.0
2.08k stars 111 forks source link

bind directory by JUNEST_ARGS #262

Closed tshu-w closed 3 years ago

tshu-w commented 3 years ago

I was wondering if there could be a way to bind the directory via JUNEST_ARGS or something else. Right now I have it set up like this but it doesn't work

export JUNEST_ARGS="ns --fakeroot -b \"--bind $XDG_RUNTIME_DIR $XDG_RUNTIME_DIR\""
tshu-w commented 3 years ago

More generally, I need to know how to avoid path problems, such as trash-cli not being able to delete files in non-HOME directories, emacsclient not being able to access the server in $XDG_RUNTIME_DIR

fsquillace commented 3 years ago

Hello, can you provide a full example here. I am not able to follow the problem.

JUNEST_ARGS is used for this purpose which I think is different from your case. If you want to specify binds this should work: junest ns --fakeroot -b "--bind $XDG_RUNTIME_DIR $XDG_RUNTIME_DIR".

tshu-w commented 3 years ago

@fsquillace I'm sorry for the unclear description. What I want is to run JuNest installed programs directly from the host OS. Most of the commands worked well, but I ran into some problems:

  1. trash-cli: I cannot trash files not in HOME and I got trash: cannot trash non existent 'emacs'
  2. emacsclint: it cannot find emacs server file and I got emacsclient: socket-name /run/user/1006/emacs/server... too long

I think the problem is that the directory is not bound because junest ns --fakeroot -b "--bind /run /run" -- emacsclient does work for me. Then I had hoped to bind some common paths by modifying JUNEST_ARGS so that I could still use emacsclient directly, since I wrote a script and didn't want to change them all.

fsquillace commented 3 years ago

Perfect thanks @tshu-w! I am wondering if the problem is due to some quotes or using the variable $XDG_RUNTIME_DIR. Can you try without $XDG_RUNTIME_DIR and use /run instead?

In the next days I will try to find time to reproduce such bug.

tshu-w commented 3 years ago

I am wondering if the problem is due to some quotes or using the variable $XDG_RUNTIME_DIR

Actually, it's because "--bind $XDG_RUNTIME_DIR $XDG_RUNTIME_DIR" is split into three args: '"--bind' $XDG_RUNTIME_DIR '$XDG_RUNTIME_DIR"'

tshu-w commented 3 years ago

Default bindings to common directories such as /tmp $XDG_RUNTIME_DIR would be appreciated, or the user can set the bindings via variables.

fsquillace commented 3 years ago

I reproduced the bug. This is due to the bash quotes nightmare. I show it with a toy example:

function myfunc() {

    for arg in "$@"
    do
        echo "$arg"
    done
}

myfunc arg1 "arg2 with space"

export ARGS="arg1 'arg2 with space'"
myfunc $ARGS

The two calls to myfunc should return the same but instead they are different:

The second call break down the second argument in multiple arguments which is wrong. I do not know how to solve this in an elegant way. Any help is appreciated :)

tshu-w commented 3 years ago

@fsquillace According to this answer https://stackoverflow.com/a/30087910, you can use arrays or xargs. or create a new array variable as a binding for the directory

fsquillace commented 3 years ago

Thanks @tshu-w I tried both but it is quite hard to use them for such use case. It is not possible to export arrays therefore the variable JUNEST_ARGS used to change the behavior of the wrappers cannot be an array. I used xargs too but it is quite hard to make it right too.

tshu-w commented 3 years ago

It is not possible to export arrays therefore the variable JUNEST_ARGS used to change the behavior of the wrappers cannot be an array.

I don't really understand here, I haven't read the code, but I think the wrapper was generated by you by some means, in that case why can't it be changed to an array?

fsquillace commented 3 years ago

The user is the one passing the variable JUNEST_ARGS, that variable has to be an array to solve the issue in the first place before that the variable gets read by the wrapper.

tshu-w commented 3 years ago

@fsquillace It seem like we cannot pass array to scripts. But I change emacsclient wrapper to the following:

#!/usr/bin/env bash

JUNEST_ARGS=${JUNEST_ARGS:-ns --fakeroot}

echo $JUNEST_ARGS | xargs -i sh -c "junest {} -- emacsclient $@"

with JUNEST_ARGS equal to 'ns --fakeroot -b \"--bind /run /run\"'and now it works!

tshu-w commented 3 years ago

@fsquillace It seems like bash -c "junest $JUNEST_ARGS -- emacsclient $@" will do the trick

fsquillace commented 3 years ago

I think I solved the issue by using the eval bash builtin inside the wrapper file. For example, the bash wrapper is:

>> cat ~/.junest/usr/bin_wrappers/bash
#!/usr/bin/env bash

JUNEST_ARGS=${JUNEST_ARGS:-ns --fakeroot}

eval junest ${JUNEST_ARGS} -- bash "$@"
>> export JUNEST_ARGS="ns --fakeroot -b '--bind /run /run2'"
>> ~/.junest/usr/bin_wrappers/bash
[root@myarch junest]# ls /
bin  boot  dev  etc  home  lib  lib64  mnt  opt  proc  root  run  run2  sbin  srv  sys  tmp  usr  var

@tshu-w Can you verify that it works also for you?

tshu-w commented 3 years ago

@fsquillace Thx, it works!

fsquillace commented 3 years ago

Great, I pushed the change into master branch. You can checkout the latest commits and try. Remember to remove all the existing wrappers so that they will be recreated again once you access to a JuNest session:

rm -rf ~/.junest/usr/bin_wrappers
junest         # Recreates the wrappers with eval in it

Thanks for catching this bug!