git-selfhost

Self-hosted git server with auto-regenerating static stagit frontend
git clone git://git.deurzen.net/git-selfhost
Log | Files | Refs | README

new-repo (1630B)


      1 #!/usr/bin/env bash
      2 set -Eeo pipefail
      3 
      4 DOMAIN="git.mydomain.net"
      5 OWNER="<owner name>"
      6 
      7 if ! [ $# -eq 3 ]; then
      8     >&2 echo "invalid number of arguments"
      9     echo "new-repo: add a new git repo"
     10     echo "usage: new-repo <private|public> <name> <description>"
     11     exit 1
     12 fi
     13 
     14 if [[ "$1" == "private" ]]; then
     15     PRIVATE=1
     16     unset PUBLIC
     17 elif [[ "$1" == "public" ]]; then
     18     PUBLIC=1
     19 else
     20     >&2 echo "invalid first argument: $1"
     21     echo "new-repo: add a new git repo"
     22     echo "usage: new-repo <private|public> <name> <description>"
     23     exit 1
     24 fi
     25 shift
     26 
     27 NAME="$1"
     28 shift
     29 
     30 DESCRIPTION="$@"
     31 
     32 while (( "$#" )); do
     33     case "$1" in
     34         -h|--help)
     35         echo "new-repo: add a new git repo"
     36         echo "usage: new-repo <private|public> <name> <description>"
     37         exit
     38         ;;
     39         -*|--*=)
     40         >&2 echo "new-repo: invalid option $1"
     41         exit 1
     42         ;;
     43         *)
     44         shift
     45         ;;
     46     esac
     47 done
     48 
     49 sudo su git -s /bin/bash <<EOF
     50 mkdir /srv/git/${NAME}.git && cd /srv/git/${NAME}.git && git init --bare
     51 test $PUBLIC && touch /srv/git/${NAME}.git/git-daemon-export-ok
     52 echo "$DESCRIPTION" >| /srv/git/${NAME}.git/description
     53 echo "$OWNER" >| /srv/git/${NAME}.git/owner
     54 echo "git://${DOMAIN}/${NAME}.git" >| /srv/git/${NAME}.git/url
     55 cp ~/post-receive /srv/git/${NAME}.git/hooks/post-receive
     56 echo ""
     57 echo "generating static pages"
     58 cd /var/www/html && ./generate.sh
     59 echo ""
     60 echo "push to: ${DOMAIN}:/srv/git/${NAME}.git"
     61 echo "config:"
     62 echo '[remote "self"]'
     63 echo "	url = self1:/srv/git/${NAME}.git"
     64 echo '	fetch = +refs/heads/*:refs/remotes/self/*'
     65 echo ""
     66 echo "pull from: git@${DOMAIN}/${NAME}.git"
     67 EOF