forked from jacobalberty/cups-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-entrypoint.sh
executable file
·54 lines (49 loc) · 1.44 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
#!/bin/bash
set -e
# usage: replace conf var new_val
replace () {
var=$2
new_val=$3
sed -i "s/^$var *= *.*/$var = $new_val/; s/^$var [^=]*$/$var $new_val/" "$1"
}
# usage: file_env VAR [DEFAULT]
# ie: file_env 'XYZ_DB_PASSWORD' 'example'
# (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
# "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
file_env() {
local var="$1"
local fileVar="${var}_FILE"
local def="${2:-}"
if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
exit 1
fi
local val="$def"
if [ "${!var:-}" ]; then
val="${!var}"
elif [ "${!fileVar:-}" ]; then
val="$(< "${!fileVar}")"
fi
export "$var"="$val"
unset "$fileVar"
}
if [[ ! -e "${VOLUME}/etc/" ]]; then
cp -R "${PREFIX}/skel/cups/etc" "${VOLUME}/"
if [[ "$LOGSTDERR" != "false" ]]; then
replace "${VOLUME}/etc/cups-files.conf" AccessLog stderr
replace "${VOLUME}/etc/cups-files.conf" ErrorLog stderr
replace "${VOLUME}/etc/cups-files.conf" PageLog stderr
fi
fi
if [ -d "/usr/local/docker/init.d" ]; then
run-parts /usr/local/docker/init.d
fi
if [ -d ${VOLUME}/init.d ]; then
run-parts ${VOLUME}/init.d
fi
# Ensure logdir exists and is owned by the correct group
if [[ ! -e "${VOLUME}/log" ]]; then
mkdir -p "${VOLUME}/log"
chgrp lp "${VOLUME}/log"
fi
$@