-
Notifications
You must be signed in to change notification settings - Fork 0
/
dep-bootstrap.sh
executable file
·49 lines (48 loc) · 1.95 KB
/
dep-bootstrap.sh
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
#!/usr/bin/env bash
scriptName=dep-bootstrap.sh
scriptVersion=2
repoURL=https://github.com/EcoMind/dep-bootstrap.git
targetDir="$HOME/.dep"
scriptErrorLabel="[ERROR IN $scriptName v.$scriptVersion]"
version="$1"
if [[ -z "$version" ]] ; then
>&2 echo "$scriptErrorLabel usage: $scriptName <version> [parameters]"
exit 1
fi
shift
if [ -z "$DEP_SOURCED" ] ; then
gitDir="$targetDir/git"
versionDir="$targetDir/bootstrap/$version"
if [[ ! -d "$versionDir" ]] ; then
if [[ $version == "local-SNAPSHOT" ]] ; then
>&2 echo "$scriptErrorLabel $versionDir not found. Please create it using following command (replacing '/path/to/my/local' part): 'mkdir -p $versionDir && ln -s /path/to/my/local/dep-bootstrap/bootstrap.sh $versionDir/bootstrap.sh'"
exit 1
fi
if [[ ! -d "$gitDir" ]] ; then
if ! git -c advice.detachedHead=false clone --depth 1 --branch "$version" "$repoURL" "$gitDir" -q ; then
>&2 echo "$scriptErrorLabel error cloning repo '$repoURL' tag '$version' in '$gitDir'"
exit 1
fi
else
if ! (cd "$gitDir" && git fetch --all --tags --prune -q && git reset --hard -q "tags/$version") ; then
>&2 echo "$scriptErrorLabel error checking out repo '$repoURL' tag '$version' in '$gitDir'"
exit 1
fi
fi
if ! mkdir -p "$versionDir" ; then
>&2 echo "$scriptErrorLabel error creating dir '$versionDir'"
exit 1
fi
bootstrapSource="$gitDir/bootstrap.sh"
if ! cp "$bootstrapSource" "$versionDir" ; then
>&2 echo "$scriptErrorLabel error copying '$bootstrapSource' into '$versionDir'"
exit 1
fi
fi
bootstrapTarget="$versionDir/bootstrap.sh"
# shellcheck disable=SC1090
if ! . "$bootstrapTarget" "$@" ; then
>&2 echo "$scriptErrorLabel error sourcing '$bootstrapTarget'"
exit 1
fi
fi