I want to make a GitHub repository of all relevant scripts I posted here as answers.
But to keep it ultimately simple for the users, I would like to give them a single command to download the script file from my repository directly, without having to install git
first to git clone
the entire repository.
I know I can use wget
to download a single file, but when I use the "Raw" link of a file (e.g. https://github.com/AskUbuntu-Answers/dupe-check/raw/master/dupe-check), the file will get default umask
permissions and therefore has no execution bit set. But I don't want that the user still has to run chmod +x
.
The script files are committed pushed to the repository with correct execution bits, they are also preserved when I use git clone
to get the entire repository.
What is the simplest way to retrieve (and sometimes automatically execute) a single file from GitHub preserving its executing permission without having to install git
and cloning the entire repository?
Best Answer
Get the tarballs!
Even though Github doesn't expose this in the site (apparently they did ages ago), they provide
tar.gz
files of the repositories.<user>
,<repo>
,<filename>
are what you'd expect them to be.--strip-components
is use to preventtar
from creating a directory named after the repo.Therefore:
I'm not convinced this is a particularly friendly way. An additional
chmod +x
is IMO infinitely preferable.Failed attempts
Get the zips!
You can process substitution on zsh to extract the zips linked on the Github repo page. Github, thankfully, adds extra metadata to zips so that permissions are preserved.
unzip
on Ubuntu is able to use that to restore permissions. So:Unfortunately,
=()
is a zsh thing. It creates a proper file instead of a FIFO. Bash doesn't have an equivalent.<()
is always FIFO.Git single files
You can get a single file from repo using
git
. However, Github doesn't support this.