2

my OS is Ubuntu 20.04

I Have gone through this post How to add chmod permissions to file in GIT?

What I have is this file https://github.com/PRATAP-KUMAR/focalgdm3/blob/master/focalgdm3

What am I looking is to

chmod +x such that once I download the file by this link wget https://raw.githubusercontent.com/PRATAP-KUMAR/focalgdm3/master/focalgdm3 from github it is ready to be executed in Ubuntu 20.04

I tried git update-index command but got error..

pratap@i7-6550U:~$ git update-index --chmod=+x focalgdm3fatal: not a git repository (or any of the parent directories): .gitpratap@i7-6550U:~$ 

looking for a step by step procedure..

PRATAP
  • 127
  • 3
  • 17
  • Why do you skyp the commit step I mention in the answer? You cannot add, then push. It is `git add --chmod=+x focalgdm3`, (with an `=`), then `git commit -m "executable"`, then git push. If it does not work, it just means you *already* added with executable set. – VonC Jun 23 '20 at 05:01
  • Yes, I have edited the answer to include the relevant commands to avoid that error message. – VonC Jun 23 '20 at 05:07
  • What you want to achieve is impossible: https://serverfault.com/questions/863522/how-to-download-a-file-and-preserver-original-permissions-using-wget – Antwane Jun 23 '20 at 06:26

3 Answers3

3

I have added the file to github by dragging the file from my computer to github upload existing file page.

Then clone the repository, and locally:

cd /path/to/local/clone
git add --chmod=+x myFile
git config --global user.name "My name"
git config --global user.email "my@email.com" (the one used for GitHub account)
git commit -m "Made myFile executable"
git push

As explained in Antwane's answer, a wget through HTTP won't work.
But as seen from "Download executable script from GitHub preserving +x permissions", you can:

  • get the tarball from the GitHub repository (no need for Git)
  • extract the single file from it: its permission should then be preserved.

That is:

wget -qO - https://github.com/<user>/repo>/archive/master.tar.gz | \
tar zx --strip-components=1 <repo>-master/<filename>

Replace <user> with your GitHub username, <repo> with your repository name

In your case:

wget -qO - https://github.com/PRATAP-KUMAR/focalgdm3/archive/master.tar.gz | \
tar zx --strip-components=1 focalgdm3-master/focalgdm3
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/216494/discussion-on-answer-by-vonc-how-to-make-a-uploaded-file-in-github-chmodx-and). – Samuel Liew Jun 23 '20 at 12:09
1

Please go to github.com/PRATAP-KUMAR/focalgdm3 directory before performing the git update-index command.

$ cd github.com/PRATAP-KUMAR/focalgdm3
$ git update-index --chmod=+x focalgdm3
Kamol Hasan
  • 12,218
  • 1
  • 37
  • 46
-1

As I understand, you want to have an executable ready to run immediatly after downloading it using wget. Something like that:

wget https://raw.githubusercontent.com/PRATAP-KUMAR/focalgdm3/master/focalgdm3
./focalgdm3

This is impossible (mainly for security reasons), as HTTP protocol (used when you download file from GitHub) have no information about RWX flags of your file (see https://serverfault.com/a/863523/398223)

A possible solution would be adding the chmod command in your install procedure

wget https://raw.githubusercontent.com/PRATAP-KUMAR/focalgdm3/master/focalgdm3
chmod +x focalgdm3
./focalgdm3

You can also put your focalgdm3 binary into a zip or .tar.gz archive (preserving executable flag), and put it into your GitHub repository so your users can download, extract and run the program.

Antwane
  • 20,760
  • 7
  • 51
  • 84