forked from buildkite/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·214 lines (168 loc) · 5.48 KB
/
install.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/bash
#
# You can install the Buildbox Agent with the following:
#
# bash -c "`curl -sL https://raw.githubusercontent.com/buildbox/agent/master/install.sh`"
#
# For more information, see: https://github.com/buildbox/agent
COMMAND="bash -c \"\`curl -sL https://raw.githubusercontent.com/buildbox/agent/master/install.sh\`\""
LATEST_BETA="1.0-beta.6"
if [ "$VERSION" = "1.0-beta.1" ]
then
echo "NOTICE: Installing 1.0-beta.1 is no longer supported...sorry. Please install 1.0-beta.6"
exit 1
fi
if [ "$VERSION" = "1.0-beta.2" ]
then
echo "NOTICE: Installing 1.0-beta.2 is no longer supported...sorry. Please install 1.0-beta.6"
exit 1
fi
if [ "$BETA" = "true" ]
then
VERSION=$LATEST_BETA
fi
# Allow custom setting of the version
if [ -z "$VERSION" ]; then
VERSION="0.2"
fi
set -e
function buildbox-download {
if command -v wget >/dev/null
then
if [ "$DEBUG" = "true" ]
then
wget $1 -O $2
else
wget -q $1 -O $2
fi
else
if [ "$DEBUG" = "true" ]
then
curl -L -o $2 $1
else
curl -L -s -o $2 $1
fi
fi
}
echo -e "\033[33m
_ _ _ _ _ _
| | (_) | | | | | |
| |__ _ _ _| | __| | |__ _____ __ __ _ __ _ ___ _ __ | |_
| '_ \| | | | | |/ _\` | '_ \ / _ \ \/ / / _\` |/ _\` |/ _ \ '_ \| __|
| |_) | |_| | | | (_| | |_) | (_) > < | (_| | (_| | __/ | | | |_
|_.__/ \__,_|_|_|\__,_|_.__/ \___/_/\_\ \__,_|\__, |\___|_| |_|\__|
__/ |
|___/\033[0m
-- https://buildbox.io
Installing Version: \033[35mv$VERSION\033[0m"
UNAME=`uname -sp | awk '{print tolower($0)}'`
if [[ ($UNAME == *"mac os x"*) || ($UNAME == *darwin*) ]]
then
PLATFORM="darwin"
else
PLATFORM="linux"
fi
if [[ ($UNAME == *x86_64*) || ($UNAME == *amd64*) ]]
then
ARCH="amd64"
else
ARCH="386"
fi
# Allow custom setting of the destination
if [ -z "$DESTINATION" ]; then
# But default to the home directory
DESTINATION="$HOME/.buildbox"
mkdir -p $DESTINATION
fi
if [ ! -w "$DESTINATION" ]
then
echo -e "\n\033[31mUnable to write to destination \`$DESTINATION\`\n\nYou can change the destination by running:\n\nDESTINATION=/my/path $COMMAND\033[0m\n"
exit 1
fi
echo -e "Destination: \033[35m$DESTINATION\033[0m"
# Download and unzip the file to the destination
DOWNLOAD="buildbox-agent-$PLATFORM-$ARCH.tar.gz"
URL="https://github.com/buildbox/agent/releases/download/v$VERSION/$DOWNLOAD"
echo -e "\nDownloading $URL"
# Remove the download if it already exists
rm -f $DESTINATION/$DOWNLOAD
# If the file already exists in a folder called pkg, just use that. :)
if [[ -e pkg/$DOWNLOAD ]]
then
cp pkg/$DOWNLOAD $DESTINATION/$DOWNLOAD
else
buildbox-download "$URL" "$DESTINATION/$DOWNLOAD"
fi
# Extract the download to the destination folder
tar -C $DESTINATION -zxf $DESTINATION/$DOWNLOAD
INSTALLED_VERSION=`$DESTINATION/buildbox-agent --version`
if [[ "$INSTALLED_VERSION" = "buildbox-agent version $LATEST_BETA" ]]
then
# Move the buildbox binary into a bin folder
mkdir -p $DESTINATION/bin
mv $DESTINATION/buildbox-agent $DESTINATION/bin
chmod +x $DESTINATION/bin/buildbox-agent
function shim {
echo "#!/bin/bash
DIR=\$(cd \"\$( dirname \"\${BASH_SOURCE[0]}\" )\" && pwd)
echo \"###################################################################
DEPRECATED: This binary is deprecated.
Please use: \\\`$DESTINATION/bin/buildbox-agent$1\\\`
###################################################################
\"
exit 1"
}
# Deprecate the old 1.0-beta.1 binary.
if [[ -e $DESTINATION/bin/buildbox ]]
then
shim "" > $DESTINATION/bin/buildbox
chmod +x $DESTINATION/bin/buildbox
fi
# Was there a previous agent installed?
if [[ -e $DESTINATION/buildbox-artifact ]]
then
shim " start --token 123" > $DESTINATION/buildbox-agent
shim " build-artifact" > $DESTINATION/buildbox-artifact
shim " build-data" > $DESTINATION/buildbox-data
fi
fi
chmod +x $DESTINATION/buildbox-*
# Clean up the download
rm -f $DESTINATION/$DOWNLOAD
# Copy the bootstrap sample and make sure it's writable
if [[ -e $DESTINATION/bootstrap.sh ]]
then
echo -e "\n\033[34mSkipping bootstrap.sh installation as it already exists\033[0m"
else
BOOTSTRAP_URL=https://raw.githubusercontent.com/buildbox/agent/master/templates/bootstrap.sh
BOOTSTRAP_DESTINATION=$DESTINATION/bootstrap.sh
echo -e "Downloading $BOOTSTRAP_URL"
buildbox-download "$BOOTSTRAP_URL" "$BOOTSTRAP_DESTINATION"
chmod +x $DESTINATION/bootstrap.sh
fi
# Allow custom setting of the version
if [ -z "$TOKEN" ]; then
TOKEN="token123"
fi
# Switch the start command depending on the version
if [[ -e $DESTINATION/bin/buildbox-agent ]]
then
START_COMMAND="bin/buildbox-agent start --token $TOKEN"
else
START_COMMAND="buildbox-agent start --access-token $TOKEN"
fi
echo -e "\n\033[32mSuccessfully installed to $DESTINATION\033[0m
You can now run the Buildbox agent like so:
$DESTINATION/$START_COMMAND
You can find your agent's Access Token on your Account Settings
page under \"Agents\".
To customize how builds are run on your server, you can edit:
$DESTINATION/bootstrap.sh
This file is run for every build and it's responsible for checking out
the source code and running the build script.
The source code of the agent is available here:
https://github.com/buildbox/agent
If you have any questions or need a hand getting things setup,
please email us at: [email protected]
Happy Building!
<3 Buildbox"