forked from nashcom/domino-startscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_domino_container
executable file
·234 lines (179 loc) · 6.16 KB
/
install_domino_container
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
#!/bin/bash
###########################################################################
# Install Script - Domino Container Script #
# Version 1.0 15.01.2021 #
# #
# (C) Copyright Daniel Nashed/NashCom 2021 #
# Feedback domino_unix@nashcom.de #
# #
# 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_REAL=`realpath $0`
SCRIPT_DIR=`dirname $SCRIPT_REAL`
CONTAINER_SYSTEMD_NAME=domino_container.service
CONTAINER_INSTALL_CONFIG_FILE=domino_container
CONTAINER_INSTALL_CONFIG_FILEPATH=/etc/sysconfig/$CONTAINER_INSTALL_CONFIG_FILE
# 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
ROOT_USER=root
ROOT_GROUP=root
#DOMINO_DEBUG_MODE="yes"
START_SCRIPT_DIR=`dirname $0`
if [ "$START_SCRIPT_DIR" = "/" ]; then
START_SCRIPT_DIR=""
fi
if [ ! $EUID = "0" ]; then
echo "Terminating installation - Please run as root user!"
exit 1
fi
echo "CONTAINER_INSTALL_CONFIG_FILEPATH: [$CONTAINER_INSTALL_CONFIG_FILEPATH]"
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
}
check_file_busy()
{
if [ ! -e "$1" ]; then
return 0
fi
local TARGET_REAL_BIN=`readlink -f $1`
local FOUND_TARGETS=`lsof "$TARGET_REAL_BIN" 2>/dev/null | grep "$TARGET_REAL_BIN"`
if [ -n "$FOUND_TARGETS" ]; then
return 1
else
return 0
fi
}
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
check_file_busy "$TARGET_FILE"
if [ $? -eq 1 ]; then
echo "[$TARGET_FILE] Error - Can not update file -- Binary in use"
return 1
fi
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"
}
header "Installing Domino Container Script & Config"
if [ ! -e "$DOMINO_START_SCRIPT_DIR" ]; then
mkdir -p -m 755 "$DOMINO_START_SCRIPT_DIR"
fi
DebugText "START_SCRIPT_DIR: [$START_SCRIPT_DIR]"
# create /etc/sysconfig if not present
if [ ! -e "/etc/sysconfig" ]; then
mkdir -m 755 /etc/sysconfig
fi
install_file $START_SCRIPT_DIR/domino_container $DOMINO_START_SCRIPT_DIR/domino_container $ROOT_USER $ROOT_GROUP 755
install_file $START_SCRIPT_DIR/software.txt $DOMINO_START_SCRIPT_DIR/software.txt $ROOT_USER $ROOT_GROUP 755
install_file "$START_SCRIPT_DIR/extra/nshinfo.sh" "$DOMINO_START_SCRIPT_DIR/nshinfo.sh" $ROOT_USER $ROOT_GROUP 755
if [ ! -e /usr/bin/domino_container ]; then
ln -s $DOMINO_START_SCRIPT_DIR/domino_container /usr/bin/domino_container
fi
cp -r $START_SCRIPT_DIR/build_image $DOMINO_START_SCRIPT_DIR
find $DOMINO_START_SCRIPT_DIR -name "*.sh" -exec chmod 755 {} \;
if [ "$PARAM1" = "upd" ]; then
install_file $START_SCRIPT_DIR/sysconfig/domino_container "$CONTAINER_INSTALL_CONFIG_FILEPATH" "$ROOT_USER" "$ROOT_GROUP" 644
install_file $START_SCRIPT_DIR/sysconfig/env_container_domino11 "/etc/sysconfig/env_container_domino11" "$ROOT_USER" "$ROOT_GROUP" 644
install_file $START_SCRIPT_DIR/sysconfig/env_container_domino12 "/etc/sysconfig/env_container_domino12" "$ROOT_USER" "$ROOT_GROUP" 644
else
install_file_noupdate $START_SCRIPT_DIR/sysconfig/domino_container "$CONTAINER_INSTALL_CONFIG_FILEPATH" "$ROOT_USER" "$ROOT_GROUP" 644
install_file_noupdate $START_SCRIPT_DIR/sysconfig/env_container_domino11 "/etc/sysconfig/env_container_domino11" "$ROOT_USER" "$ROOT_GROUP" 644
install_file_noupdate $START_SCRIPT_DIR/sysconfig/env_container_domino12 "/etc/sysconfig/env_container_domino12" "$ROOT_USER" "$ROOT_GROUP" 644
fi
if [ -x /usr/bin/podman ]; then
install_file_noupdate $START_SCRIPT_DIR/domino_container.service /etc/systemd/system/$CONTAINER_SYSTEMD_NAME $ROOT_USER $ROOT_GROUP 644
fi
if [ $? -eq 2 ]; then
systemctl daemon-reload
fi
header Done
exit 0