-
Notifications
You must be signed in to change notification settings - Fork 5
/
bootstrap.sh
executable file
·105 lines (90 loc) · 2.92 KB
/
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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
# Copyright 2015 The Vanadium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
NATTEMPTS="${NATTEMPTS:-3}"
retry() {
for attempt in $(seq 1 "${NATTEMPTS}"); do
"$@" && break
if [[ "${attempt}" == "${NATTEMPTS}" ]]; then
echo "\"$@\" failed ${NATTEMPTS} times in a row."
echo "This can happen if servers are unavailable,"
echo "and is most likely a temporary problem."
echo "Please try again later."
exit 1
fi
echo "\"$@\" failed, trying again."
sleep 1
done
}
check_environment() {
# Check that the JIRI_ROOT environment variable is set.
if [[ -z "${JIRI_ROOT}" ]]; then
echo "The JIRI_ROOT environment variable is not set."
echo "Set the environment variable and re-run."
exit 1
fi
# Check that the JIRI_ROOT environment variable does not contain spaces.
# Note: This limitation is inherited from Autotools.
local -r PATTERN="[ ']"
if [[ "${JIRI_ROOT}" =~ "${PATTERN}" ]]; then
echo "The JIRI_ROOT environment variable cannot contain"
echo "space characters."
exit 1
fi
# Check that the JIRI_ROOT path does not exist.
if [[ -e "${JIRI_ROOT}" ]]; then
echo "The JIRI_ROOT path already exists: ${JIRI_ROOT}"
echo "Remove it or choose a different path and re-run."
exit 1
fi
# Check that the host OS and package manager is supported.
case $(uname -s) in
"Linux")
apt-get -v &> /dev/null
if [[ "$?" -ne 0 ]]; then
echo "Could not find the apt-get package manager."
exit 1
fi
;;
"Darwin")
brew -v &> /dev/null
if [[ "$?" -ne 0 ]]; then
echo "Could not find the brew package manager."
exit 1
fi
;;
*)
echo "Operating system $(uname -s) is not supported."
exit 1
esac
# Check that GOPATH does not contain v.io packages.
local -r VANADIUM_PACKAGES=$(go list v.io/... 2> /dev/null)
if [[ -n "${VANADIUM_PACKAGES}" ]]; then
echo "Your GOPATH already contains v.io packages."
echo "Remove these from your GOPATH and re-run."
exit 1
fi
# Check that git exists on the host.
local -r GIT_VERSION=$(git version 2> /dev/null)
if [[ "$?" -ne 0 ]]; then
echo "The 'git' command does not exist in your PATH."
echo "Add it to the PATH and re-run."
exit 1
fi
}
main() {
check_environment
trap "rm -rf ${JIRI_ROOT}" INT TERM EXIT
# Run the jiri_bootstrap script.
curl -f -s https://raw.githubusercontent.com/vanadium/go.jiri/master/scripts/bootstrap_jiri | bash -s $JIRI_ROOT
# Import the Vanadium public manifest.
pushd $JIRI_ROOT
$JIRI_ROOT/.jiri_root/bin/jiri import -name=manifest public [email protected]:vanadium-archive/manifest.git
# Sync the Vanadium projects locally.
retry $JIRI_ROOT/.jiri_root/bin/jiri update
popd
echo "Recommended: Add ${JIRI_ROOT}/.jiri_root/scripts to your PATH."
trap - EXIT
}
main "$@"