| 1 | #!/bin/sh |
| 2 | # install sharness.sh |
| 3 | # |
| 4 | # Copyright (c) 2014, 2022 Juan Batiz-Benet, Piotr Galar |
| 5 | # MIT Licensed; see the LICENSE file in this repository. |
| 6 | # |
| 7 | |
| 8 | gitrepo=ipfs/sharness |
| 9 | githash=803df39d3cba16bb7d493dd6cd8bc5e29826da61 |
| 10 | |
| 11 | if test ! -n "$clonedir" ; then |
| 12 | clonedir=lib |
| 13 | fi |
| 14 | sharnessdir=sharness |
| 15 | gitdir="$clonedir/$sharnessdir/.git" |
| 16 | |
| 17 | die() { |
| 18 | echo >&2 "$@" |
| 19 | exit 1 |
| 20 | } |
| 21 | |
| 22 | if test -d "$clonedir/$sharnessdir"; then |
| 23 | giturl="git@github.com:${gitrepo}.git" |
| 24 | echo "Checking if $giturl is already cloned (and if its origin is correct)" |
| 25 | if ! test -d "$gitdir" || test "$(git --git-dir "$gitdir" remote get-url origin)" != "$giturl"; then |
| 26 | echo "Removing $clonedir/$sharnessdir" |
| 27 | rm -rf "$clonedir/$sharnessdir" || die "Could not remove $clonedir/$sharnessdir" |
| 28 | fi |
| 29 | fi |
| 30 | |
| 31 | if ! test -d "$clonedir/$sharnessdir"; then |
| 32 | giturl="https://github.com/${gitrepo}.git" |
| 33 | echo "Cloning $giturl into $clonedir/$sharnessdir" |
| 34 | git clone "$giturl" "$clonedir/$sharnessdir" || die "Could not clone $giturl into $clonedir/$sharnessdir" |
| 35 | fi |
| 36 | |
| 37 | |
| 38 | echo "Changing directory to $clonedir/$sharnessdir" |
| 39 | cd "$clonedir/$sharnessdir" || die "Could not cd into '$clonedir/$sharnessdir' directory" |
| 40 | |
| 41 | echo "Checking if $githash is already fetched" |
| 42 | if ! git show "$githash" >/dev/null 2>&1; then |
| 43 | echo "Fetching $githash" |
| 44 | git fetch origin "$githash" || die "Could not fetch $githash" |
| 45 | fi |
| 46 | |
| 47 | echo "Resetting to $githash" |
| 48 | git reset --hard "$githash" || die "Could not reset to $githash" |
| 49 | |
| 50 | exit 0 |