Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

passing arguments when calling proot-distro login with a command #40

Closed
ronnac opened this issue Nov 26, 2020 · 3 comments
Closed

passing arguments when calling proot-distro login with a command #40

ronnac opened this issue Nov 26, 2020 · 3 comments

Comments

@ronnac
Copy link

ronnac commented Nov 26, 2020

In termux I use a shell script that replaces java, cf. description "workaround for having java in termux" below. It works incredibly well. At its core is the command
proot -R $UBUNTU java "$@"
The only limitation is that I would like to mount some more directories that are not included by the -R switch.
I tried to use proot-distro instead of proot with the following command in the "java" script:
proot-distro login ubuntu-20.04 -- java "$@"
When I run a simple command like java --version this works, too, however I get error messages when I pass lists of quoted arguments.

Here is an example output of a java call that works fine, when I use proot -R $UBUNTU java "$@":

Starting new CIDER session ...
[nREPL] Starting server via /data/data/com.termux/files/usr/var/lib/proot-distro/installed-rootfs/ubuntu-20.04/usr/bin/lein update-in :dependencies conj \[nrepl\ \"0.8.2\"\] -- update-in :plugins conj \[cider/cider-nrepl\ \"0.25.4\"\] -- repl :headless :host localhost
[nREPL] server started on 40408
[nREPL] Establishing direct connection to localhost:40408 ...
[nREPL] Direct connection to localhost:40408 established

Here is an example error, when I use proot-distro login ubuntu-20.04 -- java "$@":

[nREPL] Starting server via /data/data/com.termux/files/usr/var/lib/proot-distro/installed-rootfs/ubuntu-20.04/usr/bin/lein update-in :dependencies conj \[nrepl\ \"0.8.2\"\] -- update-in :plugins conj \[cider/cider-nrepl\ \"0.25.4\"\] -- repl :headless :host localhost
error in process sentinel: nrepl-server-sentinel: Could not start nREPL server:
java.lang.NumberFormatException: Invalid number: 0.8.2
 at clojure.lang.LispReader.readNumber (LispReader.java:352)
    clojure.lang.LispReader.read (LispReader.java:278)
    clojure.lang.LispReader.readDelimitedList (LispReader.java:1398)
    clojure.lang.LispReader$VectorReader.invoke (LispReader.java:1347)
    clojure.lang.LispReader.read (LispReader.java:285)
    clojure.lang.LispReader.read (LispReader.java:216)
    clojure.lang.LispReader.read (LispReader.java:205)
    clojure.lang.RT.readString (RT.java:1878)
    clojure.lang.RT.readString (RT.java:1873)
    clojure.core$read_string.invokeStatic (core.clj:3815)
    clojure.core$read_string.invoke (core.clj:3805)
    clojure.core$mapv$fn__8445.invoke (core.clj:6912)
    clojure.core.protocols$fn__8159.invokeStatic (protocols.clj:168)
    clojure.core.protocols/fn (protocols.clj:124)
    clojure.core.protocols$fn__8114$G__8109__8123.invoke (protocols.clj:19)
    clojure.core.protocols$seq_reduce.invokeStatic (protocols.clj:31)
    clojure.core.protocols$fn__8146.invokeStatic (protocols.clj:75)
    clojure.core.protocols/fn (protocols.clj:75)
    clojure.core.protocols$fn__8088$G__8083__8101.invoke (protocols.clj:13)
    clojure.core$reduce.invokeStatic (core.clj:6828)
    clojure.core$mapv.invokeStatic (core.clj:6903)
    clojure.core$mapv.invoke (core.clj:6903)
    leiningen.update_in$parse_args.invokeStatic (update_in.clj:13)
    leiningen.update_in$parse_args.invoke (update_in.clj:9)
    leiningen.update_in$update_in.invokeStatic (update_in.clj:36)
    leiningen.update_in$update_in.doInvoke (update_in.clj:24)
    clojure.lang.RestFn.applyTo (RestFn.java:146)
    clojure.lang.Var.applyTo (Var.java:705)
    clojure.core$apply.invokeStatic (core.clj:667)
    clojure.core$apply.invoke (core.clj:660)
    leiningen.core.main$partial_task$fn__7330.doInvoke (main.clj:284)
    clojure.lang.RestFn.applyTo (RestFn.java:139)
    clojure.lang.AFunction$1.doInvoke (AFunction.java:31)
    clojure.lang.RestFn.applyTo (RestFn.java:137)
    clojure.core$apply.invokeStatic (core.clj:667)
    clojure.core$apply.invoke (core.clj:660)
    leiningen.core.main$apply_task.invokeStatic (main.clj:334)
    leiningen.core.main$apply_task.invoke (main.clj:320)
    leiningen.core.main$resolve_and_apply.invokeStatic (main.clj:343)
    leiningen.core.main$resolve_and_apply.invoke (main.clj:336)
    leiningen.core.main$_main$fn__7419.invoke (main.clj:453)
    leiningen.core.main$_main.invokeStatic (main.clj:442)
    leiningen.core.main$_main.doInvoke (main.clj:439)
    clojure.lang.RestFn.applyTo (RestFn.java:137)
    clojure.lang.Var.applyTo (Var.java:705)
    clojure.core$apply.invokeStatic (core.clj:665)
    clojure.main$main_opt.invokeStatic (main.clj:514)
    clojure.main$main_opt.invoke (main.clj:510)
    clojure.main$main.invokeStatic (main.clj:664)
    clojure.main$main.doInvoke (main.clj:616)
    clojure.lang.RestFn.applyTo (RestFn.java:137)
    clojure.lang.Var.applyTo (Var.java:705)
    clojure.main.main (main.java:40)

Here is an example error, when I use proot-distro login ubuntu-20.04 -- java "\"$@\"" (escaped quotes around $@) :

Starting new CIDER session ...
[nREPL] Starting server via /data/data/com.termux/files/usr/var/lib/proot-distro/installed-rootfs/ubuntu-20.04/usr/bin/lein update-in :dependencies conj \[nrepl\ \"0.8.2\"\] -- update-in :plugins conj \[cider/cider-nrepl\ \"0.25.4\"\] -- repl :headless :host localhost
error in process sentinel: nrepl-server-sentinel: Could not start nREPL server:
Error occurred during initialization of VM
java.nio.charset.IllegalCharsetNameException: UTF-8 -Dmaven.wagon.http.ssl.easy=false -Dmaven.wagon.rto=10000 -Xbootclasspath/a:/data/data/com.termux/files/home/.lein/self-installs/leiningen-2.9.4-standalone.jar -Xverify:none -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Dleiningen.input-checksum= -Dleiningen.original.pwd=/data/data/com.termux/files/home/cloj-projects/clojupyter-fiddle -Dleiningen.script=/data/data/com.termux/files/usr/var/lib/proot-distro/installed-rootfs/ubuntu-20.04/usr/bin/lein -classpath /data/data/com.termux/files/home/.lein/self-installs/leiningen-2.9.4-standalone.jar clojure.main -m leiningen.core.main update-in :dependencies conj [nrepl
	at java.nio.charset.Charset.checkName(java.base/Charset.java:308)
	at java.nio.charset.Charset.lookup2(java.base/Charset.java:482)
	at java.nio.charset.Charset.lookup(java.base/Charset.java:462)
	at java.nio.charset.Charset.defaultCharset(java.base/Charset.java:608)
	at sun.nio.cs.StreamEncoder.forOutputStreamWriter(java.base/StreamEncoder.java:56)
	at java.io.OutputStreamWriter.<init>(java.base/OutputStreamWriter.java:110)
	at java.io.PrintStream.<init>(java.base/PrintStream.java:110)
	at java.io.PrintStream.<init>(java.base/PrintStream.java:148)
	at java.lang.System.newPrintStream(java.base/System.java:1898)
	at java.lang.System.initPhase1(java.base/System.java:1974)

And finally, here is an example error, when I use proot-distro login ubuntu-20.04 -- java $@ (no quotes around $@):

Wrote /data/data/com.termux/files/home/cider_escaped_quotes.txt
Starting new CIDER session ...
[nREPL] Starting server via /data/data/com.termux/files/usr/var/lib/proot-distro/installed-rootfs/ubuntu-20.04/usr/bin/lein update-in :dependencies conj \[nrepl\ \"0.8.2\"\] -- update-in :plugins conj \[cider/cider-nrepl\ \"0.25.4\"\] -- repl :headless :host localhost
error in process sentinel: nrepl-server-sentinel: Could not start nREPL server: mktemp: failed to create file via template ‘/tmp/lein-trampoline-XXXXXXXXXXXXX’: No such file or directory
java.lang.RuntimeException: EOF while reading
 at clojure.lang.Util.runtimeException (Util.java:221)
    clojure.lang.LispReader.readDelimitedList (LispReader.java:1403)
    clojure.lang.LispReader$VectorReader.invoke (LispReader.java:1347)
    clojure.lang.LispReader.read (LispReader.java:285)
    clojure.lang.LispReader.read (LispReader.java:216)
    clojure.lang.LispReader.read (LispReader.java:205)
    clojure.lang.RT.readString (RT.java:1878)
    clojure.lang.RT.readString (RT.java:1873)
    clojure.core$read_string.invokeStatic (core.clj:3815)
    clojure.core$read_string.invoke (core.clj:3805)
    clojure.core$mapv$fn__8445.invoke (core.clj:6912)
    clojure.core.protocols$fn__8159.invokeStatic (protocols.clj:168)
    clojure.core.protocols/fn (protocols.clj:124)
    clojure.core.protocols$fn__8114$G__8109__8123.invoke (protocols.clj:19)
    clojure.core.protocols$seq_reduce.invokeStatic (protocols.clj:31)
    clojure.core.protocols$fn__8146.invokeStatic (protocols.clj:75)
    clojure.core.protocols/fn (protocols.clj:75)
    clojure.core.protocols$fn__8088$G__8083__8101.invoke (protocols.clj:13)
    clojure.core$reduce.invokeStatic (core.clj:6828)
    clojure.core$mapv.invokeStatic (core.clj:6903)
    clojure.core$mapv.invoke (core.clj:6903)
    leiningen.update_in$parse_args.invokeStatic (update_in.clj:13)
    leiningen.update_in$parse_args.invoke (update_in.clj:9)
    leiningen.update_in$update_in.invokeStatic (update_in.clj:36)
    leiningen.update_in$update_in.doInvoke (update_in.clj:24)
    clojure.lang.RestFn.applyTo (RestFn.java:146)
    clojure.lang.Var.applyTo (Var.java:705)
    clojure.core$apply.invokeStatic (core.clj:667)
    clojure.core$apply.invoke (core.clj:660)
    leiningen.core.main$partial_task$fn__7330.doInvoke (main.clj:284)
    clojure.lang.RestFn.applyTo (RestFn.java:139)
    clojure.lang.AFunction$1.doInvoke (AFunction.java:31)
    clojure.lang.RestFn.applyTo (RestFn.java:137)
    clojure.core$apply.invokeStatic (core.clj:667)
    clojure.core$apply.invoke (core.clj:660)
    leiningen.core.main$apply_task.invokeStatic (main.clj:334)
    leiningen.core.main$apply_task.invoke (main.clj:320)
    leiningen.core.main$resolve_and_apply.invokeStatic (main.clj:343)
    leiningen.core.main$resolve_and_apply.invoke (main.clj:336)
    leiningen.core.main$_main$fn__7419.invoke (main.clj:453)
    leiningen.core.main$_main.invokeStatic (main.clj:442)
    leiningen.core.main$_main.doInvoke (main.clj:439)
    clojure.lang.RestFn.applyTo (RestFn.java:137)
    clojure.lang.Var.applyTo (Var.java:705)
    clojure.core$apply.invokeStatic (core.clj:665)
    clojure.main$main_opt.invokeStatic (main.clj:514)
    clojure.main$main_opt.invoke (main.clj:510)
    clojure.main$main.invokeStatic (main.clj:664)
    clojure.main$main.doInvoke (main.clj:616)
    clojure.lang.RestFn.applyTo (RestFn.java:137)
    clojure.lang.Var.applyTo (Var.java:705)
    clojure.main.main (main.java:40)

workaround for having java in termux

TL;DR
I create an ubuntu proot, where I install the openjdk. Back in termux I create a bash script named "java" which, when called, forwards to the real java within the ubuntu proot by using the proot command.

How
Set up the ubuntu-20.04 proot (more info here):

pkg install proot-distro
proot-distro list #(check ubuntu versions available)
proot-distro install ubuntu-20.04
proot-distro login ubuntu-20.04

Within the ubuntu distro install the openjdk:

apt update
apt upgrade
apt install openjdk-8-jdk

(I suppose this also works with later versions of the openjdk.)

Return to termux (press Ctrl-D)

Add the following line in ~/.bashrc
export UBUNTU=$PREFIX/var/lib/proot-distro/installed-rootfs/ubuntu-20.04/
From the bash or fish prompt you can do this using the following command:
echo "export UBUNTU=\$PREFIX/var/lib/proot-distro/installed-rootfs/ubuntu-20.04/" >> ~/.bashrc
Restart the termux session so that .bashrc is executed and the variable $UBUNTU is set.

Create the script file "java" in ~/../usr/bin/ with the following content:

#!/usr/bin/bash
unset LD_PRELOAD
proot -R $UBUNTU java "$@"

From the fish prompt you can do this using the following command:

echo "#!/usr/bin/bash
unset LD_PRELOAD
proot -R \$UBUNTU java \"\$@\" " >> ~/../usr/bin/java

(I don't know how to do this from the bash prompt)

For more information about the proot command, check the manual.

Make the script "java" executable:
chmod 777 ../usr/bin/java

You can now call java with arguments from termux. I suppose you can do the same trick for javac.

I would be happy to hear about your suggestions for improvement.

Originally posted by @ronnac in termux/termux-packages#324 (comment)

@ronnac
Copy link
Author

ronnac commented Nov 26, 2020

I can get it to work if I change line 710 in proot-distro:

line 710: from
shell_command_args+=("\"$i\"")
to
shell_command_args+=("'$i'") i.e. replace escaped double-quotes by single quotes

@ghost
Copy link

ghost commented Dec 5, 2020

Done in e3d0ffd.

@ghost ghost closed this as completed Dec 5, 2020
@ronnac
Copy link
Author

ronnac commented Dec 5, 2020

Thank you!

@ghost ghost locked and limited conversation to collaborators Oct 9, 2021
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant