This repository was archived by the owner on May 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcometd.sh
More file actions
executable file
·80 lines (67 loc) · 2.09 KB
/
cometd.sh
File metadata and controls
executable file
·80 lines (67 loc) · 2.09 KB
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
#!/bin/sh
COMET_DIR=/opt/cometd
COMET_BIN=cometd
COMET_CFG=cometd.cfg
# Docker Variables
#COMET_LICENSE - Comet license code
#COMET_LICENSE_FORCE - Force the Comet license to be re-added to the config file
#COMET_ARGUMENTS - Additional arguments to pass to the Comet server
#COMET_ADMIN_USER - Admin user #0 username
#COMET_ADMIN_PASS - Admin user #0 password
cd "$COMET_DIR"
# If no config, create it
if [[ ! -f "$COMET_DIR/$COMET_CFG" ]]; then
echo -n 'Creating default Comet config... '
"$COMET_DIR/$COMET_BIN" -ValidateConfigOnly > /dev/null 2>&1
if [[ $? == 0 ]]; then
echo -e '\e[32mDone!\e[0m'
else
echo -e '\e[31mFailed!\e[0m'
exit 1
fi
fi
# Create tempfiles for jq filters
JQTMP=$(mktemp)
# function to add jq filters to the JQTMP file.
jq_filter_add () {
# If the file contains data, prepend a JQ pipe
if [[ -s "$JQTMP" ]]; then
echo "| $@" >> "$JQTMP"
else
echo "$@" >> "$JQTMP"
fi
}
# Check if we have a license set yet and add if not
if [[ $(jq '.License.SerialNumber' "$COMET_DIR/$COMET_CFG") == '""' || -n "$COMET_LICENSE_FORCE" ]]; then
if [[ -z "$COMET_LICENSE" ]]; then
# No license key set and none provided. Exit.
echo -e '\e[31mNo Comet license key provided!\e[0m'
echo -e '\e[31mProvide one using the "COMET_LICENSE" environment variable\e[0m'
exit 1
fi
jq_filter_add ".License.SerialNumber = \"$COMET_LICENSE\""
fi
# Handle environment variables pertaining to the Admin user
if [[ -n "$COMET_ADMIN_USER" ]]; then
jq_filter_add ".AdminUsers[0].Username = \"$COMET_ADMIN_USER\""
fi
if [[ -n "$COMET_ADMIN_PASS" ]]; then
jq_filter_add ".AdminUsers[0].PasswordFormat = 0"
jq_filter_add ".AdminUsers[0].Password = \"$COMET_ADMIN_PASS\""
fi
# Write new config and save it
if [[ -s $JQTMP ]]; then
echo -n 'Updating config... '
CFGTMP=$(mktemp)
jq -f "$JQTMP" "$COMET_DIR/$COMET_CFG" > "$CFGTMP"
if [[ $? != 0 ]]; then
echo -e '\e[31mFailed to update config file! Exiting.\e[0m'
exit 1
fi
mv "$CFGTMP" "$COMET_DIR/$COMET_CFG"
rm -f $CFGTMP
echo -e '\e[32mComet config updated!\e[0m'
fi
# Cleanup temp files
rm -f "$JQTMP"
"$COMET_DIR/$COMET_BIN" $COMET_ARGUMENTS