Last active
August 25, 2016 16:07
-
-
Save Technicus/59e57c0edce8393255ab32e69dd6c833 to your computer and use it in GitHub Desktop.
Repository Management Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
clear | |
# Check for arguments, and give feedback | |
if [ -z "$1" ]; then | |
printf "\n\tThis script will read the list-git.<account> file and download the git project" | |
printf "\n\tto the directory provided.\n" | |
printf "\n\t\tInsifficient arguments provided." | |
printf "\n\t\tUsage:" | |
printf "\n\t\t\t# ${0} list-git.<account> <download_directory>\n\n" | |
exit 1 | |
fi | |
if [ -z "$2" ]; then | |
printf "\n\tThis script will read the list-git.<account> file and download the git project" | |
printf "\n\tto the directory provided.\n" | |
printf "\n\t\tInsifficient arguments provided." | |
printf "\n\t\tUsage:" | |
printf "\n\t\t\t# ${0} list-git.<account> <download_directory>\n\n" | |
exit 1 | |
fi | |
# Assign the arguments to gitlist and working directory | |
gitList="$1" | |
workingDirectory="$2" | |
if [ -d "$workingDirectory" ]; then | |
# Control will enter here if $DIRECTORY doesn't exist. | |
printf "\n\tThe directory is present.\n\n" | |
else | |
printf "\n\tThe directory is not present.\n" | |
printf "\n\tCreating ${workingDirectory}." | |
mkdir "$workingDirectory" | |
printf "\n\n" | |
fi | |
# Download repositories from Github listed in a file | |
filename="${gitList}" | |
printf "\t" | |
# (cd "${workingDirectory}" && exec pwd) | |
while read -r gitFile | |
do | |
printf "\t\tgit clone ${gitFile}" | |
# git clone "${gitFile}" | |
# (cd "${workingDirectory}" && `git checkout -f HEAD "${gitFile}"`) | |
(cd "${workingDirectory}" && `git clone "${gitFile}"`) | |
printf "\t\tgit cloned ${gitFile}\n\n" | |
done < "$filename" | |
printf "\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# Assign argument to repository value and create working directory, clear the screen | |
repository="$1" | |
workingPath=.. | |
workingDirectory="${workingPath}/${repository}" | |
pWorkingDirectory=`pwd` | |
clear | |
# Check for arguments, and give feedback | |
if [ $# -eq 0 ]; then | |
printf "\n\tThis script will query the Github API and return four files. The files will\n" | |
printf "\tinclude URL links to the repositories, tar links to the repositories, zip links\n" | |
printf "\tto the repositories, and git links to the repositories. All in plain text files.\n" | |
printf "\n\t\tNo arguments provided." | |
printf "\n\t\tUsage:" | |
printf "\n\t\t\t# get_repository_links.sh < github_account >\n\n" | |
exit 1 | |
fi | |
if [ -d "$workingDirectory" ]; then | |
# Control will enter here if $DIRECTORY doesn't exist. | |
printf "\n\tThe list directory is present.\n" | |
else | |
printf "\n\tThe list directory is not present.\n" | |
printf "\n\tCreating ${workingDirectory}." | |
mkdir "$workingDirectory" | |
fi | |
printf "\n\tPresent working directory = ${pWorkingDirectory} \n" | |
printf "\n\thttps://api.github.com/users/$1/repos?per_page=1000\n\n" | |
# Querry API and create temp | |
printf "\n\n\tQuerry API and create temp\n" | |
curl "https://api.github.com/users/$1/repos?per_page=1000" | grep -o 'https://github.com/[^"]*' > "${workingDirectory}/list-tmp-0.$1" | |
awk '{if (++dup[$0] == 1) print $0;}' "${workingDirectory}/list-tmp-0.$1" > "${workingDirectory}/list-tmp-1.$1" | |
printf "\t\t${workingDirectory}/list-tmp-0.$1\n\t\t${workingDirectory}/list-tmp-1.$1" | |
# Create list of .git repos | |
printf "\n\n\tCreate list of .git repos\n" | |
cat "${workingDirectory}/list-tmp-1.$1" | grep "\.git$" > ./"${workingDirectory}/list-tmp-2.$1" | |
sed -i -e 's/https/git/g' "${workingDirectory}/list-tmp-2.$1" | |
mv "${workingDirectory}/list-tmp-2.$1" "${workingDirectory}/list-git.$1" | |
printf "\t\t${workingDirectory}/list-git.$1" | |
# Create list of reop url links | |
printf "\n\n\tCreate list of reop url links\n" | |
cat "${workingDirectory}/list-tmp-1.${repository}" | sed -n '/\.git/!p' > ./"${workingDirectory}/list-url.$1" | |
printf "\t\t${workingDirectory}/list-url.$1" | |
# Create list of reop titles | |
printf "\n\n\tCreate list of reop titles\n" | |
grep -oP "https://github.com/${repository}/\K.*" "${workingDirectory}/list-url.${repository}" > "${workingDirectory}/list-tit.$1" | |
printf "\t\t${workingDirectory}/list-tit.$1" | |
# Create list of reop zip links | |
printf "\n\n\tCreate list of reop zip links\n" | |
echo -n "" > "${workingDirectory}/list-zip.$1" | |
filename=${workingDirectory}/list-tit."$1" | |
while read -r name | |
do | |
echo https://api.github.com/repos/$1/$name/zipball/master >> "${workingDirectory}/list-zip.$1" | |
done < "$filename" | |
printf "\t\t${workingDirectory}/list-zip.$1" | |
# Create list of reop tar links | |
printf "\n\n\tCreate list of reop tar links\n" | |
echo -n "" > "${workingDirectory}/list-tar.$1" | |
filename=${workingDirectory}/list-tit."$1" | |
while read -r name | |
do | |
# name="$line" | |
echo https://api.github.com/repos/$1/$name/tarball/master >> "${workingDirectory}/list-tar.$1" | |
done < "$filename" | |
printf "\t\t${workingDirectory}/list-tar.$1" | |
# Remove the temporary files | |
printf "\n\n\tRemove the temporary files\n" | |
rm "${workingDirectory}/list-tmp-"{0..1}".$1" | |
printf "\n\tDone\n\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script will query the Github API and return four files. The files will include URL links to the repositories, tar links to the repositories, zip links to the repositories, and git links to the repositories. All in plain text files.
Usage:
get_repository_links.sh < github_account >