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

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 :)

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

  1. Pingback: A Script to Open All The Sources! (I released 70 open source … | Open Hacking

  2. Pingback: I open-sourced 68 Android applications today, BSD licensed so you can use the code at work. » App Crow

  3. 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!

    • 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*!

  4. Pingback: Open sourcing everything… there’s an app for that | ro-Stire

  5. Pingback: Open sourcing everything… there’s an app for that - Hack a Day

  6. 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.

  7. 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!

  8. Pingback: Open sourcing everything… there’s an app for that « Hackaday « Cool Internet Projects

  9. 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.

  10. Pingback: Open sourcing everything… there’s an app for that « vis a vis | visual mind

    • 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!

  11. 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

  12. Pingback: Hunter Davis Releases 70 Open Source Apps in One Shot | Zoo Pazintys

  13. 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 !!!

  14. Pingback: Android | Pearltrees

  15. Pingback: Publica el código fuente de todos sus proyectos | CyberHades

  16. Pingback: Servicios Web Gratis » Publica el código fuente de todos sus proyectos

  17. Pingback: Hunter Davis Releases 70 Open Source Apps in One Shot | virtualfiles.net

Leave a Reply

Your email address will not be published. Required fields are marked *

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>