Fork me on GitHub
#babashka
<
2021-11-04
>
Karol Wójcik08:11:00

Does babashka support?

runtime.getShutdown().addShutdownHook()

Karol Wójcik08:11:39

But if this is enabled:

export BABASHKA_DISABLE_SIGNAL_HANDLERS="true"
shutdown hooks doesn't work?

mike_ananev09:11:35

Hello. Recently, I saw an example how to execute local bb script on a remote machine using ssh. Can't find it.

Mno09:11:29

ohh that sounds useful lemme know if you find it

mike_ananev10:11:57

How to enter 'sudo' password locally for command, executed remotely?

mike_ananev10:11:51

I'm trying to execute remotely:

(sh "sudo ls -la /")

borkdude11:11:20

With sh you must separate all arguments: (sh "sudo" "ls" "-la" "/")

borkdude11:11:29

if you don't want this, use babashka.process which tokenizes all arguments automatically for you

mike_ananev11:11:20

(babashka.process/process ["sudo" "ls" "/"] {:out :inherit})
?

borkdude11:11:48

bb -e '(babashka.process/sh "sudo ls -la /")'

borkdude11:11:13

inherit also works of course, it depends if you want to get a string out or print the output immediately

borkdude11:11:49

bb -e '(babashka.process/process "sudo ls -la" {:out :inherit})

borkdude11:11:26

This is actually the same as:

bb -e '(babashka.tasks/shell "sudo ls -la")'

borkdude11:11:39

I'm going to write a blog post about this, because this question comes up too often

mike_ananev11:11:20

Got error: sudo: no tty and program askpass

borkdude11:11:39

this is because sudo is going to ask you interactively for the password I guess

mike_ananev11:11:59

Yes. I want transfer all my bash scripts for program install to babashka scripts. And I need to enter sudo password locally once.

mike_ananev11:11:40

ssh rssys "bb -e '(load-string (slurp in))'" < install.clj

mike_ananev11:11:01

install.clj contains sudo commands

borkdude11:11:26

perhaps you can prepend sudo in your ssh command instead

borkdude11:11:50

ssh [email protected] "sudo bb -e '(load-string (slurp *in*))'" < script.clj

mike_ananev11:11:51

ssh [email protected] "sudo bb -e '(load-string (slurp in))'" < install.clj

mike_ananev11:11:11

the same result: sudo: no tty and program askpass

borkdude11:11:55

can you try ssh -t ?

mike_ananev11:11:01

[email protected]  ~ ssh -t rssys "sudo bb -e '(load-string (slurp *in*))'" < install.clj
Pseudo-terminal will not be allocated because stdin is not a terminal.
sudo: нет tty и не указана программа askpass

borkdude11:11:43

@mike1452 hmm, it works for me:

$ ssh [email protected] "bb -e '(babashka.tasks/shell \"sudo ls -la\")'"
sudo: no tty present and no askpass program specified
Error while executing task:
$ ssh -t [email protected] "bb -e '(babashka.tasks/shell \"sudo ls -la\")'"
[sudo] password for user:

borkdude11:11:38

I see, it's something with stdin:

$ ssh -t  "bb -e '(load-string (slurp *in*))'" <<< '(+ 1 2 3)'
Pseudo-terminal will not be allocated because stdin is not a terminal.
6

borkdude11:11:02

yeah, you can't read from different stdins...

borkdude11:11:17

you need one stdin to read the script and another one to read your password

borkdude11:11:55

so perhaps the script can be done in a different way

borkdude11:11:47

Somehow this doesn't work for me:

SCRIPT="(prn (+ 1 2 3))" ssh -t [email protected] "bb -e $SCRIPT"

borkdude11:11:51

but I think it should

borkdude11:11:55

and then sudo should also work

borkdude11:11:48

I guess interpolation doesn't work on a single line

borkdude11:11:02

$ FOO=1 echo "$FOO"

borkdude11:11:01

@mike1452 got it!

$ SCRIPT=`cat script.clj`; ssh -t [email protected] "bb -e '$SCRIPT'"

borkdude11:11:14

I'll update the wiki with this

mike_ananev09:11:27

@borkdude thank you!

👍 1
🙌 1
borkdude10:11:36

For now I'll bump babashka to GraalVM 21.3.0 JDK 11 and hope GraalVM will solve https://github.com/oracle/graal/issues/3225 so I can strip some classes when upgrading to JDK 17.

lispyclouds10:11:57

@borkdude for the linux static failure in the last build in ci, maybe adding a ln -s /usr/bin/musl-gcc /usr/bin/x86_64-linux-musl-gcc after https://github.com/babashka/babashka/blob/master/script/setup-musl#L15 could solve it? I think thats the new executable they are looking for now?

borkdude10:11:35

see fix-musl branch ;)

borkdude13:11:38

@U9ES37CSZ ^ this might be interesting for you perhaps

🙏 1
mynomoto20:11:17

I'm trying to create a bb task to setup clj-kondo by linting the dependencies. (shell "clj-kondo --lint \"$(clojure -A:test-deps -Spath)\" --dependencies --parallel --copy-configs") is not working, it prints nothing and exits. The command works on the terminal (minus escaped quotes).

Bob B21:11:31

I don't know that sub-shelling works in shell. (shell "echo \"$(clojure -Spath)\"") just echoes the literal string for me

mynomoto21:11:27

Yeah, i just added a shell script to run that command and call it from bb. Thanks!

borkdude21:11:42

@U05094X3J yeah, shelling out doesn't mean you're invoking bash. it's best to invoke clojure -A:test-deps -Spath as another step and then just feed that input back into the other command

mynomoto21:11:33

Ok, thanks.

borkdude21:11:14

{:tasks
 {lint (let [cp (with-out-str (clojure "-Spath"))]
         (shell "clj-kondo --lint" cp))}}

👏 1
Bob B21:11:30

and if I'm not mistaken, the --dependencies switch causes clj-kondo to not report anything, right?

mynomoto21:11:12

When you already have a cache it reports that the dependency was already linted.

mynomoto21:11:51

(let [cp (with-out-str (clojure "-A:test-deps -Spath"))]
  (shell "clj-kondo --lint" cp "--dependencies --parallel --copy-configs"))

mynomoto21:11:07

Should this work? Seems to be ignoring the later options.

borkdude21:11:15

@U05094X3J after the first string you probably have to tokenize the arguments yourself into separate strings

borkdude21:11:43

"--dependencies" "--parallel" "--copy-configs"

mynomoto21:11:03

Oh, it cannot be mixed. Thanks.

mynomoto21:11:54

This is great, it's working!

borkdude21:11:54

(shell <some complex string which is split for you> <additional> <separate> <strings>)

mynomoto21:11:00

Is it the same for clojure?

mynomoto21:11:18

Ok, thank you!

borkdude21:11:34

in doubt you can also use babashka.process/tokenize to split strings into separate ones