This repository has been archived by the owner on Mar 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
/
update.sh
executable file
·339 lines (311 loc) · 9.36 KB
/
update.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
#! /usr/bin/env bash
#=========================================================================
# Copyright (C) GemStone Systems, Inc. 2010.
#
# Name - update.sh
#
# Purpose - Automatically update to a new version of GemStone
# in an existing git repository cloned from MagLev on github.
# Be both verbose and idempotent, so we can easily diagnose
# any problems.
#
# $Id:$
#
# Description:
# Updates GemStone to a version corresponsing to $MAGLEV_HOME/version.txt
# Safe to run multiple times. Only saves one prior backup repository though.
#
# Actions:
# Download the GemStone archive into the parent directory
# Uncompress the GemStone archive in the parent directory
# Update the gemstone link to point to the new GemStone
# Backup any existing 'maglev' repository
# Wipeout any previous 'maglev' configuration file
# Create a new default repository called 'maglev'
# Generate the MagLev HTML documentation
# Print build version information
# Remind user to setup environment variables
#=========================================================================
# Defaults
export MAGLEV_SOURCE=$PWD
export MAGLEV_HOME=$PWD
export GEMSTONES_HOME=$PWD/versions
export ARCHIVES_HOME=$PWD/versions
export BACKUPS_HOME=$PWD/backups
export DISABLE_INSTALL_DOC=0
export SKIP_RC_REMINDER=0
export SKIP_STONE_START=0
export RUN_STWRAPPERS=0
export STONENAME
if [[ -z "$STONENAME" && -s .stonename && -f .stonename ]]
then STONENAME="$(cat .stonename)"
else STONENAME="${STONENAME:-maglev}"
fi
# Parse parameters
while (( $# ))
do
case "$1" in
(--prefix)
MAGLEV_HOME="$2"
shift 2
;;
(--gemstones)
GEMSTONES_HOME="$2"
shift 2
mkdir -p "$GEMSTONES_HOME"
;;
(--archives)
ARCHIVES_HOME="$2"
shift 2
mkdir -p "$ARCHIVES_HOME"
;;
(--backups)
BACKUPS_HOME="$2"
shift 2
;;
(--disable-install-doc)
DISABLE_INSTALL_DOC=1
shift
;;
(--skip-rc-reminder)
SKIP_RC_REMINDER=1
shift
;;
(--skip-stone-start)
SKIP_STONE_START=1
shift
;;
(--run-stwrappers)
RUN_STWRAPPERS=1
shift
;;
(--stonename)
STONENAME="$2"
shift 2
;;
(--help)
printf "%b" "Usage:\n./update.sh [--prefix <prefix>] [--gemstone <gemstone>] [--archives <archives] [--backups <backups>] [--disable-install-doc] [--skip-rc-reminder] [--skip-stone-start] [--run-stwrappers] [--stonename <stonename>]\n"
exit 0
;;
(*)
echo "[ERROR] Unknown flag '$1'."
printf "%b" "Usage:\n./update.sh [--prefix <prefix>] [--gemstone <gemstone>] [--archives <archives] [--backups <backups>] [--disable-install-doc] [--skip-rc-reminder] [--skip-stone-start] [--run-stwrappers] [--stonename <stonename>]\n"
exit 1
;;
esac
done
echo "$STONENAME" > .stonename
# check if it's proper maglev source
[[ -x "${MAGLEV_SOURCE}/bin/maglev-ruby" ]] || {
echo "[Error] $PWD is not a valid MagLev directory"
echo "To fix this, 'clone git://github.com:MagLev/maglev.git'"
echo "then run install.sh from the resulting directory."
exit 1
}
# Make the archives directory
[[ -w "$GEMSTONES_HOME" ]] || {
mkdir -p "$GEMSTONES_HOME"
}
# We should run this as a normal user, not root.
[[ $UID -ge 0 ]] || {
echo "[Error] This script should be run as a normal user, not root."
exit 1
}
function ensure()
{
"$@" || {
typeset _ret=$?
echo "[Error] execution failed for '$*' with error ${_ret}."
exit ${_ret}
}
}
source ./build_functions.sh
# Detect operating system
PLATFORM="`uname -sm | tr ' ' '-'`"
# Macs with Core i7 use the same software as older Macs
[[ $PLATFORM == "Darwin-x86_64" ]] && PLATFORM="Darwin-i386"
gsvers=`grep ^GEMSTONE version.txt | cut -f2 -d-`
gss_name="GemStone-${gsvers}.${PLATFORM}"
gss_file="${gss_name}.tar.gz"
# We're good to go. Let user know.
machine_name="`uname -n`"
echo "[Info] Installing $gss_name on $machine_name"
# Look for either wget or curl to download GemStone
if [ -e "`which wget 2>/dev/null`" ]; then
cmd="`which wget`"
elif [ -e "`which curl 2>/dev/null`" ]; then
cmd="`which curl` -s -O"
else
echo "[Error] Neither wget nor curl is available. Install one of them and rerun this script."
exit 1
fi
# Download appropriate version of GemStone
builtin cd "${GEMSTONES_HOME}"
if
[[ -e "$gss_file" ]]
then
echo "[Info] $gss_file already exists"
echo "to replace it, remove or rename it and rerun this script"
else
# Look for either wget or curl to download GemStone
if
[[ -e "`which wget 2>/dev/null`" ]]
then
cmd="`which wget` --quiet"
elif
[[ -e "`which curl 2>/dev/null`" ]]
then
cmd="`which curl` -s -O"
else
echo "[Error] Neither wget nor curl is available. Install one of them and rerun this script."
exit 1
fi
echo "[Info] Downloading $gss_file using ${cmd}"
ensure $cmd http://seaside.gemtalksystems.com/maglev/$gss_file
fi
# Uncompress the downloaded GemStone archive in the current directory
if
[[ -e "$gss_name" ]]
then
echo "[Warning] $gss_name already exists"
echo "to replace it, remove or rename it and rerun this script"
else
echo "[Info] Uncompressing $gss_file in $PWD"
ensure tar xzf "$gss_file"
fi
# Create a link to the GemStone directory
echo "[Info] Linking $gss_name to ${MAGLEV_SOURCE}/gemstone"
rm -f "$MAGLEV_SOURCE/gemstone"
ln -sf "${GEMSTONES_HOME}/$gss_name" "$MAGLEV_SOURCE/gemstone"
# Finally get back to the MagLev directory
builtin cd "${MAGLEV_SOURCE}"
# Make sure we have a locks directory
mkdir -p locks
# and the correct updated keyfile
rm -f etc/maglev.demo.key
ln -sf maglev.demo.key-$PLATFORM etc/maglev.demo.key
# Make sure we have specs and benchmarks.
echo "[Info] updating MSpec and RubySpec submodules"
ensure git submodule --quiet update --init
# Check for existence of required executable rake
if
which rake > /dev/null 2>&1
then
# Backup any existing maglev repository
if
[[ -e "${MAGLEV_HOME}/data/maglev/extent/extent0.ruby.dbf" ]]
then
[[ "$BACKUPS_HOME" == "$PWD/backups" ]] || {
rm -rf backups
ln -s "$BACKUPS_HOME/" backups
}
echo "[Info] Backing up existing 'maglev' repository to $BACKUPS_HOME/previous_maglev_extent.tgz"
rake maglev:take_snapshot >/dev/null
mv backups/maglev_extent.tgz backups/previous_maglev_extent.tgz
fi
else
echo "[Warning] rake not found!"
echo " Skipping backup and HTML documentation."
fi
[[ "$MAGLEV_SOURCE" == "$MAGLEV_HOME" ]] || {
echo "[Info] Coping MagLev to target location $MAGLEV_HOME"
if [[ -d "$MAGLEV_HOME" ]]
then rm -rf "$MAGLEV_HOME"
fi
cp -rf "$MAGLEV_SOURCE" "$MAGLEV_HOME"
# Make sure we are in MagLev target directory
builtin cd "${MAGLEV_SOURCE}"
}
# setup topaz environment
export GEMSTONE GEMSTONE_GLOBAL_DIR GEMSTONE_SYS_CONF GEMSTONE_DATADIR GEMSTONE_LOG
GEMSTONE="${MAGLEV_HOME}/gemstone"
GEMSTONE_GLOBAL_DIR="$MAGLEV_HOME"
GEMSTONE_SYS_CONF="${MAGLEV_HOME}/etc/system.conf"
GEMSTONE_DATADIR="${MAGLEV_HOME}/data/${STONENAME}"
GEMSTONE_LOG="${MAGLEV_HOME}/log/${STONENAME}/${STONENAME}.log"
# Create a default repository called "maglev" and generate the MagLev HTML documentation
#TODO: stop stone if running
# create a clean slate
if
[[ -e etc/conf.d/maglev.conf ]]
then
echo "[Info] Removing existing '${STONENAME}' configuration file."
rm -rf "${GEMSTONE_DATADIR}"
rm -rf "${MAGLEV_HOME}/etc/conf.d/${STONENAME}.conf"
rm -rf "${MAGLEV_HOME}/log/${STONENAME}"
fi
if
[[ -e "${MAGLEV_HOME}/bin/extent0.ruby.dbf" ]]
then
[[ -e etc/conf.d/maglev.conf ]] || build_maglev_stone_create
else
extent0='gemstone/bin/extent0.dbf'
if
[[ -e $extent0 ]]
then
if
build_maglev
then
if
[[ $DISABLE_INSTALL_DOC == 0 ]] &&
[[ -x "${MAGLEV_HOME}/bin/rake" ]]
then
echo "[Info] Generating the MagLev HTML documentation"
env GEM_HOME="" GEM_PATH="${MAGLEV_HOME}/lib/maglev/gems/1.8/gems" \
"${MAGLEV_HOME}/bin/rake" rdoc >/dev/null 2>&1
fi
else
echo "[Error] Could not build new ruby extent"
exit 1
fi
else
echo "[Warning] Can't find ${extent0}: Skip building ruby extent"
fi
fi
if
[[ $RUN_STWRAPPERS == 1 ]]
then
#rake stwrappers
wrapper_dir="${MAGLEV_HOME}/lib/ruby/site_ruby/1.8/smalltalk"
if
[[ -e "${wrapper_dir}" ]]
then
echo "[Info] Smalltalk FFI already exist."
else
echo "[Info] Generating smalltalk FFI."
#TODO: what was the % supposed to do?
run_on_stone "omit resultcheck" "run" "RubyContext createSmalltalkFFIWrappers" "%"
fi
fi
if
[[ $SKIP_STONE_START == 0 ]]
then
echo "[Info] Starting MagLev stone (loading kernel classes)"
"$MAGLEV_HOME/bin/maglev" start
fi
echo
echo "[Info] Finished upgrade to $gss_name on $machine_name"
echo ""
echo "[Info] MagLev version information:"
cat version.txt
echo "[Info] GemStone version information:"
cat gemstone/version.txt
# Reminder to setup environment variables
if
[[ $SKIP_RC_REMINDER == 0 ]]
then
echo ""
echo "[Info] Adding these to your .bashrc will make it easier to run MagLev"
echo "export MAGLEV_HOME=${PWD}"
echo 'export PATH=$MAGLEV_HOME/bin:$PATH'
fi
# Reminder to generate Smalltalk FFI
if
[[ $RUN_STWRAPPERS == 0 ]]
then
echo ""
echo "[Info] If you want to call GemStone Smalltalk methods from Ruby, run"
echo " rake stwrappers"
echo "after this upgrade has finished. This will generate .rb files you can use"
echo "in \$MAGLEV_HOME/lib/ruby/site_ruby/1.8/smalltalk/"
fi