-
Notifications
You must be signed in to change notification settings - Fork 4
/
install_script
executable file
·446 lines (344 loc) · 11.2 KB
/
install_script
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
#!/bin/bash
###########################################################################
# Install Script - Start/Stop Script for Domino on xLinux/zLinux/AIX #
# Version 4.0.1 07.08:2024 #
# #
# (C) Copyright Daniel Nashed/NashCom 2005-2024 #
# Feedback [email protected] #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #
# you may not use this file except in compliance with the License. #
# You may obtain a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.#
# See the License for the specific language governing permissions and #
# limitations under the License. #
###########################################################################
SCRIPT_NAME=$0
PARAM1=$1
SCRIPT_DIR=$(dirname $SCRIPT_NAME)
START_SCRIPT_DIR=$SCRIPT_DIR
DOMINO_INSTALL_CONFIG_FILE=$SCRIPT_DIR/sysconfig/rc_domino_config
DOMINO_INSTALL_CONFIG_TARGET=/etc/sysconfig/rc_domino_config
DOMINO_DOCKER_SCRIPT=entrypoint.sh
DONT_TOUCH_THIS_NASHCOM_PATH=/opt/nashcom/startscript
DONT_TOUCH_THIS_STANDARD_USER=notes
DOMINO_SCRIPT_VERSION=4.0.1
# if you really really need to, change this and all files will be patched
if [ -z "$DOMINO_START_SCRIPT_DIR" ]; then
DOMINO_START_SCRIPT_DIR=/opt/nashcom/startscript
fi
if [ -z "$DOMINO_USER" ]; then
DOMINO_USER=notes
fi
if [ -z "$DOMINO_GROUP" ]; then
DOMINO_GROUP=notes
fi
ROOT_USER=root
ROOT_GROUP=root
if [ -z "$DOMINO_DATA_PATH" ]; then
DOMINO_DATA_PATH=/local/notesdata
fi
DOMINO_SCRIPT_BIN=/usr/bin/domino
#DOMINO_DEBUG_MODE="yes"
if [ "$START_SCRIPT_DIR" = "/" ]; then
START_SCRIPT_DIR=""
fi
if [ ! $EUID = "0" ]; then
echo "Terminating installation - Please run as root user!"
exit 1
fi
# first check standard location for existing config
if [ -r "$DOMINO_INSTALL_CONFIG_TARGET" ]; then
. $DOMINO_INSTALL_CONFIG_TARGET
else
# use fresh config (might be still customized)
if [ -r "$DOMINO_INSTALL_CONFIG_FILE" ]; then
. $DOMINO_INSTALL_CONFIG_FILE
else
echo "Terminating installation - cannot read config file! [$DOMINO_INSTALL_CONFIG_FILE]"
exit 1
fi
fi
# Determine architecture and platform
if [ $(uname) = "AIX" ]; then
LARCH=ibmpow
PLATFORM_NAME=AIX
ROOT_GROUP=system
else
LARCH=linux
PLATFORM_NAME=xLinux
fi
header()
{
echo
echo "$@"
echo
}
DebugText()
{
if [ "$DOMINO_DEBUG_MODE" = "yes" ]; then
if [ -z "$DOMINO_DEBUG_FILE" ]; then
echo "Debug: $@"
else
echo "Debug: $@" >> $DOMINO_DEBUG_FILE
fi
fi
return 0
}
create_link()
{
if [ -z "$1" ]; then
return 0
fi
if [ -z "$2" ]; then
return 0
fi
if [ -e "$2" ]; then
echo "link already exists [$2]"
return 0
fi
if [ ! -r "$1" ]; then
return 0
fi
ln -s "$1" "$2"
}
nsh_cmp()
{
if [ -z "$1" ]; then
return 1
fi
if [ -z "$2" ]; then
return 1
fi
if [ ! -e "$1" ]; then
return 1
fi
if [ ! -e "$2" ]; then
return 1
fi
if [ -x /usr/bin/cmp ]; then
cmp -s "$1" "$2"
return $?
fi
HASH1=$(sha256sum "$1" | cut -d" " -f1)
HASH2=$(sha256sum "$2" | cut -d" " -f1)
if [ "$HASH1" = "$HASH2" ]; then
return 0
fi
return 1
}
install_file()
{
SOURCE_FILE=$1
TARGET_FILE=$2
OWNER=$3
GROUP=$4
PERMS=$5
if [ ! -r "$SOURCE_FILE" ]; then
echo "[$SOURCE_FILE] Can not read source file"
return 1
fi
if [ -e "$TARGET_FILE" ]; then
nsh_cmp "$SOURCE_FILE" "$TARGET_FILE"
if [ $? -eq 0 ]; then
echo "[$TARGET_FILE] File did not change -- No update needed"
return 0
fi
if [ ! -w "$TARGET_FILE" ]; then
echo "[$TARGET_FILE] Can not update binary -- No write permissions"
return 1
fi
fi
if [ -e "$TARGET_FILE" ]; then
unlink "$TARGET_FILE"
fi
cp -f "$SOURCE_FILE" "$TARGET_FILE"
if [ ! -z "$OWNER" ]; then
chown $OWNER:$GROUP "$TARGET_FILE"
fi
if [ ! -z "$PERMS" ]; then
chmod "$PERMS" "$TARGET_FILE"
fi
echo "[$TARGET_FILE] installed"
return 2
}
install_file_noupdate()
{
SOURCE_FILE=$1
TARGET_FILE=$2
if [ -e "$TARGET_FILE" ]; then
echo "[$TARGET_FILE] Skipping file -- Not overwriting"
return 0
fi
install_file "$1" "$2" "$3" "$4" "$5"
}
patch_install_dir()
{
if [ ! -e "$1" ]; then
echo "FILE DOES NOT EXIST: [$1]"
return 0;
fi
if [ "$DONT_TOUCH_THIS_NASHCOM_PATH" = "$DOMINO_START_SCRIPT_DIR" ]; then
return 0;
fi
sed -i "s~${DONT_TOUCH_THIS_NASHCOM_PATH}~${DOMINO_START_SCRIPT_DIR}~g" "$1"
}
patch_user_name()
{
if [ ! -e "$1" ]; then
echo "FILE DOES NOT EXIST: [$1]"
return 0;
fi
if [ "$DONT_TOUCH_THIS_STANDARD_USER" = "$DOMINO_USER" ]; then
return 0;
fi
sed -i "s~${DONT_TOUCH_THIS_STANDARD_USER}~${DOMINO_USER}~g" "$1"
}
copy_one_touch_templates()
{
local TARGET_DIR=$DOMINO_START_SCRIPT_DIR/OneTouchSetup
local SOURCE_DIR=$SCRIPT_DIR/OneTouchSetup
mkdir -p -m 755 $TARGET_DIR
cp -f $SOURCE_DIR/* $TARGET_DIR
chown -R "$DOMINO_USER":"$DOMINO_GROUP" $TARGET_DIR
chmod -R 644 $TARGET_DIR/*
return 0
}
detect_container_env()
{
if [ "$LARCH" = "ibmpow" ]; then
return 0
fi
# check if running inside a container
if [ -e "/.dockerenv" ]; then
CONTAINER_ENV=docker
return 1
fi
# Podman has it's own name
if [ -e "/run/.containerenv" ]; then
CONTAINER_ENV=podman
return 1
fi
# K8s environment
if [ -n "$KUBERNETES_SERVICE_HOST" ]; then
CONTAINER_ENV=k8s
return 1
fi
# Some container environments define e.g. 'oci'
if [ -n "$container" ]; then
CONTAINER_ENV=$container
return 1
fi
FIRST_PROCESS=$(ps -p 1 -o cmd=)
case "$FIRST_PROCESS" in
*entrypoint.sh)
CONTAINER_ENV=other
return 1
;;
/bin/bash*)
return 1
;;
esac
return 0
}
# rc script files install
header "Installing StartScript & Config"
if [ ! -e "$DOMINO_START_SCRIPT_DIR" ]; then
mkdir -p -m 755 "$DOMINO_START_SCRIPT_DIR"
# Depending on the umask the directory might have still the wrong permissions
chmod 755 /opt/nashcom
fi
DebugText "DOMINO_USER: [$DOMINO_USER]"
DOMINO_USER_GROUPID=$(id -g "$DOMINO_USER" 2>/dev/null)
DebugText "DOMINO_USER_GROUPID: [$DOMINO_USER_GROUPID]"
DebugText "START_SCRIPT_DIR: [$START_SCRIPT_DIR]"
if [ -z "$DOMINO_USER_GROUPID" ]; then
echo "Terminating installation - User Linux '$DOMINO_USER' does not exist"
exit 1
fi
if [ ! -e "$DOMINO_DATA_PATH" ]; then
echo "Terminating installation - Domino data directory directory '$DOMINO_DATA_PATH' does not exist"
exit 1
fi
install_file "$START_SCRIPT_DIR/rc_domino" "$DOMINO_SCRIPT_BIN" $ROOT_USER $ROOT_GROUP 755
install_file "$START_SCRIPT_DIR/rc_domino_script" "$DOMINO_START_SCRIPT_DIR/rc_domino_script" $ROOT_USER $ROOT_GROUP 755
install_file "$START_SCRIPT_DIR/rc_domino_readme.txt" "$DOMINO_START_SCRIPT_DIR/rc_domino_readme.txt" "$DOMINO_USER" "$DOMINO_GROUP" 644
install_file "$START_SCRIPT_DIR/nshinfo.sh" "$DOMINO_START_SCRIPT_DIR/nshinfo.sh" $ROOT_USER $ROOT_GROUP 755
install_file "$START_SCRIPT_DIR/DominoOneTouchSetup.sh" "$DOMINO_START_SCRIPT_DIR/DominoOneTouchSetup.sh" $ROOT_USER $ROOT_GROUP 755
install_file "$START_SCRIPT_DIR/nshcfg.sh" "$DOMINO_START_SCRIPT_DIR/nshcfg.sh" $ROOT_USER $ROOT_GROUP 755
install_file "$START_SCRIPT_DIR/domino.cfg" "$DOMINO_START_SCRIPT_DIR/domino-example.cfg" $ROOT_USER $ROOT_GROUP 755
START_SCRIPT_CONFIG_VER=$DOMINO_START_SCRIPT_DIR/rc_domino_config_$DOMINO_SCRIPT_VERSION.txt
START_SCRIPT_CONFIG_LATEST=$DOMINO_START_SCRIPT_DIR/rc_domino_config_latest.txt
install_file $DOMINO_INSTALL_CONFIG_FILE $START_SCRIPT_CONFIG_VER "$DOMINO_USER" "$DOMINO_GROUP" 644
if [ -e "$START_SCRIPT_CONFIG_LATEST" ]; then
rm -f "$START_SCRIPT_CONFIG_LATEST"
fi
create_link $START_SCRIPT_CONFIG_VER $START_SCRIPT_CONFIG_LATEST
# create /etc/sysconfig if not present
if [ ! -e "/etc/sysconfig" ]; then
mkdir -m 755 /etc/sysconfig
fi
if [ "$PARAM1" = "upd" ]; then
install_file "$DOMINO_INSTALL_CONFIG_FILE" "$DOMINO_INSTALL_CONFIG_TARGET" "$DOMINO_USER" "$DOMINO_GROUP" 644
install_file "$START_SCRIPT_DIR/systemdbs.ind" "$DOMINO_DATA_PATH/systemdbs.ind" "$DOMINO_USER" "$DOMINO_GROUP" 644
install_file "$START_SCRIPT_DIR/domino.cfg" "/etc/sysconfig/domino.cfg" "$DOMINO_USER" "$DOMINO_GROUP" 644
else
install_file_noupdate "$DOMINO_INSTALL_CONFIG_FILE" "$DOMINO_INSTALL_CONFIG_TARGET" "$DOMINO_USER" "$DOMINO_GROUP" 644
install_file_noupdate "$START_SCRIPT_DIR/systemdbs.ind" "$DOMINO_DATA_PATH/systemdbs.ind" "$DOMINO_USER" "$DOMINO_GROUP" 644
install_file_noupdate "$START_SCRIPT_DIR/domino.cfg" "/etc/sysconfig/domino.cfg" "$DOMINO_USER" "$DOMINO_GROUP" 644
fi
copy_one_touch_templates
# if old start script location exists, replace it with link to new start script location
OLD_RC_DOMINO_SCRIPT_LOCATION=/opt/ibm/domino/rc_domino_script
if [ -e "$OLD_RC_DOMINO_SCRIPT_LOCATION" ]; then
rm -f "$OLD_RC_DOMINO_SCRIPT_LOCATION"
create_link $DOMINO_START_SCRIPT_DIR/rc_domino_script $OLD_RC_DOMINO_SCRIPT_LOCATION
echo link for legacy start script location created [$OLD_RC_DOMINO_SCRIPT_LOCATION]
fi
# In a container environment install entrypoint.sh
detect_container_env
if [ -n "$CONTAINER_ENV" ] || [ "$CONTAINER_USE_SYSTEMD" = "yes" ]; then
# when running in a container environment, don't use systemd/init.d
if [ "$CONTAINER_ENV" = "other" ]; then
header "Container environment detected!"
else
header "${CONTAINER_ENV} container environment detected!"
fi
if [ -e "$START_SCRIPT_DIR/$DOMINO_DOCKER_SCRIPT" ]; then
if [ "$PARAM1" = "upd" ]; then
install_file "$START_SCRIPT_DIR/$DOMINO_DOCKER_SCRIPT" "/$DOMINO_DOCKER_SCRIPT" $ROOT_USER $ROOT_GROUP 755
else
install_file_noupdate "$START_SCRIPT_DIR/$DOMINO_DOCKER_SCRIPT" "/$DOMINO_DOCKER_SCRIPT" $ROOT_USER $ROOT_GROUP 755
fi
fi
fi
# Configure systemd if available
if [ ${LARCH} = "linux" ]; then
if [ -e /etc/systemd/system ]; then
if [ "$PARAM1" = "upd" ]; then
install_file $START_SCRIPT_DIR/domino.service /etc/systemd/system/$DOMINO_SYSTEMD_NAME $ROOT_USER $ROOT_GROUP 644
else
install_file_noupdate $START_SCRIPT_DIR/domino.service /etc/systemd/system/$DOMINO_SYSTEMD_NAME $ROOT_USER $ROOT_GROUP 644
fi
fi
patch_install_dir "/etc/systemd/system/$DOMINO_SYSTEMD_NAME"
patch_user_name "/etc/systemd/system/$DOMINO_SYSTEMD_NAME"
# add domino service (systemd/init.d)
if [ -z "$(ps --no-headers -o comm 1 | grep systemd)" ]; then
echo "Info: System is not running systemd"
else
systemctl daemon-reload
$DOMINO_SCRIPT_BIN service add
fi
fi
if [ -e "$DOMINO_SCRIPT_BIN" ]; then
patch_install_dir "$DOMINO_SCRIPT_BIN"
patch_user_name "$DOMINO_SCRIPT_BIN"
fi
header Done
exit 0