Skip to content

Commit e7c37d0

Browse files
committed
chore: move xml-edit to a script
1 parent 6e1857a commit e7c37d0

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,15 @@ ENV USER=icecast
5454

5555
RUN adduser --disabled-password --gecos '' --no-create-home $USER
5656

57+
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint
58+
COPY xml-edit.sh /usr/local/bin/xml-edit
59+
RUN chmod +x \
60+
/usr/local/bin/docker-entrypoint \
61+
/usr/local/bin/xml-edit
62+
5763
COPY --from=builder /build/output /
5864
RUN chown $USER:$USER /etc/icecast.xml
5965

60-
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint
61-
RUN chmod +x /usr/local/bin/docker-entrypoint
62-
6366
RUN install --directory --owner=$USER \
6467
/var/log/icecast
6568

docker-entrypoint.sh

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
11
#!/bin/sh
22

3-
xml_edit() {
4-
tag="$1"
5-
value="$2"
6-
RESULT=$(sed -e "s|<${tag}>[^<]*</${tag}>|<${tag}>${value}</${tag}>|g" /etc/icecast.xml) &&
7-
echo "$RESULT" > /etc/icecast.xml
3+
edit_icecast_config() {
4+
xml-edit "$@" /etc/icecast.xml
85
}
96

107
if [ -n "$ICECAST_SOURCE_PASSWORD" ]; then
11-
xml_edit source-password "$ICECAST_SOURCE_PASSWORD"
8+
edit_icecast_config source-password "$ICECAST_SOURCE_PASSWORD"
129
fi
1310
if [ -n "$ICECAST_RELAY_PASSWORD" ]; then
14-
xml_edit relay-password "$ICECAST_RELAY_PASSWORD"
11+
edit_icecast_config relay-password "$ICECAST_RELAY_PASSWORD"
1512
fi
1613
if [ -n "$ICECAST_ADMIN_PASSWORD" ]; then
17-
xml_edit admin-password "$ICECAST_ADMIN_PASSWORD"
14+
edit_icecast_config admin-password "$ICECAST_ADMIN_PASSWORD"
1815
fi
1916
if [ -n "$ICECAST_ADMIN_USERNAME" ]; then
20-
xml_edit admin-user "$ICECAST_ADMIN_USERNAME"
17+
edit_icecast_config admin-user "$ICECAST_ADMIN_USERNAME"
2118
fi
2219
if [ -n "$ICECAST_ADMIN_EMAIL" ]; then
23-
xml_edit admin "$ICECAST_ADMIN_EMAIL"
20+
edit_icecast_config admin "$ICECAST_ADMIN_EMAIL"
2421
fi
2522
if [ -n "$ICECAST_LOCATION" ]; then
26-
xml_edit location "$ICECAST_LOCATION"
23+
edit_icecast_config location "$ICECAST_LOCATION"
2724
fi
2825
if [ -n "$ICECAST_HOSTNAME" ]; then
29-
xml_edit hostname "$ICECAST_HOSTNAME"
26+
edit_icecast_config hostname "$ICECAST_HOSTNAME"
3027
fi
3128
if [ -n "$ICECAST_MAX_CLIENTS" ]; then
32-
xml_edit clients "$ICECAST_MAX_CLIENTS"
29+
edit_icecast_config clients "$ICECAST_MAX_CLIENTS"
3330
fi
3431
if [ -n "$ICECAST_MAX_SOURCES" ]; then
35-
xml_edit sources "$ICECAST_MAX_SOURCES"
32+
edit_icecast_config sources "$ICECAST_MAX_SOURCES"
3633
fi
3734

3835
exec "$@"

xml-edit.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh -eu
2+
3+
usage() {
4+
cat >&2 <<- EOF
5+
Usage : $0 <tag> <value> <file>
6+
7+
EOF
8+
}
9+
10+
if test $# -lt 3; then
11+
usage
12+
exit 1
13+
fi
14+
15+
tag="$1"
16+
value="$2"
17+
file="$3"
18+
19+
result=$(sed -e "s|<${tag}>[^<]*</${tag}>|<${tag}>${value}</${tag}>|g" "$file") || exit 1
20+
echo "$result" > "$file"

0 commit comments

Comments
 (0)