Daniel P. Berrange | aef45d5 | 2017-09-29 11:11:56 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # This code is licensed under the GPL version 2 or later. See |
| 4 | # the COPYING file in the top-level directory. |
| 5 | |
Daniel P. Berrange | aef45d5 | 2017-09-29 11:11:56 +0100 | [diff] [blame] | 6 | substat=".git-submodule-status" |
| 7 | |
| 8 | command=$1 |
| 9 | shift |
Daniel P. Berrange | 37b5e74 | 2017-10-27 10:49:58 +0100 | [diff] [blame^] | 10 | maybe_modules="$@" |
Daniel P. Berrange | aef45d5 | 2017-09-29 11:11:56 +0100 | [diff] [blame] | 11 | |
Daniel P. Berrange | cc84d63 | 2017-10-20 15:02:43 +0100 | [diff] [blame] | 12 | test -z "$GIT" && GIT=git |
| 13 | |
| 14 | error() { |
| 15 | echo "$0: $*" |
| 16 | echo |
| 17 | echo "Unable to automatically checkout GIT submodules '$modules'." |
| 18 | echo "If you require use of an alternative GIT binary (for example to" |
| 19 | echo "enable use of a transparent proxy), then please specify it by" |
| 20 | echo "running configure by with the '--with-git' argument. e.g." |
| 21 | echo |
| 22 | echo " $ ./configure --with-git='tsocks git'" |
| 23 | echo |
Daniel P. Berrange | f62bbee | 2017-10-26 13:52:26 +0100 | [diff] [blame] | 24 | echo "Alternatively you may disable automatic GIT submodule checkout" |
| 25 | echo "with:" |
| 26 | echo |
| 27 | echo " $ ./configure --disable-git-update'" |
| 28 | echo |
| 29 | echo "and then manually update submodules prior to running make, with:" |
| 30 | echo |
| 31 | echo " $ scripts/git-sbumodule.sh update $modules" |
| 32 | echo |
Daniel P. Berrange | cc84d63 | 2017-10-20 15:02:43 +0100 | [diff] [blame] | 33 | exit 1 |
| 34 | } |
| 35 | |
Daniel P. Berrange | 37b5e74 | 2017-10-27 10:49:58 +0100 | [diff] [blame^] | 36 | if test -z "$maybe_modules" |
Daniel P. Berrange | aef45d5 | 2017-09-29 11:11:56 +0100 | [diff] [blame] | 37 | then |
| 38 | test -e $substat || touch $substat |
| 39 | exit 0 |
| 40 | fi |
| 41 | |
Daniel P. Berrange | 37b5e74 | 2017-10-27 10:49:58 +0100 | [diff] [blame^] | 42 | modules="" |
| 43 | for m in $maybe_modules |
| 44 | do |
| 45 | $GIT submodule status $m 1> /dev/null 2>&1 |
| 46 | if test $? = 0 |
| 47 | then |
| 48 | modules="$modules $m" |
| 49 | else |
| 50 | echo "warn: ignoring non-existent submodule $m" |
| 51 | fi |
| 52 | done |
| 53 | |
Daniel P. Berrange | aef45d5 | 2017-09-29 11:11:56 +0100 | [diff] [blame] | 54 | if ! test -e ".git" |
| 55 | then |
| 56 | echo "$0: unexpectedly called with submodules but no git checkout exists" |
| 57 | exit 1 |
| 58 | fi |
| 59 | |
| 60 | case "$command" in |
| 61 | status) |
| 62 | test -f "$substat" || exit 1 |
Daniel P. Berrange | 96089f6 | 2017-10-26 13:45:38 +0100 | [diff] [blame] | 63 | CURSTATUS=`$GIT submodule status $modules` |
| 64 | OLDSTATUS=`cat $substat` |
| 65 | test "$CURSTATUS" = "$OLDSTATUS" |
Daniel P. Berrange | aef45d5 | 2017-09-29 11:11:56 +0100 | [diff] [blame] | 66 | exit $? |
| 67 | ;; |
| 68 | update) |
Daniel P. Berrange | cc84d63 | 2017-10-20 15:02:43 +0100 | [diff] [blame] | 69 | $GIT submodule update --init $modules 1>/dev/null |
| 70 | test $? -ne 0 && error "failed to update modules" |
| 71 | |
| 72 | $GIT submodule status $modules > "${substat}" |
| 73 | test $? -ne 0 && error "failed to save git submodule status" >&2 |
Daniel P. Berrange | aef45d5 | 2017-09-29 11:11:56 +0100 | [diff] [blame] | 74 | ;; |
| 75 | esac |
Daniel P. Berrange | cc84d63 | 2017-10-20 15:02:43 +0100 | [diff] [blame] | 76 | |
| 77 | exit 0 |