Poor man's github

  |   Source

Key points of this article:

  • Build a github prototype written in Bash within 5 minutes
  • Highlight key elements in my usual git work flow
  • Git is scalabe. you can use any tool to extend it.

As Yuri Albuquerque mentioned, there are more powerful tools like gitolite. But the key concept behind the system is similar.

Add following code into ~/.bashrc and run "source ~/.bashrc", then run "gih" to see help:

function gih() {
    local MY_USERNAME=git
    local MY_SSH_URL=git@domain.name
    local MY_SSH_PORT=8888
    if [ -z "$1" ]; then
        cat << 'EOF'
Usage: gih [command]

Commands:

l, ls, list - list the projects

n, new [project-name] - create a new project

r, readme [project-name] - show README

i, issue [project-name] - show issues list

st, status - check free space of git server

u, url [project-name] - the full url of the project

EOF else case $1 in l|ls|list) ssh -p $MY_SSH_PORT $MY_SSH_URL "ls -1"|sed 's/.git$//g' ;; n|new) if [ -z "$2" ]; then echo "Please input the name of new project!" echo "Current projects hosted:" ssh -p $MY_SSH_PORT $MY_SSH_URL "ls -1"|sed 's/.git$//g' else ssh -p $MY_SSH_PORT $MY_SSH_URL "mkdir -p ~/$2.git;cd ~/$2.git;git --bare init;" echo "Push existing repository from command line:" echo git remote add origin ssh://$MY_SSH_URL:$MY_SSH_PORT/home/$MY_USERNAME/$2.git echo git push -u origin master fi ;; r|readme) if [ -z "$2" ]; then echo "Please input the name of new project!" echo "Current projects hosted:" ssh -p $MY_SSH_PORT $MY_SSH_URL "ls -1"|sed 's/.git$//g' else ssh -p $MY_SSH_PORT $MY_SSH_URL "cd ~/$2.git;git show HEAD:README.org || git show HEAD:README.md" fi ;; i|issue) if [ -z "$2" ]; then echo "Please input the name of new project!" echo "Current projects hosted:" ssh -p $MY_SSH_PORT $MY_SSH_URL "ls -1"|sed 's/.git$//g' else ssh -p $MY_SSH_PORT git@sydneypc.mooo.com "cd ~/$2.git;git show HEAD:ISSUE.org || git show HEAD:ISSUE.md" fi ;; st|status) ssh -p $MY_SSH_PORT $MY_SSH_URL "df -h /dev/sda1" ;; u|url) echo ssh://$MY_SSH_URL:$MY_SSH_PORT/home/$MY_USERNAME/$2.git ;; *) echo "Unknown command, check help please" ;; esac fi }

Comments powered by Disqus