Apr 112012
 

I’ve been studying my site and app traffic for a while now, and I’ve come to a very sure conclusion. Open-sourcing an app does nothing to decrease app sales or ad traffic, but increases web traffic significantly. Therefore I’ve decided to open source everything I’ve ever done, BSD licensed so you can use it at work.

Seriously, all the sources. Every one. To start with, I’ve created repositories for the roughly 70 Android applications I’ve released. As of today, you can browse through them all on my GitHub account page.

Unfortunately for me, the task of open sourcing 100+ projects is a daunting one, so I set about writing a script to troll my folders and create GitHub projects. This script itself is also available on GitHub here. Read on for more info about the construction of the script.


I started with a folder full of my android applications, but you can apply this to any set of directories. You’ll need curl, git, and your GitHub username and API key. The script simply creates a set of repositories with a combination of passed and inferred metadata.

I started by getting my API access key, metadata prefix, and github user-name and read them in via parameter as follows.


# 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

Here I iterate over each folder in the passed-in directory.

for dir in `ls "$src/"`
do
  if [ -d "$src/$dir" ]; then

From the folder name I glean the title of the app, which is used to create the application on GitHub via their yaml api. I also sleep 5 seconds after repository creation, for politeness.

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;

After this is completed, I move into the directory, and initialize a git repository, add all the files, make the first commit, and push it up to GitHub.

# 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

And that’s that. You can see the full code at the script’s git repository. Feel free to browse the avalanche of source code that’s hitting GitHub from my computer today :)

Share
 Posted by at 10:50 pm

  34 Responses to “A Script to Open All The Sources! (I released 70 open source projects today)”

  1. [...] the original here:  A Script to Open All The Sources! (I released 70 open source … This entry was posted on Wednesday, April 11th, 2012 at 10:50 pm and is filed under Android, [...]

  2. [...] applications today, BSD licensed so you can use the code at work.submitted b&#1091 huntergdavis [link] [11 comments]PostedApril 11th, 2012Filed Android RedditNo CommentsLeave a Comment Click here to [...]

  3. You are an awesome person. Thank you.

  4. A grammar nitpick : Trolling through is not a verb! The verb is trolling. Fishing boats don’t troll through the sea. They troll the sea!

  5. Actually BMBM they “trawl” the sea, but troll is a bastardization of “trawl”.

    • Good call flyingwolf! I am getting all sorts of grammar goodness up in here.

    • Actually, “trolling” is a distinct thing in its own right – moving a lure through the water with a boat or on foot. Trawling generally involved dragging a net or a line with many lures. Interestingly, both of the dictionaries I checked said that “trawl” could be used to mean “troll”, but the entries for “troll” didn’t mention “trawl” – so it’s actually closer to the opposite of what you said (though both terms have distinct origins).

      And of course to Hunter – what you’ve done is *awesome*!

  6. [...] What happens if you’re a prolific developer and decide to release all of the source code from your work? Well, you should get a huge pat on the back from all interested parties. And so we say thank you to [Hunter Davis] for releasing the source code for his 70+ Android apps. But just making the decision isn’t the end of things, you’ve got actually get the code out there. And herein lies the hack. Instead of archiving and posting all of those projects he wrote a script to crawl, init, and push his projects to Github automatically. [...]

  7. [...] What happens if you’re a prolific developer and decide to release all of the source code from your work? Well, you should get a huge pat on the back from all interested parties. And so we say thank you to [Hunter Davis] for releasing the source code for his 70+ Android apps. But just making the decision isn’t the end of things, you’ve got actually get the code out there. And herein lies the hack. Instead of archiving and posting all of those projects he wrote a script to crawl, init, and push his projects to Github automatically. [...]

  8. Too bad you have more comments about your grammar than you do about your code.

    Thanks for releasing it. I will probably use this myself for all the half-finished projects I still have to upload.

  9. Thanks hunter! I’m just starting out learning java so I can write android apps. Every language I’ve ever worked with I learn the fastest by building off of other peoples code samples. You have several programs that perform tasks I’m interested in for an app I want to write, so this will help me out tremendously. Glad your proving that sharing your source doesn’t decrease ad and app revenue. Developers aren’t going to be part of your market for app sales. Your market is generally the folks that have no idea how to compile source in the first place. Keep up the good work and a big thanks for giving me some great code to learn from and build off of!

    • You’re welcome! I’m glad to hear it’ll help you out, and I agree completely. They are different markets completely, and conflating them doesn’t help anyone in the long run. Best of luck and thanks!

  10. [...] What happens if you’re a prolific developer and decide to release all of the source code from your work? Well, you should get a huge pat on the back from all interested parties. And so we say thank you to [Hunter Davis] for releasing the source code for his 70+ Android apps. But just making the decision isn’t the end of things, you’ve got actually get the code out there. And herein lies the hack. Instead of archiving and posting all of those projects he wrote a script to crawl, init, and push his projects to Github automatically. [...]

  11. I’m not much of a coder, but I do appreciate open source. Thank you for sharing!

  12. Wow.
    Perhaps It’s time I also GitHub.
    All my open source pieces end up cleaner, more maintained, more used and more loved than my code once and use pieces.
    May many follow your example.
    I will.
    Murray.

  13. [...] What happens if you’re a prolific developer and decide to release all of the source code from your work? Well, you should get a huge pat on the back from all interested parties. And so we say thank you to [Hunter Davis] for releasing the source code for his 70+ Android apps. But just making the decision isn’t the end of things, you’ve got actually get the code out there. And herein lies the hack. Instead of archiving and posting all of those projects he wrote a script to crawl, init, and push his projects to Github automatically. [...]

  14. Hey, please contact me if you have an XDA-Developers account. I’d like to link the article to your member name. http://www.xda-developers.com/android/hunter-davis-releases-70-open-source-apps-in-one-shot/

    Great job and thanks for chosing open source!

    • Hey Adam,

      My XDA username is ‘huntergdavis’. I’ll send it to you in an email too. Appreciate the heads up, and thanks for checking it out!

  15. Great job man, since i’ve just started learning java, your simple apps will really help in making something wonderful.

    On a sidenote, how about using repo to clone all the apps at once (and keep them up-to-date)
    Would be cool, just repo init n sync and get source of 70 market app at once

    • Hey cdesai,

      Thanks! Glad to hear my apps will help you out, that’s what they’re there for. Cloning all the apps at once is definitely a possibility now, and it’s a pretty cool workflow when you think about it that way. Best of luck!
      /H

  16. [...] developed his development machine to make it do his bidding. First, Davis released the source for seventy applications in a single bound and released the code he used to release his source code. A day later, he released eleven [...]

  17. Thanks, Hunter !!! You are the man !! You are doing a GREAT service for many budding Android devs out there. I’m sure that many of them, like myself, would like to give you a big hand for giving back so generously to the open source community. This is what open source is all about !!!

  18. [...] To start with, I've created repositories for the roughly 70 Android applications I've released. A Script to Open All The Sources! (I released 70 open source projects today) « HunterDavis.com [...]

  19. I might just rewrite this in perl, should be fun

  20. [...] es el caso de Hunter Davis, un desarrollador que ha decidido compartir el código fuente de todos sus proyectos, entre ellos sus más de 70 aplicaciones para [...]

  21. [...] es el caso de Hunter Davis, un desarrollador que ha decidido compartir el código fuente de todos sus proyectos, entre ellos sus más de 70 aplicaciones para Android. var uri = [...]

  22. [...] developed his development machine to make it do his bidding. First, Davis released the source for seventy applications in a single bound and released the code he used to release his source code. A day later, he released eleven [...]

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>