#!/bin/bash # # Create a new repo. # THIS HAS TO BE RUN ON THE GIT SERVER! # WARNING: # This file is maintained within puppet? # All local changes will be lost. # License: GPLv2 (see https://fedorahosted.org/fedora-infrastructure/ticket/3351#comment:2) # Figure out the environment we're running in GITROOT=/srv/git/rpms # check if a moron is driving me if [ ! -d $GITROOT ] ; then # we're not on the git server (this check is fragile) echo "ERROR: This script has to be run on the git server." echo "ERROR: Homer sez 'Duh'." exit -9 fi # Local variables VERBOSE=0 TEST= IGNORE= AUTHOR="Fedora Release Engineering " GIT_SSH_URL="ssh://localhost" Usage() { cat < Creates a new repo for Options: -h,--help This help message EOF } if [ $# -gt 2 ]; then Usage exit -1 fi # parse the arguments while [ -n "$1" ] ; do case "$1" in -h | --help ) Usage exit 0 ;; * ) PACKAGE="$1" ;; esac shift done # I hate shell scripting. I'm sure the above is totally wrong # check the arguments if [ -z "$PACKAGE" ] ; then Usage exit -1 fi # Sanity checks before we start doing damage [ $VERBOSE -gt 1 ] && echo "Checking package $PACKAGE..." if [ -d $GITROOT/$PACKAGE.git ] ; then echo "ERROR: Package module $PACKAGE already exists!" >&2 exit -1 fi # Just don't run as root, mmkey? if [ "$(id -un)" = "root" ] ; then echo "Please run this script as yourself" exit -3 fi # "global" permissions check if [ ! -w $GITROOT ] ; then echo "ERROR: You can not write to $GITROOT" echo "ERROR: You can not create repos" exit -1 fi # Now start working on creating those branches # Create a tmpdir to do some git work in TMPDIR=$(mktemp -d /tmp/tmpXXXXXX) # First create the master repo mkdir $GITROOT/$PACKAGE.git pushd $GITROOT/$PACKAGE.git >/dev/null git init -q --shared --bare echo "$PACKAGE" > description # This is used to figure out who to send mail to. git config --add hooks.mailinglist "$PACKAGE-owner@fedoraproject.org,scm-commits@lists.fedoraproject.org" git config --add hooks.maildomain fedoraproject.org popd >/dev/null # Now clone that repo and create the .gitignore and sources file git clone -q $GITROOT/$PACKAGE.git $TMPDIR/$PACKAGE pushd $TMPDIR/$PACKAGE >/dev/null touch .gitignore sources git add . git commit -q -m 'Initial setup of the repo' --author "$AUTHOR" git push -q origin master popd >/dev/null # Put our special update hooks in place ln -s /usr/share/gitolite/hooks/common/update $GITROOT/$PACKAGE.git/hooks/ ln -s /usr/share/git-core/mail-hooks/gnome-post-receive-email \ $GITROOT/$PACKAGE.git/hooks/post-receive rm -rf $TMPDIR echo "Done."