Is there a way to get that fs/delete
function to work using a relative path? Something like this:
(shell/with-sh-dir root-dir
(fs/delete (fs/path "foo")))
clojure.java.shell
and babashka.fs
are two different libraries, with-sh-dir
doesn't affect fs/delete
if you want to do this, you'll have to use (fs/delete (fs/path root-dir "foo"))
Is there a way for me to create a single exe out of babashka + my scripts (perhaps cli-matic based) .. I want to do this because I want to distribute a tool to some of the engineers to execute certain commands against our production cluster (with a single file its convenient, just put it in path). They have permissions and everything, the scripts just simplify certain flows. I found this: https://github.com/MnRA/nativity which I will give it a try. I was wondering if there's some in-built way of doing so.
For a single file uberscript might be useful, right? https://book.babashka.org/#_uberscript
yes, but then you still need babashka to execute it. I think @verma wants a single executable with all sources included
Another approach: https://gist.github.com/thiagokokada/115b2588ff65a48d54b8832488801c92
This gist downloads Babashka to $HOME/.bb
, if it doesn't exist, and re-exec the file as a Babashka script
Combine this with uberscript
and you should have a Babashka script that runs anywhere
(Well, anywhere that have curl
installed at least)
Very nice, thanks for all the insights, much appreciated. I will take a look at these sources and see what I come up with π
You could convert your script to a GraalVM project but I think just letting them download babashka is the easiest
worked like a charm, thanks!
Hi all, @borkdude will be talking about Babashka tasks at the London Clojurians meetup in July https://www.meetup.com/London-Clojurians/events/278466747/
@borkdude install script failed on one of my systems because of the default_download_dir="/tmp"
as on the system there is no write access to /tmp
I was wondering if you could do 1) use TMPDIR
environment variable (as described https://en.wikipedia.org/wiki/TMPDIR) 2) allow option to specify location for temporary files 3) both 1 and 2. Should I open ticket for it?
@ales.najmann the script has a --download-dir
option
oh, you're right... my bad! good
but we could actually change the default to $TMPDIR
, that's probably better, I will do that now
don't do it just yet
there is issue that some of distros actualy don't set it up... so it's one of those cases wher POSIX tells something, but systems don't respect it generally
I think it's ok to not have a support for this... as I can always say: --download-dir=$TMPDIR from the outside
yeah, we can choose ${TMPDIR:-/tmp}
Debian don't set TMPDIR it seems, also Arch don't have it
yes, so it defaults to /tmp/
is TMPDIR is not there
yeah, as a default above would be great
btw if you're interested what I wanted to try... I wanted to install bb to Termux on Android
Did you have a chance to try it in this environment?
applied the change. no, I haven't tried it
you must use the aarch64 binary there I believe?
Ok. I'll try and let you know if it works π yes, aarch64 binary has to be used.
the install script does that automatically
if it doesn't work, try the --static
option
oh oh
this won't work π
~$ ./bb
Bad system call
(with static linking)
With normal binary, it doesn't see it as executable
this might be the glibc stuff
yeah, on Android there is no glibc
if GraalVM supported linking with musl on aarch64 then this would be no problem, but it currently doesn't cc @thiagokokada @rahul080327
they have Bionic
if I remember correctly, which is something similar to musl
you could read in this topic: https://github.com/babashka/babashka/issues/241#issuecomment-804721420
π
at least the one thing with TMPDIR comes out of it. That already pleases my β€οΈ
This sums the differences pretty well: https://wiki.termux.com/wiki/Differences_from_Linux
so yeah... not everything is shinny and beatiful π
> if GraalVM supported linking with musl on aarch64 maybe if its possible to get a graal to just emit the object file for aarch64, not do the full link, MAYBE we could figure out the rest of the linkage with musl.a for aarch64 instead of letting graal do the link. in theory this should work
very very off the top of my head, very possible none of it works π
you can emit more info with --native-image-info
and see all the c/c++ stuff it does
good weekend project for me it seems
or just wait for Graal to support it ;)
Hmm, I'm seeing a new --target
argument:
--target selects native-image compilation target (in <OS>-<architecture>
format). Defaults to host's OS-architecture pair.
does this mean it now supports cross-compilation? ;)
one can hope!
I don't think so, but I wonder what it's for
@ales.najmann did you manage to run bb in Termux?
if you're getting Bad system call
, then first try running termux-chroot
command and then execute bb
. It might help (it did for me - Android 10.
@brdloush ok, it works... thank you fellow citizen! π
No problem. Now tell me what's your plan with bb on termux π. I have a feeling that having an option to execute bb
on your android phone/tablet (via termux) might be opening a huge amount of new possibilities. But I haven't discovered them yet π. Tried running http server from @holyjak and it works flawlessly. It even opens a chrome browser and navigates to the server page.
well, well. I'm still just playing around with Clojure and Babashka is just another option to explore Lisp world.
@borkdude About the TMPDIR
issue. Maybe it is better to create the temporary directory using mktemp
instead. At least on Linux, it does the correct thing. From the documentation:
if DIR is not specified, use $TMPDIR if set, else /tmp
@ales.najmann I don't think this is the issue of linking with glibc, I think this is a SELinux issue
https://github.com/MasterDevX/Termux-Java/issues/3#issuecomment-548653884
To fix it, install proot
, run proot -0
and try to run ./bb
again
@thiagokokada I believe you, it makes sense.
> Maybe it is better to create the temporary directory usingΒ mktempΒ instead. Looking at the macOS manpage it also seems to do the correct thing there: https://ss64.com/osx/mktemp.html > mktemp will generate a template string based on the prefix and the CSDARWIN_USER_TEMP_DIR configuration variable if available. Fallback locations if CSDARWIN_USER_TEMP_DIR is not available are TMPDIR and /tmp. I can open a PR if you want
Can you test it @ales.najmann? I remember testing it in the past, not sure if this is still the fix. But maybe if this is really "the fix" for now, we could document this somewhere
mktemp seems to be available on Termux, so it can be used I believe
btw it even works on Windows if I install Busybox on it π
but I just destroyed quite a lot of shims in my scoop environment π
(thank you busybox!)
TIL, surprised to discover that mktemp
is not POSIX, but seems to be supported everywhere we care: https://stackoverflow.com/a/2792789
(Also, coreutils, busybox and toybox includes it, so pretty much any Linux distribution will have it too)
Just need to take care about the flags, but -d
flag seems to be supported anywhere (the flag we care for this case)
PR welcome
well mktemp
makes a temporary file rather than a directory right
ah -d
creates a dir? perfect
perhaps make a fallback to just ${TMPDIR:-/tmp}
if mktemp
cannot be found
This will be the most solid install script ever ;)
SELinux ready I would say. Babashka can be now installed with curl on nuclear power plan without any concerns π
@thiagokokada I assume you tested the script locally.. correct?
is there a PR?
I need to debug some of the http requests I'm making with http-kit.client bundled with babashka - is there a way to pass the `
-Djavax.net.debug=all
flag somehow?@lukaszkorecki you should be able to pass JVM opts as the first args to bb
Yeah, for Linux
NixOS
ok, if @ales.najmann gives the OK, I'll merge :)
Let me check, I think I tried that before
it depends on when programs read this variable whether it's being picked up
This script is btw a remarkable example of why bb
exists in the first place π
Ah I see - I included it after args passed to bb
π€¦
it seems to work here:
$ bb -Djavax.net.debug=all -e '(do @(org.httpkit.client/get "<https://clojure.org>") nil)'
lots of info printed
Yep!
wow, there is even a fix for a bug with move from bb to bb.old right?
Ah, bummer - the option works, but it's not what I need - this only prints SSL/TLS diagnostic info, I just need to debug the actual request being sent
it looks good to me. nice bash skills.
@lukaszkorecki does httpkit document that this option should work for debugging its request?
I assume this isn't included in bb: https://clojars.org/http-kit.debug
merged.
@borkdude nothing in http-kit docs. It's ok, I can switch to regular Clojure to verify what's going on
beauty of babashka
yeah, I recommend doing that. I wasn't aware of http-kit.debug
it works in Termux, backup of old version done π
nice
> This script is btw a remarkable example of whyΒ bbΒ exists in the first place Yeah, exactly I have a similar script to bootstrap Babashka automatically in a project of mine. It is three times bigger than the rest of the init code of the project, most by trying to make it "safe"
Just a correction: the "Bad system call" issue is related to seccomp
enforcement on newer Android versions, not SELinux
: https://toybox.landley.narkive.com/v0fQYJw7/android-o-xargs-bad-system-call#post8
And using termux-chroot
seems to be better than proot -0
(it is available by installing the same package)
TIL, this works:
$ curl <https://github.com/babashka/babashka/releases/download/v0.4.3/babashka-0.4.3-linux-aarch64-static.tar.gz> -LO
$ tar xfv babashka-0.4.3-linux-aarch64-static.tar.gz
$ time qemu-aarch64 ./bb -e "(+ 1 2)"
3
qemu-aarch64 ./bb -e "(+ 1 2)" 0.19s user 0.03s system 106% cpu 0.201 total
And it is not even that slowSince I can't edit the Wiki to add this, here is a documentation about this part:
# Running Babashka on Android with Termux
You can run the static builds of Babashka on Android inside Termux. However if you're using Android 8.0+, you may have the following error while trying to run them:
`
$ ./bb
Bad system call
`
This happens because of `seccomp` rules enforcement on newer versions of Android, as can be seem on [this link](<https://toybox.landley.narkive.com/v0fQYJw7/android-o-xargs-bad-system-call#post8>).
As a workaround, you can run Babashka inside `proot`, an user-space implementation of `chroot`. To do this, run:
`
$ pkg install proot
$ termux-chroot
$ ./bb
`
Note that only basic functionality was tested and this is completely unsupported.
@borkdude Do you think it makes sense to add that on the Wiki :thinking_face: ?
It might be better to add this to http://book.babashka.org?
Maybe under "recipes"
or yeah, since this is experimental, let's do the wiki. or you can just post it on Github discussions
btw, I opened the wiki now
Done