forked from jimeh/docker-znc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-entrypoint.sh
executable file
·58 lines (46 loc) · 1.78 KB
/
docker-entrypoint.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
#! /bin/bash
# Options.
DATADIR="/znc-data"
# Build modules from source.
if [ -d "${DATADIR}/modules" ]; then
# Store current directory.
cwd="$(pwd)"
# Find module sources.
modules=$(find "${DATADIR}/modules" -name "*.cpp")
# Build modules.
for module in $modules; do
echo "Building module $module..."
cd "$(dirname "$module")"
znc-buildmod "$module"
done
# Go back to original directory.
cd "$cwd"
fi
# Generate self-signed certificate if one doesn't exist
if [ ! -f "${DATADIR}/ssl/znc.pem" ]; then
# Store current directory.
cwd="$(pwd)"
# Create SSL directory if one doesn't exist already
mkdir -p "${DATADIR}/ssl"
# Create private key, generate 5 year self-signed certificate, and concat into a pem in one shot
# To use a signed cert, create a PEM with your key, intermediate and cert inside and put it at ${DATADIR}/ssl/znc.pem
openssl req -subj '/CN=znc/O=ZNC/C=GB' -new -newkey rsa:2048 -sha256 -days 1825 -nodes -x509 -keyout ${DATADIR}/ssl/znc.key -out ${DATADIR}/ssl/znc.crt && \
cat ${DATADIR}/ssl/znc.key ${DATADIR}/ssl/znc.crt > ${DATADIR}/ssl/znc.pem && \
echo "Created self-signed certificate ${DATADIR}/ssl/znc.pem..."
# Go back to original directory.
cd "$cwd"
fi
# Create default config if it doesn't exist
if [ ! -f "${DATADIR}/configs/znc.conf" ]; then
echo "Creating a default configuration..."
mkdir -p "${DATADIR}/configs"
cp /znc.conf.default "${DATADIR}/configs/znc.conf"
sed -i 's#@DATADIR@#'"${DATADIR}"'#g' "${DATADIR}/configs/znc.conf"
fi
# Make sure $DATADIR is owned by znc user. This effects ownership of the
# mounted directory on the host machine too.
echo "Setting necessary permissions..."
chown -R znc:znc "$DATADIR"
# Start ZNC.
echo "Starting ZNC..."
exec sudo -u znc znc --foreground --datadir="$DATADIR" $@