Skip to content
This repository
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 116 lines (103 sloc) 3.886 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
#!/bin/sh
# Shell script for creating local git mirrors of drupal's cvs contrib repository
# Assumes that you have:
# a) a cron'd rsync job that periodically pulls down drupal contrib via the provided rsyncd urls
# b) about 6G of hard drive space (as of this writing)
# c) a drupal cvs account. there isn't much point to this if you don't
# d) the right tools installed - cvs, cvsps, git, find, grep, sed. nothin fancy
#
# There are three ways to run this script:
# a) with 'all' as the only argument, in which case it will do all of contrib.
# doing all of contrib will probably take a couple hours the first time around,
# and 30-45 minutes once it's already done.
# b) with a space-delimited list of module names. it will do only those modules.
# c) with no arguments, in which case it will use the list of modules that are
# set in the 'MINE' variable, below.
#
# @author Sam Boyer (sdboyer, tech@samboyer.org)
#
# YOU SHOULDN'T NEED TO TOUCH ANYTHING IN THIS SCRIPT
#

# Include our configuration options.
. /etc/drupal_sync.conf

syncItem() {
  echo "Syncing directories for module, $1."
  # Update or build our cache directory.
  gitCVSSync $1
  
  # Update or build our frontend git repository.
  updateGitRepo $1

  echo " $MINE " | grep -q " $1 " && updateBranches $1
}

updateGitRepo() {
  if [ -d $GITSRV/$GIT_MODULE_BASE/$1.git ]; then
echo " -> Updating git mirror."
    git --git-dir=$GITSRV/$GIT_MODULE_BASE/$1.git fetch > /dev/null
    git --git-dir=$GITSRV/$GIT_MODULE_BASE/$1.git gc > /dev/null
  else
echo " * Building mirror of the cvsimport into a bare repo."
    CLONE_COMMAND="git clone --mirror file://$GITSRV/$GIT_MODULE_BASE/.cvsimport/$1/ $GITSRV/$GIT_MODULE_BASE/$1.git"
    $CLONE_COMMAND > /dev/null
  fi
}

gitCVSSync() {
  echo " -> Updating git storage from CVS."
  #ensure directory
  if [ ! -d $GITSRV/$GIT_MODULE_BASE/.cvsimport/$1 ]; then
mkdir -p $GITSRV/$GIT_MODULE_BASE/.cvsimport/$1
  fi
IMPORT_COMMAND="git cvsimport -umak -p u -o master -C $GITSRV/$GIT_MODULE_BASE/.cvsimport/$1 -d$CVSSRV ${CVS_MODULE_BASE}$1"
  $IMPORT_COMMAND > /dev/null
  git --git-dir=$GITSRV/$GIT_MODULE_BASE/.cvsimport/$1/.git gc > /dev/null
}

updateBranches() {
  echo " * Updating CVS commit checkouts."
  for branch in `git --git-dir=$GITSRV/$GIT_MODULE_BASE/.cvsimport/$1/.git branch | sed 's/\ *//;s/*\ //'`; do
if [ ! -d $GITSRV/$GIT_MODULE_BASE/.cvsco/$1/$branch ]; then
newBranch $1 $branch
    elif [ $branch != "#CVSPS.NO.BRANCH" ]; then
cd $GITSRV/$GIT_MODULE_BASE/.cvsco/$1/$branch/
      cvs -Q -d$CVSEXTERNAL up -dRP > /dev/null
      cd - > /dev/null
    fi
done
}

newBranch() {
  echo " * Setting up new branch"
  echo " -> Checking out $2 branch of the $1 module directly from CVS (for git-cvsexportcommit)"
  mkdir -p $GITSRV/$GIT_MODULE_BASE/.cvsco/$1/
  CVS_COMMAND="cvs -d$CVSSRV co "
  if [ $2 != 'master' ]; then
CVS_COMMAND="$CVS_COMMAND -r $2 "
  else
CVS_COMMAND="$CVS_COMMAND -A "
  fi
CVS_COMMAND="$CVS_COMMAND -d $GITSRV/$GIT_MODULE_BASE/.cvsco/$1/$2 ${CVS_MODULE_BASE}$1"
  $CVS_COMMAND > /dev/null

  # Replace all the CVS Root files' pointers at my local rsync'd repo to cvs.d.o
  find $GITSRV/$GIT_MODULE_BASE/.cvsco/$1/$2 -type f -name 'Root' -exec sed -i "s#$CVSSRV#$CVSEXTERNAL#" '{}' \;
}

if [ $# -gt 0 ]; then
if [ $1 = 'all' ]; then
LIST=`ls $CVSSRV/contributions/modules | grep -v Attic`
    LIST="$LIST core"
  else
LIST=$*
  fi
else
LIST=$MINE
fi

for module in $LIST; do
if [ -d "$CVSSRV/contributions/modules/$module" ]; then
CVS_MODULE_BASE="contributions/modules/"
    GIT_MODULE_BASE="contrib"
    syncItem $module
  else
if [ $module = 'core' ]; then
CVS_MODULE_BASE=""
      GIT_MODULE_BASE="drupal"
      syncItem drupal
    else
echo "Missing $module $CVSSRV/contributions/modules/$module"
    fi
fi
done

Something went wrong with that request. Please try again.