Converting safegit bash scripts to SAFE CLI?

Any bash script kiddies fancy trying to adapt the bash script that I wrote for safegit with SAFE Drive to use the new CLI?

I’m not sure if everything we need is there yet, but that’s the point really - to find out if there are any features missing for this and similar applications as well as add to the testing of what we have.

It should be fairly straightforward, not so much writing script as converting CLI commands (eg rsync) to SAFE CLI commands.

I can’t use the shared section myself atm, but would in any case prefer not to divert from what I’m working on.

There’s a blog explaining how to use safegit with SAFE Drive so you can follow that and I’ll be around to help of course.

There’s also a bash test script I wrote for SAFE Drive that might be interesting to try and convert. That might be more tricky, but could be useful in identifying some nice to have extras even if not much of it can be used directly with SAFE CLI.

So there’s room for a couple of people, and you could work together of course, hint hint :smile:

UPDATE: while I’m in script mode and have mastered the embarrassingly :blush: simple safe vault run-baby-fleming and @southside is relaxing on the beach, I’m going to have a look at the safegit script and have created a repository for safenetwork git stuff where the new script will live: safenetwork-git

3 Likes

Well now you stopped me and @JPL getting wellied on the homebrew round the back of the bike sheds, I suppose Im going to have to get on with the bash homework - which the dog ate BTW -
Am I right in thinking this all ground to a halt cos safe-js err safenetworkjs had the ground move from under it and we were on hold until an alternative got developed once things settled down a bit?

2 Likes

I was hoping I’d snag a bash addict.

Yes, spot on. But hopefully there’s enough features in the CLI to sit the same safegit functionality on top.

Essentially it uses git commands on you local drive and then rsyncs to/from SAFE Drive, so you need to replace those bits with the equivalent SAFE CLI sync commands, and probably a few other bits and pieces to create the container etc.

Hopefully fairly obvious but shout if not. I haven’t looked at this for ages.

1 Like

Calling all sed geniuses, yes you @davidpbrown
Given I have /tmp/safegitworkarea
willie@gagarin:/tmp$ cat safegit-workarea

== URL resolution step 1 ==
Resolved from: safe://a-safeish.blog
= NRS Map Container =
PublicName: "blog"
XOR-URL: safe://a-safeish.hnyydyzpwcws1qruk5t11zqen95xhdpapwo8hoqhewfksq3g7aku5denscbqh
Version: 1
Type tag: 1500
XOR name: 0xdb4652d27126adc652bb902fedfc1b70da40fc83b88a1556764ddc2a7b1a0566
Native data type: PublishedSeqAppendOnlyData
+------------------+----------------------+----------------------+--------------------------------------------------------------------------+
| NRS name/subname | Created              | Modified             | Link                                                                     |
+------------------+----------------------+----------------------+--------------------------------------------------------------------------+
| blog             |                      |                      | Alias to subname 'a-safeish'                                             |
+------------------+----------------------+----------------------+--------------------------------------------------------------------------+
| a-safeish.blog   | 2020-06-05T10:04:48Z | 2020-06-05T10:04:48Z | safe://hnyynysu89ereoi68i1p9496sp88cnx9swbh6njgdjy3octsrwosnigrfebnc?v=0 |
+------------------+----------------------+----------------------+--------------------------------------------------------------------------+

== URL resolution step 2 ==
Resolved from: safe://hnyynysu89ereoi68i1p9496sp88cnx9swbh6njgdjy3octsrwosnigrfebnc?v=0
= FilesContainer =
XOR-URL: safe://hnyynysu89ereoi68i1p9496sp88cnx9swbh6njgdjy3octsrwosnigrfebnc?v=0
Version: 0
Type tag: 1100
XOR name: 0xa67fa088857c7ac9bfd7fd669cec13ff6a079e124c348330646c4a42c2a98854
Native data type: PublishedSeqAppendOnlyData

How can I use sed to make this more elegant
willie@gagarin:/tmp$ grep -rn “XOR-URL” safegit-workarea |grep “?v=”|cut -d : -f4
//hnyynysu89ereoi68i1p9496sp88cnx9swbh6njgdjy3octsrwosnigrfebnc?v=0

What result are you wanting?.. safe dog can give upto 10 steps now… if wanting step 2 xorurl then there’s an option with sed to select from line to line and grep just that second step.

Will look again later…

1 Like

I want the Files Container XOR-URL (for starters) please.

THank you , superb support response time :slight_smile:

cat safegit-workarea | sed -n -e '/^== URL resolution step 2 ==/,/Native data type: /p' | grep -m 1 'XOR-URL:' | sed 's#XOR-URL: safe://##'

1 Like

Thanks - I’ll try that.

Remember all commands support the --output / -o argument to get the output in json/yaml formats, I guess it’s easier to parse those than the default pretty printed one.

I’ve never used it, but I see the jq tool in my Ubuntu which you can use to parse the complete json output.

4 Likes

E.g.:

$ safe dog <safe-url> --json | jq '.[1][1]["FilesContainer"]["xorurl"]'
"safe://hnyynb8xt9qpd1j533ipkhjhwakyd8e5b6are4aiort9pcfsa61n85r7n6bnc?v=0"
5 Likes

Nice one @bochaco, i must admit to not having considered that.

A spot of rethinking with a cool beer in the garden now — Thank you for the excuse.

3 Likes

UPDATE: while I’m in script mode and have mastered the embarrassingly :blush: simple safe vault run-baby-fleming and @southside is relaxing on the beach, I’m going to have a look at the safegit script and have created a repository for safenetwork git stuff where the new script will live: safenetwork-git

1 Like