forked from zauberzeug/XFormsTouch
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·192 lines (160 loc) · 5.32 KB
/
build.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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env bash
set -eEuo pipefail
shopt -s extglob;
##########################################################################
# This is the Cake bootstrapper script for Linux and OS X.
# This file was downloaded from https://github.com/cake-build/resources
# Feel free to change this file to fit your needs.
##########################################################################
# Define directories.
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
TOOLS_DIR=$SCRIPT_DIR/tools
ADDINS_DIR=$TOOLS_DIR/Addins
MODULES_DIR=$TOOLS_DIR/Modules
NUGET_EXE=$TOOLS_DIR/nuget.exe
MANIFEST_FILE=$SCRIPT_DIR/.config/dotnet-tools.json
PACKAGES_CONFIG=$TOOLS_DIR/packages.config
PACKAGES_CONFIG_MD5=$TOOLS_DIR/packages.config.md5sum
ADDINS_PACKAGES_CONFIG=$ADDINS_DIR/packages.config
MODULES_PACKAGES_CONFIG=$MODULES_DIR/packages.config
export CAKE_PATHS_TOOLS=$TOOLS_DIR
export CAKE_PATHS_ADDINS=$ADDINS_DIR
export CAKE_PATHS_MODULES=$MODULES_DIR
# Define md5sum or md5 depending on Linux/OSX
MD5_EXE=
if [[ "$(uname -s)" == "Darwin" ]]; then
MD5_EXE="md5 -r"
else
MD5_EXE="md5sum"
fi
# Define default arguments.
SCRIPT=$SCRIPT_DIR/build.cake
CAKE_ARGUMENTS=()
# Parse arguments. (modified heavily by srichey)
while [ ${#} -gt 0 ]; do
case "${1}" in
-s|--script)
SCRIPT="${2}"
;;
\-\-+([a-zA-Z])=+(*)) # double dash flags ONLY (mainly to avoid parsing bugs)
if [[ "${1}" =~ "=" ]]; then # check if we have an equals sign
IFS='='; ARRAY=(${1}); unset IFS;
# check that the value after the = is valid
if [ -z "${ARRAY[1]-}" ]; then
echo "Invalid value for flag: \"${1}\""
exit 1
fi
CAKE_ARGUMENTS+=("${1}")
elif [ -z "${2:-}" ]; then # check if 2 is bound
# if not, we better have an equals sign
if [[ "${1}" =~ "=" ]]; then
IFS='='; ARRAY=(${1}); unset IFS;
# check that the value after the = is valid
if [ -z ${ARRAY[1]-} ]; then
echo "Invalid value for flag: \"${1}\""
exit 1
fi
CAKE_ARGUMENTS+=("${1}")
else
echo "Expected \"=\" or another argument for flag \"${1}\""
exit 1
fi
else # if 2 is bound but we have an equals, assume "--flag value"
echo "Please provide an equals sign to tie flags to their values."
exit 1
fi
;;
\-+([A-Za-z])=+(*)) # single dash flags
echo "Please use double dash flags: single dashes are unsupported."
exit 1
;;
\-\-+([a-zA-Z])) # double dash, implicitly true
CAKE_ARGUMENTS+=("${1}=true")
;;
*)
echo "Error: unrecognized argument ${1}"
exit 1
;;
esac
shift
done
# Make sure the tools folder exist.
if [ ! -d "$TOOLS_DIR" ]; then
mkdir "$TOOLS_DIR"
fi
# Make sure that packages.config exist.
if [ ! -f "$TOOLS_DIR/packages.config" ]; then
echo "Downloading packages.config..."
curl -Lsfo "$TOOLS_DIR/packages.config" https://cakebuild.net/download/bootstrapper/packages
if [ $? -ne 0 ]; then
echo "An error occurred while downloading packages.config."
exit 1
fi
fi
# Download NuGet if it does not exist.
if [ ! -f "$NUGET_EXE" ]; then
echo "Downloading NuGet..."
curl -Lsfo "$NUGET_EXE" https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
if [ $? -ne 0 ]; then
echo "An error occurred while downloading nuget.exe."
exit 1
fi
fi
# Restore tools from NuGet.
pushd "$TOOLS_DIR" >/dev/null
if [ ! -f "$PACKAGES_CONFIG_MD5" ] || [ "$( cat "$PACKAGES_CONFIG_MD5" | sed 's/\r$//' )" != "$( $MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' )" ]; then
find . -type d ! -name . ! -name 'Cake.Bakery' | xargs rm -rf
fi
mono "$NUGET_EXE" install -ExcludeVersion
if [ $? -ne 0 ]; then
echo "Could not restore NuGet tools."
exit 1
fi
$MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' >| "$PACKAGES_CONFIG_MD5"
popd >/dev/null
# Restore addins from NuGet.
if [ -f "$ADDINS_PACKAGES_CONFIG" ]; then
pushd "$ADDINS_DIR" >/dev/null
mono "$NUGET_EXE" install -ExcludeVersion
if [ $? -ne 0 ]; then
echo "Could not restore NuGet addins."
exit 1
fi
popd >/dev/null
fi
# Restore modules from NuGet.
if [ -f "$MODULES_PACKAGES_CONFIG" ]; then
pushd "$MODULES_DIR" >/dev/null
mono "$NUGET_EXE" install -ExcludeVersion
if [ $? -ne 0 ]; then
echo "Could not restore NuGet modules."
exit 1
fi
popd >/dev/null
fi
# Restore dotnet tools from NuGet.
if [ -f "${MANIFEST_FILE}" ]; then
dotnet tool restore
if [ $? -ne 0 ]; then
echo "Could not restore dotnet tools."
exit 1
fi
fi
# Make sure that Cake has been installed as a dotnet tool.
dotnet cake --version
if [ $? -ne 0 ]; then
echo "Unable to run Cake as a dotnet tool."
exit 1
fi
# Logging added by srichey
if [[ "${CAKE_ARGUMENTS[@]+"${CAKE_ARGUMENTS[@]}"}" ]]; then
echo "Bootstrapper parsed the following arguments:"
for arg in "${CAKE_ARGUMENTS[@]}"; do
echo " $arg"
done
else
echo "No arguments provided."
fi
echo "Bootstrap completing, starting Cake..."
# Start Cake
exec dotnet cake "${SCRIPT}" "${CAKE_ARGUMENTS[@]+"${CAKE_ARGUMENTS[@]}"}"