How to make a uploaded file in github chmod=+x? and then download the file with wget command preserving the executable set in github mode?

♀尐吖头ヾ 提交于 2020-06-26 14:13:43

问题


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..


回答1:


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



回答2:


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



回答3:


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.



来源:https://stackoverflow.com/questions/62442139/how-to-make-a-uploaded-file-in-github-chmod-x-and-then-download-the-file-with

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!