2

I'd like to automize a build process which involves getting some code from an svn repository. The server certificate is not automatically trusted.

Things that I tried but that don't work:

  1. svn checkout --non-interactive --trust-server-cert --username name --password password --no-auth-cache -r revision https://server.address/trunk/

results in

svn: E230001: Server SSL certificate verification failed: certificate has expired, issuer is not trusted

  1. echo "t" | svn checkout --username name --password password --no-auth-cache -r revision https://server.address/trunk/

results in the same result

svn: E230001: Server SSL certificate verification failed: certificate has expired, issuer is not trusted

however when using

svn checkout --username name --password password --no-auth-cache -r revision https://server.address/trunk/

then the dialog (R)eject or accept (t)emporarily? appear, and when pressing 't' the source gets fetched.

Particularly the manual method and the echo "t"-method confuses me, because it should actually be the same thing. Has anybody an explanation for this or knows a solution that could work?

1

Your echo "t" input is ignored most probably because svn flushes the stream before asking the user for input, so the string provided by echo gets discarded. This behavior is quite widespread for important questions where an unwanted input could ruin something or lead to actions which are impossible to undo. You could use strace to confirm that.

The solution using expect by Dalvenjia will likely work (though technically a race condition will still be there), or you can try to wait past the flushing the quick & dirty way:

{sleep 3; echo "t"; } | svn checkout ...
  • thank your for the answer. I could't get it working this way.. – user236012 Oct 27 '16 at 10:36
  • Anyway, I'm glad you got it working. I guess we'll never know what the problem was without debugging. – Dmitry Grigoryev Oct 27 '16 at 11:12
1
+200

You can use expect, is a command line application to simulate user interaction, just install it and copy the following script to a new executable file.

#!/usr/bin/expect -f

set timeout 20
set user [lindex $argv 0]
set password [lindex $argv 1]

spawn svn checkout --username $user --password $password --no-auth-cache -r revision https://server.address/trunk/

expect "(R)eject or accept (t)emporarily?" { send "t\r" }

interact

Just edit the script to your needs, basically it will run the command and read the output, then will "type" t and return(\r) and release the session

The timeout is for how long expect will wait for the output before giving up, the user and password are variables that will be set from command line arguments, so you must call the script as expectscript.exp user password or you can just remove those 2 lines and put the user and password directly on the spawn line.


EDIT:

Other possible solution:

This might take care of svn "cleaning" STDIN before reading the answer by constantly sending the answer from a forked process to the terminal.

# The following command will fork to the background
# and keep sending 't^M' (^M is return) for 5 seconds to the terminal
{ for X in {1..5}; do printf %b 't\r' >$(tty); sleep 1; done } &

svn checkout --username name --password password --no-auth-cache -r revision https://server.address/trunk/

I hope it works, I have no way of trying it.

EDIT2:

On second thought this may work on an interactive session, but provably not on a script.

EDIT3:

Maybe delaying the answer in a pipe?

(echo -n; sleep 5; printf %b 't\r') | svn checkout --username name --password password --no-auth-cache -r revision https://server.address/trunk/
  • Thank your for the answer. Though it actually doesn't solve my problem (requires extra software package), it works and thus earns the reputation. If somebody gets it working without expect, I'm happy about the answer. – user236012 Oct 27 '16 at 10:46
  • @user236012: try the solution in my edit, I do not have a svn server with a bad cert to try. – Dalvenjia Oct 31 '16 at 22:34
0

The --trust-server-cert option doesn't accept expired certificates, AFAIK. I believe it only works for unknown certificate authorities. Your SVN version might affect this behavior as well, as indicated in this question.

I'm not really sure why the echo command isn't working since I can't replicate the behavior. The 't' may be echoed to a different prompt or point where input is possible. Instead you might try the yes command:

yes 't'

As part of your command:

yes 't' | svn checkout --username name --password password --no-auth-cache -r revision https://server.address/trunk/
  • doesn't work either, same error message.. – user236012 Oct 25 '16 at 8:44
  • @user236012 and similar approaches like <<< t also don't work? It's odd that your SVN client doesn't seem to be using stdin. Is there anything strange about the environment? – edaemon Oct 25 '16 at 18:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.