-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadgit
executable file
·80 lines (76 loc) · 2.2 KB
/
loadgit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
usage() {
echo 'loadgit [ -h | --help ] | [ --hash] [--publish] [ -b | --branch branchname ] [-v | --version version ] [ -d | --dir ddfDirectory ] git_url dataset_name'
}
bigwaffleDir=${BIG_WAFFLE_HOME:-"."}
workingDir=${LOAD_GIT_DIR:-"./tmp"}
branch="master"
subDir=
version=
logToSlack=""
useHash=0
publish=""
while [ $# -gt 2 ]; do
case $1 in
-b | --branch ) shift
branch=$1
;;
-d | --dir ) shift
subDir=$1
;;
-v | --version ) shift
version=$1
;;
--logToSlack ) logToSlack="--logToSlack"
;;
--hash ) useHash=1
;;
--publish ) publish="--publish"
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done
if [ $# -lt 2 ]; then
usage
exit 1
fi
gitUrl=$1
name=$2
node ${bigwaffleDir}/src/cli.js list > /dev/null
if [ $? -gt 0 ] ; then
echo "BigWaffle CLI setup is not correct. Check PATH and ENVIRONMENT."
exit 1
fi
if ! [ -d $workingDir ] ; then
mkdir $workingDir
fi
if ! [ -d $workingDir ] ; then
echo "Working directory $workingDir does not exist"
exit 1
fi
git clone -q -b $branch --single-branch --depth 1 $gitUrl ${workingDir}/${name}
if [ $? -gt 0 ] ; then
echo "Could not clone $gitUrl into ${workingDir}/${name}"
exit 1
fi
ddfDirectory=${workingDir}/${name}
if [ "$subDir" != "" ] ; then
ddfDirectory=${ddfDirectory}/${subDir}
fi
if [ $useHash -gt 0 ] ; then
version=`git -C ${workingDir}/${name} rev-parse --short ${branch}`
fi
node ${bigwaffleDir}/src/cli.js ${logToSlack} load $publish -d $ddfDirectory $name $version
if [ $? -gt 0 ] ; then
echo "Loading $gitUrl as $name failed"
rm -Rf ${workingDir}/${name}
exit 1
fi
rm -Rf ${workingDir}/${name}
node ${bigwaffleDir}/src/cli.js list | grep $name
exit 0