-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstall.sh
executable file
·383 lines (319 loc) · 9.83 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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# Copyright (C) 2014-2015 Droonga Project
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1 as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# Usage:
#
# Ubuntu:
#
# Install a release version:
# $ curl https://raw.githubusercontent.com/droonga/droonga-engine/master/install.sh | sudo bash
# Install the latest revision from the repository:
# $ curl https://raw.githubusercontent.com/droonga/droonga-engine/master/install.sh | sudo VERSION=master bash
# Install with the specified hostname (disabling auto-detection):
# $ curl https://raw.githubusercontent.com/droonga/droonga-engine/master/install.sh | sudo HOST=xxx.xxx.xxx.xxx bash
#
# CentOS 7:
#
# Install a release version:
# # curl https://raw.githubusercontent.com/droonga/droonga-engine/master/install.sh | bash
# Install the latest revision from the repository:
# # curl https://raw.githubusercontent.com/droonga/droonga-engine/master/install.sh | VERSION=master bash
# Install with the specified hostname (disabling auto-detection):
# # curl https://raw.githubusercontent.com/droonga/droonga-engine/master/install.sh | HOST=xxx.xxx.xxx.xxx bash
NAME=droonga-engine
DOWNLOAD_URL_BASE=https://raw.githubusercontent.com/droonga/$NAME
REPOSITORY_URL=https://github.com/droonga/$NAME.git
DROONGA_CLIENT_RUBY_REPOSITORY_URL=https://github.com/droonga/droonga-client-ruby.git
DRNDUMP_REPOSITORY_URL=https://github.com/droonga/drndump.git
RROONGA_REPOSITORY_URL=https://github.com/ranguba/rroonga.git
GROONGA_COMMAND_REPOSITORY_URL=https://github.com/groonga/groonga-command.git
GROONGA_COMMAND_PARSER_REPOSITORY_URL=https://github.com/groonga/groonga-command-parser.git
USER=$NAME
GROUP=droonga
DROONGA_BASE_DIR=/home/$USER/droonga
TEMPDIR=/tmp/install-$NAME
: ${VERSION:=release}
: ${HOST:=Auto Detect}
: ${PORT:=10031}
: ${INSTALL_FROM_REPOSITORY:=$NAME}
case $(uname) in
Darwin|*BSD|CYGWIN*) sed="sed -E" ;;
*) sed="sed -r" ;;
esac
ensure_root() {
if [ "$EUID" != "0" ]; then
echo "You must run this script as the root."
exit 1
fi
}
guess_platform() {
if [ -e /etc/debian_version ] || [ -e /etc/debian_release ]; then
echo "debian"
return 0
elif [ -e /etc/centos-release ]; then
echo "centos"
return 0
fi
return 1
}
exist_command() {
type "$1" > /dev/null 2>&1
}
exist_all_commands() {
for command in $@; do
if ! exist_command $command; then
return 1
fi
done
return 0
}
exist_yum_repository() {
if ! yum --enablerepo=$1 repolist; then
return 1
fi
yum --enablerepo=$1 repolist | grep --quiet "$1"
}
exist_user() {
id "$1" > /dev/null 2>&1
}
prepare_user() {
echo ""
echo "Preparing the user..."
groupadd $GROUP
if ! exist_user $USER; then
useradd -m $USER
fi
usermod -G $GROUP $USER
return 0
}
setup_configuration_directory() {
echo ""
echo "Setting up the configuration directory..."
[ ! -e $DROONGA_BASE_DIR ] &&
mkdir $DROONGA_BASE_DIR
if [ ! -e $DROONGA_BASE_DIR/catalog.json -o \
! -e $DROONGA_BASE_DIR/$NAME.yaml ]; then
[ "$HOST" = "Auto Detect" ] &&
HOST=$(determine_hostname)
if [ "$HOST" = "" ]; then
HOST=$(hostname)
echo "********************** CAUTION!! **********************"
echo "Installation process coudln't detect the hostname of"
echo "this node, which is accessible from other nodes."
echo "You may have to configure droonga-engine manually"
echo "to refer a valid accessible hostname for this node,"
echo "by following command line:"
echo ""
echo " droonga-engine-configure --reset-config --reset-catalog"
echo "*******************************************************"
fi
echo "This node is configured with a hostname $HOST."
fi
# we should use --no-prompt instead of --quiet, for droonga-engine 1.0.8 and later.
droonga-engine-configure --quiet \
--host=$HOST --port=$PORT
if [ $? -ne 0 ]; then
echo "ERROR: Failed to configure $NAME!"
exit 1
fi
chown -R $USER:$GROUP $DROONGA_BASE_DIR
}
guess_global_hostname() {
if hostname -d > /dev/null 2>&1; then
local domain=$(hostname -d)
local hostname=$(hostname -s)
if [ "$domain" != "" ]; then
echo "$hostname.$domain"
return 0
fi
fi
echo ""
return 1
}
determine_hostname() {
local global_hostname=$(guess_global_hostname)
if [ "$global_hostname" != "" ]; then
echo "$global_hostname"
return 0
fi
local address=$(hostname -i | \
$sed -e "s/127\.[0-9]+\.[0-9]+\.[0-9]+//g" \
-e "s/[0-9a-f:]+%[^ ]+//g" \
-e "s/ +/ /g" \
-e "s/^ +| +\$//g" |\
cut -d " " -f 1)
if [ "$address" != "" ]; then
echo "$address"
return 0
fi
echo ""
return 1
}
download_url() {
if [ "$VERSION" != "release" ]; then
echo "$DOWNLOAD_URL_BASE/master/$1"
else
echo "$DOWNLOAD_URL_BASE/v$(installed_version)/$1"
fi
}
installed_version() {
$NAME --version | cut -d " " -f 2
}
install_gem_from_repository() {
GEM_NAME=$1
GEM_REPOSITORY_URL=$2
cd $TEMPDIR
if [ -d $GEM_NAME ]
then
cd $GEM_NAME
git reset --hard
git pull --rebase
git checkout master
bundle update
else
git clone $GEM_REPOSITORY_URL
cd $GEM_NAME
git checkout master
bundle install --path vendor/
fi
rm -rf pkg
bundle exec rake build
gem install "pkg/*.gem" --no-ri --no-rdoc
}
install_from_repository() {
gem install bundler --no-ri --no-rdoc
if echo "$INSTALL_FROM_REPOSITORY" | grep "rroonga"
then
install_gem_from_repository rroonga $RROONGA_REPOSITORY_URL
install_gem_from_repository groonga-command $GROONGA_COMMAND_REPOSITORY_URL
install_gem_from_repository groonga-command-parser $GROONGA_COMMAND_PARSER_REPOSITORY_URL
else
rm -rf $TEMPDIR/rroonga
rm -rf $TEMPDIR/groonga-command
rm -rf $TEMPDIR/groonga-command-parser
fi
if echo "$INSTALL_FROM_REPOSITORY" | grep "client"
then
install_gem_from_repository droonga-client-ruby $DROONGA_CLIENT_RUBY_REPOSITORY_URL
else
rm -rf $TEMPDIR/droonga-client-ruby
fi
if echo "$INSTALL_FROM_REPOSITORY" | grep "drndump"
then
install_gem_from_repository drndump $DRNDUMP_REPOSITORY_URL
else
rm -rf $TEMPDIR/drndump
fi
install_gem_from_repository $NAME $REPOSITORY_URL
}
register_service() {
local unit=$NAME.service
curl -s -o /etc/systemd/system/$unit $(download_url "install/$unit")
if [ $? -ne 0 ];then
echo "ERROR: Failed to download systemd unit file!"
exit 1
fi
systemctl enable $unit
}
# ====================== for Debian/Ubuntu ==========================
prepare_environment_in_debian() {
local use_groonga_package=no
if apt-cache policy | grep --quiet groonga; then
use_groonga_package=yes
else
if [ "$(lsb_release -i -s)" = "Ubuntu" ]; then
add-apt-repository -y ppa:groonga/ppa
use_groonga_package=yes
else
local groonga_list=/etc/apt/sources.list.d/groonga.list
echo "deb http://packages.groonga.org/debian/ wheezy main" >> $groonga_list
echo "deb-src http://packages.groonga.org/debian/ wheezy main" >> $groonga_list
apt-get update
apt-get install -y --allow-unauthenticated groonga-keyring
use_groonga_package=yes
fi
fi
apt-get update
apt-get install -y curl ruby ruby-dev build-essential
if [ "$use_groonga_package" = "yes" ]; then
apt-get install -y libgroonga-dev
fi
if [ "$VERSION" != "release" ]; then
apt-get install -y git
fi
}
# ====================== /for Debian/Ubuntu =========================
# ========================= for CentOS 7 ============================
prepare_environment_in_centos() {
local use_groonga_package=no
if ! exist_yum_repository groonga; then
rpm -ivh http://packages.groonga.org/centos/groonga-release-1.1.0-1.noarch.rpm
# disable it by default!
groonga_repo=/etc/yum.repos.d/groonga.repo
backup=/tmp/$(basename $groonga_repo).bak
mv $groonga_repo $backup
cat $backup | $sed -e "s/enabled=1/enabled=0/" \
> $groonga_repo
fi
if exist_yum_repository groonga; then
use_groonga_package=yes
yum -y --enablerepo=groonga makecache
else
yum -y makecache
fi
yum -y groupinstall development
yum -y install curl ruby-devel
if [ "$use_groonga_package" = "yes" ]; then
yum -y --enablerepo=groonga install groonga-devel
fi
if [ "$VERSION" != "release" ]; then
yum -y install git
fi
}
# ========================= /for CentOS 7 ===========================
install() {
mkdir -p $TEMPDIR
echo "Preparing the environment..."
prepare_environment_in_$PLATFORM
gem update --system
gem update --no-document
echo ""
if [ "$VERSION" != "release" ]; then
echo "Installing $NAME from the git repository..."
install_from_repository
else
echo "Installing $NAME from RubyGems..."
gem install droonga-engine --no-document
fi
if ! exist_command droonga-engine; then
echo "ERROR: Failed to install $NAME!"
exit 1
fi
prepare_user
setup_configuration_directory
echo ""
echo "Registering $NAME as a service..."
# this function is defined by the downloaded "functions.sh"!
register_service $NAME $USER $GROUP
echo ""
echo "Successfully installed $NAME."
}
ensure_root
PLATFORM=$(guess_platform)
if [ "$PLATFORM" = "" ]; then
echo "Not supported platform."
exit 255
fi
install
exit 0