Now this is a bash script. Computers can read it and so ( to a personal extent) can humans. This human, wyleu, for instance doesnt’ really but can kind of comprehend what it’s trying to do.
The first line:
tell the computer that this script should be run by the ‘shell’ (A programme that reads instructions)
bash which is located in the directory /bin/bash. The #! has a specialized meaning to do this on the first line of a shell script . . The pursuit of knowledge on such issues is a path you frequently find yourself wandering down to get ‘complete’ understands. This is a very **ix sort of thing. . .
The if/elif/else/fi block does what you think, ( but where it’s documented I don’t know, all comments and edits accepted . . . ) so I assume -f checks for the existance of a file ./zynthian_envars.sh in the same directory as this one which is indicated by the ./ ( ./ means the directory you are in, this is done because in *ix the directory you are in isn’t on the path so you have to explicitly declare it, or it doesn’t find the script . . . .(You are just meant to know this stuff . . .this is only the beginning, computers are VERY picky )
So the source command runs against some local scripts if conditions are met. . .
IF a file zynthian_envars.sh exists in the directory you are in then run it. . .
ELSE source the file “/zynthian/zynthian-sys/scripts/zynthian_envars.sh”.
IF neither of them are there then pick up a previous location …
Yes this is all about locating old zynthian_envars.sh file from all the places it’s existed as the project has developed. and running it.
But what is source doing exactly …?
On a **ix shell ( Terminal, typy place …, one of these …)
I try initially to get the manual page for source , and that failed . . .
so I tried adding a -h to get help . . . but it saw this as an option it didn’t recognise, so I tried source --help . . . Which did work . . .(YAJMTKTS…)
But you can see what it does. . .
So source runs the script zynthian_envars.sh … Go and have a look at it if you want . . . .
lots of settings stuff like your Wiring layouts and such like…
So we’ve loaded up lots of environment variable (the export commands)
Time to move on down the script we are looking at . . .
echo "Updating zynthian-sys …"
cp -a scripts/zynthian_envars.sh /tmp
git checkout .
cp -a /tmp/zynthian_envars.sh ./scripts
echo ‘Just’ types stuff to the screen . . . . The quotes round the text is compturerize for a bit of text, called a string.
gets the system variable ZYNTHIAN_SYS_DIR from the stash of environmental variables (remember zynthian_envars.sh…) and then changes into the directory (cd) that’ it gets from there.
Quite what i meant by changes is simply the idea of a default location where ones actions are assumed to be performed, if no other instruction is given. I spent a fair old while getting lost on this in my early days. It really help that where you are to see that the command line prompt( terminal, typy thing … ) often tells you where you are. If you really don’t know type Print Working Directory (pwd)
Those are two different terminals ( actually on different machines) one is the Ubuntu xfce default terminal on my dell laptop which was previously my daughters hence the name . . .
The other is via a programme called putty which is a handy tool for accessing remote machines,
They both show the current directory you are in, but you’d be hard pressed to know it … It’s the ~ ( a tilde) which in command line speak generally means my home directory… . .
The evidence is given by the cd command changing the directory and the alterations in the command line.
on the command line (cp) copies (cp … **ix people type this a lot so it’s really short…) -a ( don’t know . … )The line copies the environmental variables somewhere safe but temporary, the /tmp directory.
This is to protect the envars from what is about to happen, we are going to grab the new code ( remember that’s what we actually want to do here … )
git checkout .
And now we meet git as commands. git ( written by the guy that wrote Linux, Linus Torvalds, over a weekend cos … we’ll read up on it )… However man git DOES Work …
You are already detecting the rather less formal aspect of linux, ( Long may it continue IMHO)
If you can run these command you must have a zynth running so it’s built itself on your machine so it WILL ( or should ) have a git based structure. This means that on your zynth there is a directory /zynhian/zynthian-sys/ where this code is kept and in there is a dreictory call .hg . . directories on **ix have a special meaning, in that they aren’t listed in a simple list command ( ls) so they tend to stay out of the way.
In .git git keeps all its stuff that allow it to keep the code you have and the place where you get that code from in a carefully managed relationship.
Git knows what version of code you have and can (if it’s got a network connection) get back to see what is in the git repository back at git-hub.
It compares the two and if your’s is out of date it gets all the differences and downloads them and then tidies up … It’s really quite clever). That’s the Pull part… Checkout makes sure everything is up to date ( More help needed here …I’m a mercurial gui creature )
So the code on your machine in the zynthian-sys directory well get overwritten by the GitHub Repositories version, which is what we want to do …
We then copy back the envars file
cp -a /tmp/zynthian_envars.sh ./scripts
from it’s temporary location. and then does the same for the other bits of required code…
So we replace the code in the directories. . . * zynthian-sys
We do also run two scripts from the scripts directory . . .
Have a look at what they do . . .
Well they pull in some other bits . . .
So be thorough, it’s can often be a little bit more involved than you may think at first…