-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcreateGitHubscript.sh
More file actions
executable file
·81 lines (60 loc) · 1.98 KB
/
createGitHubscript.sh
File metadata and controls
executable file
·81 lines (60 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
# createGitHubscript.sh
# a shell script to iterate over directories
# and create github repositories based on the information given.
# we want k for api key, x for prefix, u for username, h for help
# pre-set prefix to APPLICATION
PREFIX="APPLICATION";
while getopts "k:x:h:u:" opt;
do
case $opt in
k) API_KEY=$OPTARG;;
x) PREFIX=$OPTARG ;;
u) USERNAME=$OPTARG ;;
h) echo "Usage: createGitHubscript.sh -k GITHUB_API_KEY -u GITHUB_USERNAME -x DESCRIPTION_PREFIX" ; exit 1 ;;
*) echo "Usage: createGitHubscript.sh -k GITHUB_API_KEY -u GITHUB_USERNAME -x DESCRIPTION_PREFIX" ; exit 1 ;;
esac
done
if [ -z "$API_KEY" ];
then
echo "Must have a API KEY set!"
echo "Usage: createGitHubscript.sh -k GITHUB_API_KEY -u GITHUB_USERNAME -x DESCRIPTION_PREFIX" ;
exit 0;
fi
if [ -z "$USERNAME" ];
then
echo "Must have a API KEY set!"
echo "Usage: createGitHubscript.sh -k GITHUB_API_KEY -u GITHUB_USERNAME -x DESCRIPTION_PREFIX" ;
exit 0;
fi
echo "This script creates GitHub repositories from subdirectories in the current running folder";
# iterate over each directory
src=".";
# enable for loops over items with spaces in their name
# found this on http://heath.hrsoftworks.net/archives/000198.html
IFS=$'\n';
for dir in `ls "$src/"`
do
if [ -d "$src/$dir" ]; then
#yay, we get matches!
cleandir="${dir// /_}";
echo "Time to create a repository for $dir, named $cleandir";
curl -F "login=$USERNAME" -F "token=$API_KEY" https://github.com/api/v2/yaml/repos/create -F name="$cleandir" -F description="$PREFIX - $dir";
echo "Now sleep 5 seconds for politeness";
sleep 5;
# move down into the directory
cd $dir;
# init git
git init;
# add everything
git add ./* ;
# make a first commit
git commit -a -m "initial commit for $dir";
# add the remote origin
git remote add origin git@github.com:$USERNAME/$cleandir.git ;
# push it on up
git push origin master
# get back out
cd ..;
fi
done