forked from libgit2/objective-git
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap
executable file
·131 lines (105 loc) · 2.84 KB
/
bootstrap
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
export SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
##
## Configuration Variables
##
config ()
{
# A whitespace-separated list of executables that must be present and locatable.
# These will each be installed through Homebrew if not found.
: ${REQUIRED_TOOLS="cmake libssh2 libtool autoconf automake pkg-config"}
export REQUIRED_TOOLS
}
##
## Bootstrap Process
##
main ()
{
config
local submodules=$(git submodule status)
local result=$?
if [ "$result" -ne "0" ]
then
exit $result
fi
if [ -n "$submodules" ]
then
echo "*** Updating submodules..."
update_submodules
fi
if [ -n "$REQUIRED_TOOLS" ]
then
echo "*** Checking dependencies..."
check_deps
fi
}
check_deps ()
{
# Check if Homebrew is installed
which -s brew
local result=$?
if [ "$result" -ne "0" ]
then
echo
echo "Homebrew is not installed (http://brew.sh). You will need to manually ensure the following tools are installed:"
echo " $REQUIRED_TOOLS"
echo
echo "Additionally, the following libssh2 files must be symlinked under /usr/local:"
echo " lib/libssh2.a include/libssh2.h include/libssh2_sftp.h include/libssh2_publickey.h"
exit $result
fi
# Ensure that we have libgit2's dependencies installed.
installed=`brew list`
for tool in $REQUIRED_TOOLS
do
# Skip packages that are already installed.
echo "$installed" | grep -q "$tool" && code=$? || code=$?
if [ "$code" -eq "0" ]
then
echo "*** $tool is available"
continue
elif [ "$code" -ne "1" ]
then
exit $code
fi
echo "*** Installing $tool with Homebrew..."
brew install "$tool"
done
brew_prefix=`brew --prefix`
expected_prefix=/usr/local
if [ "$brew_prefix" != "$expected_prefix" ]
then
echo "*** Adding soft links into $expected_prefix..."
products=(lib/libssh2.a include/libssh2.h include/libssh2_sftp.h include/libssh2_publickey.h)
for product in "${products[@]}"
do
destination="$expected_prefix/$product"
if [ -e "$destination" ]
then
continue
fi
sudo mkdir -p "$(dirname "$destination")"
sudo ln -s "$brew_prefix/$product" "$destination"
done
fi
}
bootstrap_submodule ()
{
local bootstrap="script/bootstrap"
if [ -e "$bootstrap" ]
then
echo "*** Bootstrapping $name..."
"$bootstrap" >/dev/null
else
update_submodules
fi
}
update_submodules ()
{
git submodule sync --quiet && \
git submodule update --init && \
git submodule foreach --quiet bootstrap_submodule
}
export -f bootstrap_submodule
export -f update_submodules
main