#!/bin/bash # # checkout.sh # # Copyright (c) 2010-2012 John Willinsky # Distributed under the GNU GPL v2. For full terms see the file docs/COPYING. # # Script to check and minimize JavaScript for distribution. # # Usage: # checkout.sh [options] [username] [application] [directory] # # Options: # -t Indicates that the application is being checked out by a team member # (i.e. someone with commit priveleges to the pkp repositories). # # Parameters: # [username] The username to use in setting up interoperation with github. # Branches should already be created on github.com for the # application in question and the lib-pkp submodule that it uses. # [application] The name of the application to check out (ojs, ocs, ohs, or # harvester). # [directory] The directory into which to check out the application. # Fail immediately on error return set -e ### Defaults ### CORE_TEAM=0 ### Command Line Options ### while getopts ":t" opt; do case $opt in t) CORE_TEAM=1 ;; esac done shift $((OPTIND-1)) GITHUB_USERNAME=$1 APPLICATION=$2 CHECKOUT_DIR=$3 # Validate parameters if [ \( "$APPLICATION" != "ojs" \) -a \( "$APPLICATION" != "ocs" \) -a \( "$APPLICATION" != "omp" \) -a \( "$APPLICATION" != "harvester" \) ]; then echo "Invalid application \"$APPLICATION\" specified!" exit -1 fi if [ "$GITHUB_USERNAME" == "" ]; then echo "Required github.com username not specified!" exit -1 fi if [ \( "$CHECKOUT_DIR" == "" \) -o \( -e "$CHECKOUT_DIR" \) ]; then echo "Checkout directory not specified or already exists!" exit -1 fi ### Start Processing ### # Clone the main repo and enter the checkout dir git clone git@github.com:${GITHUB_USERNAME}/${APPLICATION}.git ${CHECKOUT_DIR} cd ${CHECKOUT_DIR} # Change the submodule reference to point to this user's github fork instead sed -i -e "s/url = git@github.com:pkp\/pkp-lib.git/url = git@github.com:${GITHUB_USERNAME}\/pkp-lib.git/" .gitmodules # Initialize the submodules (on some git versions, this results in a checkout too) echo "Initializing submodules..." git submodule init git submodule update # Revert .gitmodules changes now that the submodules are initialized git diff .gitmodules | patch -p1 -R cd lib/pkp echo "Configuring submodule remote..." if [ "$CORE_TEAM" -eq 1 ]; then git remote add official git@github.com:pkp/pkp-lib.git else git remote add official https://github.com/pkp/pkp-lib.git fi git checkout master git pull official master cd ../.. echo "Configuring main repository remote..." if [ "$CORE_TEAM" -eq 1 ]; then git remote add official git@github.com:pkp/${APPLICATION}.git else git remote add official https://github.com/pkp/${APPLICATION}.git fi # Flip the master branch over to remote (and fetch the tags) git config branch.master.remote official git pull cd lib/pkp git config branch.master.remote official git pull cd ../.. # Create branches for the various versions for branch in `git branch -a | fgrep remotes/official | fgrep -v HEAD | fgrep -v master`; do git branch --track ${branch##*/} $branch done cd lib/pkp for branch in `git branch -a | fgrep remotes/official | fgrep -v HEAD | fgrep -v master`; do git branch --track ${branch##*/} $branch done cd ../.. echo "Successfully checked out ${APPLICATION} into \"${CHECKOUT_DIR}\"."