简体   繁体   中英

How can I download the most recent version of a GitHub project to use in a bash script?

I'm working on a script that sets up a CMS ( Statamic ) so that devs can jump right into writing code and not have to manually move stuff around, gather commonly used code from GitHub, and so on.

I need a way to grab the most recent version of a project from GitHub, unzip it, and be able to move stuff around without knowing the lastest sha.

Code

# Download most recent version from GitHub
curl -L -o DOWNLOADED_FILE_NAME.zip https://api.github.com/repos/USER/REPO/zipball/BRANCH
unzip DOWNLOADED_FILE_NAME.zip
# Find out the name of the unzipped dir and assign it to a variable.
UNZIPPED_DIR=$(compgen -A builtin -f USER-REPO)
rm DOWNLOADED_FILE_NAME.zip

Explanation

  • -L tells curl to follow the redirect.
  • -o specifies the name of the downloaded file.
  • Read this for info on downloading GitHub files from the command line.
  • For info on compgen, check out this answer to another question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM