#!/bin/bash # (c) 2002-2006 Henning Glawe # (c) 2007 Holger Levsen for the modifications to use git # (c) 2011 Michael Goetze ### BEGIN SUBROUTINE INFO # Provides-Var: $GIT_WORK_TREE $GIT_DIR # Requires-Var: $FAI_CONFIG_SRC $FAI $LOGDIR # Suggests-Var: # Short-Description: get $FAI from a git repository. ### END SUBROUTINE INFO # matched string: "git://gitpath" protocol=$(expr match "$FAI_CONFIG_SRC" '\([^:]*\)://') gitpath=$(expr match "$FAI_CONFIG_SRC" '[^:]*://\([^[:space:]#]\+\)') gitbranch=$(expr match "$FAI_CONFIG_SRC" '[^#]*#\([^[:space:]]\+\)') [ -n "$gitbranch" ] || gitbranch=master case $protocol in git) giturl="git://$gitpath" ;; git+*) giturl="${protocol:4}://$gitpath" ;; *) echo "get-config-dir-git: protocol should be git or start with git+" exit 1 ;; esac export GIT_WORK_TREE="$FAI" export GIT_DIR="$FAI/.git" _git_checkout() { git checkout -f "origin/$gitbranch" task_error 882 $? git clean -df task_error 882 $? } if [ -d "$GIT_DIR" ]; then if [ $(git remote show -n origin | grep -E -m1 -o '[^[:space:]]+://.+') == "$giturl" ]; then echo "Updating git copy in $FAI" git fetch task_error 881 $? _git_checkout else echo "$FAI already contains a git repository, but it is not from $giturl!" >&2 echo "Please delete $FAI manually. Aborting..." >&2 task_error 883 fi else echo "Checking out from git" # cloning into an existing directory is not allowed [ -d $FAI ] && rm -rf $FAI git clone --branch "$gitbranch" "$giturl" $GIT_DIR task_error 882 $? _git_checkout fi