Skip to content

Instantly share code, notes, and snippets.

@dgleba
Last active October 4, 2018 17:13
Show Gist options
  • Save dgleba/75811a8208f7b462001e766909205afd to your computer and use it in GitHub Desktop.
Save dgleba/75811a8208f7b462001e766909205afd to your computer and use it in GitHub Desktop.
Download a folder from a github repo.
#! /bin/bash
#
# from: wget https://raw.githubusercontent.com/ojbc/docker/master/java8-karaf3/files/git-download.sh
# modified by David Gleba 2018-10-04
# rev-7
#
#set -x
if [ $# -ne 1 ]; then
echo $0: usage: git-download.sh gitHubAPIURLToDownloadFrom
echo $0: The API URL could be for example: https://api.github.com/repos/ojbc/main/contents/shared/ojb-certs
exit 1
fi
DIRS=$(curl -s $1 | grep html_url | grep -v gitignore | sed "s/.*\(https.*\)\".*/\1/g")
for dir in $DIRS
do
plain_dir=$(basename $dir)
mkdir $plain_dir
cd $plain_dir
dir=$(echo $dir | sed "s/github\.com\//api.github.com\/repos\//g" | sed "s/tree/contents/g" | sed "s/master//g")
FILES=$(curl -s $dir | grep download_url | sed "s/.*\(https.*\)\".*/\1/g")
for f in $FILES
do
plainfile=$(basename $f)
curl -s $f -o $plainfile
done
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment