| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# (c) 2002-2006 Henning Glawe <[email protected]> |
| 4 |
# (c) 2007 Holger Levsen <[email protected]> for the modifications to use git |
| 5 |
# (c) 2011 Michael Goetze <[email protected]> |
| 6 |
|
| 7 |
### BEGIN SUBROUTINE INFO |
| 8 |
# Provides-Var: $GIT_WORK_TREE $GIT_DIR |
| 9 |
# Requires-Var: $FAI_CONFIG_SRC $FAI $LOGDIR |
| 10 |
# Suggests-Var: |
| 11 |
# Short-Description: get $FAI from a git repository. |
| 12 |
### END SUBROUTINE INFO |
| 13 |
|
| 14 |
# matched string: "git://gitpath" |
| 15 |
protocol=$(expr match "$FAI_CONFIG_SRC" '\([^:]*\)://') |
| 16 |
gitpath=$(expr match "$FAI_CONFIG_SRC" '[^:]*://\([^[:space:]#]\+\)') |
| 17 |
gitbranch=$(expr match "$FAI_CONFIG_SRC" '[^#]*#\([^[:space:]]\+\)') |
| 18 |
[ -n "$gitbranch" ] || gitbranch=master |
| 19 |
|
| 20 |
case $protocol in |
| 21 |
git) |
| 22 |
giturl="git://$gitpath" |
| 23 |
;; |
| 24 |
git+*) |
| 25 |
giturl="${protocol:4}://$gitpath" |
| 26 |
;; |
| 27 |
*) |
| 28 |
echo "get-config-dir-git: protocol should be git or start with git+" |
| 29 |
exit 1 |
| 30 |
;; |
| 31 |
esac |
| 32 |
|
| 33 |
export GIT_WORK_TREE="$FAI" |
| 34 |
export GIT_DIR="$FAI/.git" |
| 35 |
|
| 36 |
_git_checkout() { |
| 37 |
git checkout -f "origin/$gitbranch" |
| 38 |
task_error 882 $? |
| 39 |
git clean -df |
| 40 |
task_error 882 $? |
| 41 |
} |
| 42 |
|
| 43 |
if [ -d "$GIT_DIR" ]; then |
| 44 |
if [ $(git remote show -n origin | grep -E -m1 -o '[^[:space:]]+://.+') == "$giturl" ]; then |
| 45 |
echo "Updating git copy in $FAI" |
| 46 |
git fetch |
| 47 |
task_error 881 $? |
| 48 |
_git_checkout |
| 49 |
else |
| 50 |
echo "$FAI already contains a git repository, but it is not from $giturl!" >&2 |
| 51 |
echo "Please delete $FAI manually. Aborting..." >&2 |
| 52 |
task_error 883 |
| 53 |
fi |
| 54 |
else |
| 55 |
echo "Checking out from git" |
| 56 |
# cloning into an existing directory is not allowed |
| 57 |
[ -d $FAI ] && rm -rf $FAI |
| 58 |
git clone --branch "$gitbranch" "$giturl" $GIT_DIR |
| 59 |
task_error 882 $? |
| 60 |
_git_checkout |
| 61 |
fi |