forked from GsSqueak/GsSqueak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·528 lines (451 loc) · 15.1 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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
#!/usr/bin/env bash
################################################################################
# Variables used throughout the whole program.
################################################################################
OUTPUT=
GEMSTONE_VERSION=
EA_VERSION=
STONE_NAME=
FORCE=false
################################################################################
# Set colors used by console prints as environment variables.
################################################################################
readonly YELLOW='\033[1;33m'
readonly ORANGE='\033[0;33m'
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly NC='\033[0m' # No Color
################################################################################
# Set status messages used to display the current progress
################################################################################
readonly SUCCESS="[ ${GREEN}SUCCESS${NC} ]"
readonly ERRORED="[ ${RED}ERRORED${NC} ]"
readonly PENDING="[ ${YELLOW}PENDING${NC} ]"
readonly REQUIRE="[ ${YELLOW}REQUIRE${NC} ]"
readonly WARNING="[ ${ORANGE}WARNING${NC} ]"
################################################################################
# Print usage of this program
################################################################################
install_usage() {
echo "NAME
install.sh - install GsSqueak and its dependencies
SYNOPSIS
./install.sh [OPTION]...
ARGUMENTS
-h, --help
display this manual
-s, --stone-name
Name of the GsSqueak-Stone [default: gsSqueak]
-f, --force
Force new stone creation
--gs-version
GemStone/S Version Number [default: 3.5.0]
--ea-version
GemStone/S EA Version Number [default: -EA-43870]
"
exit 0
}
################################################################################
# Rewrite current command as errored and print command output.
################################################################################
print_pending() {
local message
message="$1"
echo -ne "${PENDING} ${message}"
}
################################################################################
# Rewrite current command as errored and print command output.
################################################################################
print_success() {
echo -e "\r${SUCCESS}"
}
################################################################################
# Checks wheter the last command was successful
# global:
# ? exit code of last command
################################################################################
check_errors() {
if [[ $? -gt 0 ]]; then
errored
else
print_success
fi
}
################################################################################
# Checks whether the last command have a non-zero exit code. If not, emit a warning.
# global:
# ? exit code of last command
################################################################################
check_warning() {
if [[ $? -gt 0 ]]; then
warn
else
print_success
fi
}
################################################################################
#
################################################################################
warn() {
local message
message="$1"
echo -e "\r$WARNING"
if ! [[ -z "${message}" ]]; then
echo -e "${WARNING} Message: $message"
fi
if ! [[ -z "${OUTPUT}" ]]; then
echo -e "${WARNING} Command output:"
echo "$OUTPUT"
OUTPUT=''
fi
}
################################################################################
# Rewrite current command as errored and print command output.
# local:
# OUTPUT
################################################################################
errored() {
local message
message="$1"
echo -e "\r${ERRORED}"
if ! [[ -z "${message}" ]]; then
echo -e "${ERRORED} Message: $message"
fi
if ! [[ -z "${OUTPUT}" ]]; then
echo -e "${ERRORED} Command output:"
echo "$OUTPUT"
OUTPUT=''
fi
exit 1
}
################################################################################
# Exit program, because GemStone bin scripts are missing.
################################################################################
gemstone_scripts_path_error() {
echo -e "GemStone scripts are not added to path"
exit 1
}
################################################################################
# Checks whether the latest bash version is installed
################################################################################
check_bash_version() {
if ! [[ ( ${BASH_VERSINFO[0]} -ge 4 ) && ( ${BASH_VERSINFO[1]} -ge 3 ) ]]; then
echo -e "$ERRORED You need at least bash version greater than 4.3.0, your version: $BASH_VERSION"
exit 1
fi
}
################################################################################
# Get user input
################################################################################
get_user_input() {
local message options default result
declare -n __resultVar=$4
message="$1"
options="$2"
default="$3"
printf "$REQUIRE $message [ $options ] "
read __resultVar
__resultVar=${__resultVar:-${default}}
}
################################################################################
# Abort if os requirements are not met.
################################################################################
check_gs_devkit() {
local response
pushd GsDevKit_home >/dev/null 2>&1
. bin/defHOME_PATH.env >/dev/null 2>&1 # define GS_HOME env var and put $GS_HOME into PATH
popd >/dev/null 2>&1
if [[ -z "${GS_HOME+x}" ]]; then
get_user_input "Do you want to install GsDevKit_home?" "Y | n" Y response
if [[ "${response,,}" = y ]]; then
install_gs_devkit
else
echo -e "$ERRORED GsDevKit_home missing"
exit 1
fi
else
installServerClient >/dev/null 2>&1
fi
ln -fs ../../../ . >/dev/null 2>&1
}
################################################################################
# Abort if os requirements are not met.
################################################################################
install_gs_devkit() {
print_pending "Cloning GsDevKit_home"
git clone -q https://github.com/GsDevKit/GsDevKit_home.git
check_errors
pushd GsDevKit_home >/dev/null
. bin/defHOME_PATH.env # define GS_HOME env var and put $GS_HOME into PATH
popd >/dev/null
print_pending "Installing GsDevKit_home "
installServerClient >/dev/null 2>&1
check_errors
echo "To use GemStone scripts, please define GS_HOME environment variable as GsDevKit_home and put \$GS_HOME into PATH"
}
output () {
local command
command=$@
OUTPUT="$($command)"
}
################################################################################
# Abort installation if required environment variables are missing.
#
# globals:
# GS_HOME
################################################################################
check_env_variables() {
which createClient >/dev/null 2>&1
if [[ $? -gt 0 ]]; then
gemstone_scripts_path_error
fi
which createStone >/dev/null 2>&1
if [[ $? -gt 0 ]]; then
gemstone_scripts_path_error
fi
which todeIt >/dev/null 2>&1
if [[ $? -gt 0 ]]; then
gemstone_scripts_path_error
fi
which downloadGemStone >/dev/null 2>&1
if [[ $? -gt 0 ]]; then
gemstone_scripts_path_error
fi
}
################################################################################
# Abort if os requirements are not met.
################################################################################
check_os() {
readonly unamestr=`uname`
if ! [[ "$unamestr" == 'Linux' || "$unamestr" == 'Darwin' ]]; then
errored "Operating system not supported. Please open an issue for your OS."
exit 1
fi
}
################################################################################
# Update Glass Repository to work with newest EA
################################################################################
updateGlass() {
echo '*core-squeak
parseSelector: methodString for: aBehavior
| selector mDict cDict meth undefinedSymbolList |
mDict := GsMethodDictionary new.
cDict := GsMethodDictionary new.
undefinedSymbolList := GsSession currentSession symbolList objectNamed: #UndefinedSymbolList.
undefinedSymbolList == nil ifTrue: [ undefinedSymbolList := SymbolList new ].
meth := aBehavior
_primitiveCompileMethod: methodString
symbolList: GsSession currentSession symbolList, undefinedSymbolList
category: #xxxyyz
oldLitVars: nil
intoMethodDict: mDict
intoCategories: cDict.
meth class ~~ GsMethod
ifTrue: [
(meth at: 2) == nil ifFalse: [ ^nil ].
meth := (meth at: 1).
].
^meth selector asString.' > "$GS_HOME/shared/repos/glass/repository/Core.package/Behavior.extension/class/parseSelector.for..st"
echo '*core-squeak
parseSelector: methodString for: aBehavior
| mDict cDict meth undefinedSymbolList |
mDict := GsMethodDictionary new.
cDict := GsMethodDictionary new.
undefinedSymbolList := GsSession currentSession symbolList objectNamed: #UndefinedSymbolList.
undefinedSymbolList == nil ifTrue: [ undefinedSymbolList := SymbolList new ].
meth := aBehavior
_primitiveCompileMethod: methodString
symbolList: GsSession currentSession symbolList, undefinedSymbolList
category: #xxxyyz
oldLitVars: nil
intoMethodDict: mDict
intoCategories: cDict
environmentId: 0 .
meth class ~~ GsNMethod
ifTrue: [
(meth at: 2) == nil ifFalse: [ ^nil ].
meth := (meth at: 1).
].
^meth selector asString.' > "$GS_HOME/shared/repos/glass/repository/Core.v3.package/Behavior.extension/class/parseSelector.for..st"
}
################################################################################
# Downloads specified GemStone Version
################################################################################
download_gemstone() {
download_gemstone_usage () { echo "$0 <gemstone_version> [<early_access_version>]"; exit 1;}
updateGlass
local gs_version ea_version
if [[ -z "${1+x}" && -z "${2+x}" ]]; then
download_gemstone_usage
fi
gs_version="$1"
ea_version="$2"
if ! [[ -n $(find "$GS_HOME/shared/downloads/products" -name "GemStone64Bit${gs_version}*") ]]; then
find "$GS_HOME/shared/downloads/products" -name "GemStone64Bit${gs_version}*" -exec chmod -R 777 "{}" \; -exec rm -rf "{}" \; >/dev/null 2>&1
output downloadGemStone -f -d ${gs_version}-${ea_version} $gs_version >/dev/null 2>&1
fi
}
################################################################################
#
################################################################################
check_stone_exists () {
stones 2>&1 | grep -e "\s${stone_name}\$" >/dev/null
return $?
}
################################################################################
#
################################################################################
setup_gs_squeak() {
local repo_path stone_name gs_version stone_exists response
repo_path=$PWD/squeak-modifications/pre-squeak-import
stone_name="$1"
gs_version="$2"
print_pending "Checking for Stone $stone_name"
check_stone_exists $stone_name
stone_exists=$?
print_success
if [[ $stone_exists = 0 ]]; then
if [[ $FORCE = true ]]; then
print_pending "Recreating stone named $stone_name"
output createStone -fn "$stone_name" $gs_version >/dev/null 2>&1
check_errors
else
echo -e "$WARNING Stone named $stone_name already exists"
get_user_input "Do you want to recreate it?" "[o]verwrite | [R]ESTORE | [a]bort" r response
case "${response,,}" in
o)
print_pending "Recreating stone named $stone_name"
output createStone -fn "$stone_name" $gs_version >/dev/null 2>&1
check_errors
;;
r)
print_pending "Restoring stone named $stone_name from tode backup"
startStone $stone_name >/dev/null 2>&1
startNetldi $stone_name >/dev/null 2>&1
output todeRestore "$stone_name" tode.dbf >/dev/null 2>&1
check_errors
;;
a)
echo -e "$SUCCESS Aborting.. That's okay."
exit 0
;;
*)
echo -e "$ERRORED Unknown option"
exit 1 # TODO looooooop!
;;
esac
fi
else
print_pending "Creating stone named $stone_name"
output createStone -n "$stone_name" $gs_version > /dev/null 2>&1
check_errors
print_pending "Installing Graphics Library"
pushd "graffics" > /dev/null
export GEMSTONE="${GS_HOME}/server/stones/${stone_name}/product"
output make install
check_errors
popd > /dev/null
fi
print_pending "Executing topaz script"
startTopaz $stone_name -l >/dev/null 2>&1 << EOF
set u SystemUser p swordfish
login
run
SystemObjectSecurityPolicy worldAuthorization: #write.
(AllUsers userWithId: 'DataCurator') addPrivilege: #'CompilePrimitives'.
%
run
GsCompilerClasses keysAndValuesDo: [:symbol : class | Globals at: symbol put: class ]
%
commit
logout
login
input $GS_HOME/server/stones/$stone_name/product/upgrade/GsNMethodIr.gs
commit
logout
set u DataCurator p swordfish
login
method: Behavior
_clearSubclassesDisallowed
self _unsafeAt: 2 put: (format bitAnd: (16r20 bitInvert))
%
send Behavior _clearSubclassesDisallowed
send LargeInteger _clearSubclassesDisallowed
env 7
method: Class
name
^ self @env0: name
%
commit
logout
exit
EOF
check_errors
print_pending "Raising Gem VM memory limits for Squeak import"
pushd "${GS_HOME}/server/stones/${stone_name}" > /dev/null
find . -name '*.conf' | xargs sed -i 's/GEM_TEMPOBJ_CACHE_SIZE = 50000;/GEM_TEMPOBJ_CACHE_SIZE = 500000;/g'
find . -name '*.conf' | xargs sed -i 's/SHR_PAGE_CACHE_SIZE_KB = 500000;/SHR_PAGE_CACHE_SIZE_KB = 5000000;/g'
check_errors
popd > /dev/null
pushd $repo_path >/dev/null
for package in *.package; do
local package_name=$(echo "$package" | cut -d'.' -f 1)
print_pending "Loading $package_name"
output todeIt $stone_name mc load "$package_name" filetree://$repo_path >/dev/null 2>&1
check_errors
done
popd >/dev/null
print_pending "Saving State to Backup \"sq-prep\""
output todeBackup $stone_name sq-prep >/dev/null 2>&1
check_errors
}
################################################################################
# Parameter handling
################################################################################
POSITIONAL=()
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-h|--help)
install_usage
exit 0
;;
--gs-version)
GEMSTONE_VERSION="$2"
shift # past argument
shift # past value
;;
--ea-version)
EA_VERSION="$2"
shift
shift
;;
-s|--stone-name)
STONE_NAME="$2"
shift
shift
;;
-f|--force)
FORCE=true
shift
;;
*) # unknown option
install_usage
# not supported
POSITIONAL+=("$1") # save it in an array for later
shift # past argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
STONE_NAME="${STONE_NAME:-gsSqueak}"
GEMSTONE_VERSION="${GEMSTONE_VERSION:-3.5.0}"
EA_VERSION="${EA_VERSION:-EA-44511}"
check_os
check_gs_devkit
check_env_variables
print_pending "Downloading GemStone $GEMSTONE_VERSION-$EA_VERSION"
download_gemstone $GEMSTONE_VERSION $EA_VERSION
check_warning
setup_gs_squeak $STONE_NAME $GEMSTONE_VERSION
echo "finished."