commit d0bb940e346cd649cbc8a3fcdb38bf2c95d3ba97 Author: Thijn Date: Mon May 1 22:38:13 2017 +0200 Initial commit diff --git a/04rel64/Dockerfile b/04rel64/Dockerfile new file mode 100644 index 0000000..49a15fa --- /dev/null +++ b/04rel64/Dockerfile @@ -0,0 +1,38 @@ +FROM debian:jessie + +MAINTAINER Thijn + +# Install packages +RUN apt-get update && apt-get install -y \ + wget \ + unzip \ + p7zip + +# Download and extract server files +# Choose a more general directory name which does not contain any version +RUN cd / \ + && wget http://v04.maxorator.com/server/VCMP04_server_v22_linux64.zip \ + && unzip VCMP04_server_v22_linux64.zip \ + && rm -f VCMP04_server_v22_linux64.zip \ + && mkdir /vcmp \ + && mv /mpsvrrel64 /vcmp/ \ + && cd /vcmp \ + && mkdir plugins \ + && cd plugins \ + && wget http://v04.maxorator.com/allplugins_04rel004_patch7.7z + && p7zip -d allplugins_04rel004_patch7.7z \ + && chmod 700 * \ + && cd ../ \ + && chmod 700 mpsvrrel64 + +COPY vcmp.sh /usr/local/bin/vcmp +COPY docker-entrypoint.sh /entrypoint.sh + +RUN chmod +x /usr/local/bin/vcmp \ + && chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] + +CMD ["vcmp", "start"] + +EXPOSE 8192/udp diff --git a/04rel64/docker-entrypoint.sh b/04rel64/docker-entrypoint.sh new file mode 100644 index 0000000..507cb2a --- /dev/null +++ b/04rel64/docker-entrypoint.sh @@ -0,0 +1,40 @@ +#!/bin/bash +set -e + +if [ "$1" = 'vcmp' ]; then + # 1: Get environment variables -- printenv + # 2: Filter all which start with SAMP_* -- grep '^VCMP_*' + VcmpVars=`env | grep '^VCMP_*'` + + # Hand over environment variables as arguments for easier handling + # As values of environment variables may contain whitespaces the IFS needs to be overwritten + OLDIFS=$IFS + IFS=$'\n' + OLDARGS=$* + set ${VcmpVars:=""} + + # 3: Loop through each of the variables + for config in $*; do + # 4: Split environment variable up in key-value by specifying the '='-char as separator + key=`echo $config | cut -d\= -f1` + value=`echo $config | cut -d\= -f2` + + # 5: Extract the part after "SAMP_" as key + key=${key:5} + + # 6: Transform the key to lowercase + key=`echo $key | tr '[:upper:]' '[:lower:]'` + + # 7: Check if there's already a line with the respective key in the server.cfg + # 7.1 - True: Replace the current value with the new value + # 7.2 - False: Add new line to server.cfg with the key-value pair + grep -q "$key" vcmp/server.cfg && \ + sed -i "s/$key .*/$key $value/" vcmp/server.cfg 2>/dev/null || \ + sed -i "$ a\\$key $value" vcmp/server.cfg 2>/dev/null + done + + IFS=$OLDIFS + set $OLDARGS +fi + +exec "$@" \ No newline at end of file diff --git a/04rel64/vcmp.sh b/04rel64/vcmp.sh new file mode 100644 index 0000000..07091d2 --- /dev/null +++ b/04rel64/vcmp.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -e + +cd /vcmp +case "$1" in + 'start') + exec nohup ./mpsvrrel64 + ;; + 'stop') + exec killall mpsvrrel64 + ;; + 'restart') + killall mpsvrrel64 + sleep 1 + exec nohup ./mpsvrrel64 + ;; + *) + echo "Usage: $0 start/stop/restart" + exit 1 +esac \ No newline at end of file