aboutsummarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorDian Fay2016-09-22 21:28:37 -0400
committerDian Fay2016-09-24 02:09:22 -0400
commitdc6eaebd34578d5abcf1cf84355fe985f2da8bfb (patch)
tree2f9d69ac65f2d0d7dbc492f4199797d36c30357f
downloadaur-dc6eaebd34578d5abcf1cf84355fe985f2da8bfb.tar.gz
initial commit
-rw-r--r--.SRCINFO24
-rw-r--r--.gitignore3
-rw-r--r--PKGBUILD38
-rw-r--r--README.md54
-rw-r--r--default.properties19
-rwxr-xr-xdom4153
-rwxr-xr-xdom4-server31
-rw-r--r--dom4-server.install50
-rw-r--r--dom4-server.service11
-rw-r--r--dom4-sysusers.conf1
-rw-r--r--dom4-tmpfile.conf1
11 files changed, 385 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 000000000000..e3d899cf04ec
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,24 @@
+pkgbase = dom4-server
+ pkgdesc = Configure and run Dominions 4 as a headless server
+ pkgver = 1.0.0
+ pkgrel = 1
+ install = dom4-server.install
+ arch = x86_64
+ license = MIT
+ source = dom4-server
+ source = dom4-server.install
+ source = dom4-server.service
+ source = dom4-sysusers.conf
+ source = dom4-tmpfile.conf
+ source = dom4
+ source = default.properties
+ md5sums = d8e3011dfa108d3f1574c57aefcecb32
+ md5sums = 5156ef9db21ecfc104bd03e74ca5ec15
+ md5sums = 7e51badb10054709bbec60bfcbf424ee
+ md5sums = e9772a237cc540558e74235b98df8a7f
+ md5sums = 338b8462868ecf6cc56c4a520cea6bac
+ md5sums = a6f06f3a3c5d4c12717b37db2c6f4dc7
+ md5sums = 22bdb16a296d12c51988c43c3218201b
+
+pkgname = dom4-server
+
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 000000000000..a785f50249ba
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+src
+pkg
+**/*.tar.xz
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 000000000000..d1477361f466
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,38 @@
+# Dominions 4 Server Configuration
+# Maintainer: Dian Fay <dian.m.fay@gmail.com>
+pkgname=dom4-server
+pkgver=1.0.0
+pkgrel=1
+pkgdesc="Configure and run Dominions 4 as a headless server"
+arch=('x86_64')
+url=""
+license=('MIT')
+install=$pkgname.install
+source=(
+ dom4-server
+ dom4-server.install
+ dom4-server.service
+ dom4-sysusers.conf
+ dom4-tmpfile.conf
+ dom4
+ default.properties
+)
+
+package() {
+ install -Dm744 "$srcdir/dom4-server" "$pkgdir/usr/bin/dom4-server"
+ install -Dm644 "$srcdir/dom4-server.service" "$pkgdir/usr/lib/systemd/system/dom4-server.service"
+
+ install -Dm755 "$srcdir/dom4" "$pkgdir/usr/bin/dom4"
+
+ install -Dm644 "$srcdir/default.properties" "$pkgdir/usr/share/dom4/config/default.properties"
+
+ install -Dm644 "$srcdir/dom4-sysusers.conf" "$pkgdir/usr/lib/sysusers.d/dom4.conf"
+ install -Dm644 "$srcdir/dom4-tmpfile.conf" "$pkgdir/usr/lib/tmpfiles.d/dom4.conf"
+}
+md5sums=('d8e3011dfa108d3f1574c57aefcecb32'
+ '5156ef9db21ecfc104bd03e74ca5ec15'
+ '7e51badb10054709bbec60bfcbf424ee'
+ 'e9772a237cc540558e74235b98df8a7f'
+ '338b8462868ecf6cc56c4a520cea6bac'
+ 'a6f06f3a3c5d4c12717b37db2c6f4dc7'
+ '22bdb16a296d12c51988c43c3218201b')
diff --git a/README.md b/README.md
new file mode 100644
index 000000000000..1c60dd3880e1
--- /dev/null
+++ b/README.md
@@ -0,0 +1,54 @@
+# Dominions 4 Headless Server
+
+## Installing
+
+Install this package (`dom4-server`) using your AUR package manager of choice, or `makepkg`.
+
+Dominions 4 must be installed to /opt/Dominions4. If you already have it installed elsewhere and don't want to mess around with permissions, it's easiest to just copy it.
+
+If you installed it from the Steam GUI:
+
+```bash
+sudo cp -R ~/.local/share/Steam/steamapps/common/Dominions4 /opt
+```
+
+If you installed it via SteamCMD (see below for directions if you're starting from scratch with no GUI):
+
+```bash
+sudo cp -R ~/Steam/steamapps/common/Dominions4 /opt
+```
+
+If you can't find it at either of those locations, try `locate dom4.sh` (if you *just* installed Dominions 4, `sudo updatedb` first). This should output one line with the full path and filename of `dom4.sh`. `sudo cp -R` the path, excluding the filename.
+
+### License Key
+
+Your install directory must have a `dom4key` file present containing your Dominions 4 license key. If the file does not already exist, you can create it using the license information from Steam.
+
+### Network
+
+You can use whatever port number you like between 1024 and 65535. Make sure you don't have anything else running on that port.
+
+If your computer is behind a router you will need to make sure the port is forwarded. It is also helpful to configure a static IP address so the routing stays consistent. Consult your router documentation for instructions.
+
+## Game Configuration
+
+Your game configuration is stored in key=value format in a properties file. Copy `default.properties` to a safe location and edit as needed. `mapfile` should reference the filename of a map in *your* `~/dominions4/maps` directory. Once ready:
+
+1. `dom4 config mygame.properties` loads your config into the server and sets the current game name.
+1. `systemctl start dom4-server` starts the server in pretender upload mode.
+1. If `uploadmaxp` or `uploadtime` are set in your configuration, you're done: the game will start automatically when the appropriate limit is reached. If not, wait for everyone to upload their pretenders and then bring the server down with `systemctl stop dom4-server`.
+1. `dom4 ready` sets the game's start flag.
+1. Restart the server using `systemctl start dom4-server` again to begin the game.
+
+You may also want to `systemctl enable dom4-server` in order to start the server automatically after reboots.
+
+Note that only one game may be served at a time. If you run `dom4 config` with a config file when a game has already been set up, it will ask if you want to overwrite the existing game.
+
+## SteamCMD
+
+Here's how to download and install Dominions 4 from Steam without needing to let X or a monitor anywhere near your computer:
+
+1. Install `steamcmd` using your AUR package manager of choice.
+1. Run `steamcmd`.
+1. `login your_user_name`. Supply the password if asked.
+1. `app_update 259060`. Once the download finishes, you're all set.
diff --git a/default.properties b/default.properties
new file mode 100644
index 000000000000..67e16f306326
--- /dev/null
+++ b/default.properties
@@ -0,0 +1,19 @@
+###### SERVER INFO ######
+# set the map file. any image file must have the same name but a different extension.
+mapfile my_pretty_world.map
+# allow host to set dropped-out players to computer control
+masterpass supersecure
+# will default to localhost
+ipadr 127.0.0.1
+# must be between 1024 and 65535
+port 6666
+# time between turn rollover
+hours 26
+
+###### GAME SETTINGS ######
+era 1
+renaming
+storyevents
+hofsize 15
+requiredap 13
+thrones 2 8 1
diff --git a/dom4 b/dom4
new file mode 100755
index 000000000000..40647d8108c3
--- /dev/null
+++ b/dom4
@@ -0,0 +1,153 @@
+#!/bin/bash
+
+function config {
+ if [[ ! -s $1 ]]; then
+ echo "Specify a valid properties file."
+ exit 1
+ fi
+
+ if [[ -s /usr/share/dom4/current ]]; then
+ game=$(</usr/share/dom4/current)
+ new=$(basename $1 .properties)
+ read -r -n 2 -p "A game named $game already exists. Set up to host $new instead? [Y/n] " ovr
+ if [[ $ovr != Y ]]; then
+ exit 0
+ fi
+ fi
+
+ echo "Copying properties file"
+
+ cp $1 /usr/share/dom4/config
+
+ mapfile=$(grep -oP "mapfile\s+\K.+" $1)
+ mapname=$(basename $mapfile .map)
+
+ echo "Copying $mapname map files"
+
+ mkdir -p /usr/share/dom4/maps
+
+ USER_HOME=$(getent passwd $SUDO_USER | cut -d: -f6)
+ cp "$USER_HOME/dominions4/maps/$mapname."* /usr/share/dom4/maps
+
+ # Set name as current hosted game
+ echo $(basename $1 .properties) > /usr/share/dom4/current
+
+ cat <<EOF
+
+Done. Start the service to let players upload their pretenders.
+
+ sudo systemctl start dom4-server.service
+
+Once all pretenders have been uploaded, stop the service and set the game to ready.
+
+ sudo dom4 ready
+EOF
+}
+
+function ready {
+ if [[ ! -s /usr/share/dom4/current ]]; then
+ echo "No current game found. Use dom4 config to load game configuration."
+ exit 1
+ fi
+
+ game=$(</usr/share/dom4/current)
+ players=$(ls -1 /usr/share/dom4/savedgames/$game | wc -l)
+
+ if grep -qE "uploadtime|uploadmaxp" /usr/share/dom4/config/$game.properties ; then
+ echo "Upload flag already set. Start the service with systemctl."
+ exit 1
+ fi
+
+ echo "Setting start flag for $game ($players players)"
+
+ echo "uploadmaxp $players" >> "/usr/share/dom4/config/$game.properties"
+
+ cat <<EOF
+
+Flag set. Start the dom4-server service to begin the game.
+
+ sudo systemctl start dom4-server.service
+
+You may wish to enable it as well to ensure it restarts on boot.
+EOF
+}
+
+function delete {
+ if [[ -z $1 ]]; then
+ echo "Specify a game name to delete."
+ exit 0
+ fi
+
+ if [[ $1 = "default" ]]; then
+ echo "Not deleting the default config."
+ exit 0
+ fi
+
+ game=$(</usr/share/dom4/current)
+
+ if [[ $game = $1 ]]; then
+ read -r -n 2 -p "$game is currently being hosted. Really delete? [Y/n] " ovr
+ if [[ $ovr != Y ]]; then
+ exit 0
+ fi
+
+ rm /usr/share/dom4/current
+ fi
+
+ # leave the mapfile in case something else is using it
+ rm /usr/share/dom4/config/$1.properties
+ rm -rf /usr/share/dom4/savedgames/$1
+}
+
+if [[ $EUID -ne 0 && ! -z $1 ]]; then
+ echo "This script must be run as root or via sudo."
+ exit 1
+fi
+
+case $1 in
+ config)
+ config "${@:2}"
+ ;;
+
+ ready)
+ ready "${@:2}"
+ ;;
+
+ delete)
+ delete "${@:2}"
+ ;;
+
+ "")
+ cat <<EOF
+Get an example template to modify in your editor of choice:
+
+ cp /usr/share/dom4/config/default.properties mygame.properties
+
+Load a game config file:
+
+ sudo dom4 config path/to/mygame.properties
+
+Set start flag for current game after all pretenders have been uploaded, prior to running service:
+
+ sudo dom4 ready
+
+Delete a game:
+
+ sudo dom4 delete mygame
+
+Start the service:
+
+ sudo systemctl start dom4-server.service
+
+Stop the service:
+
+ sudo systemctl stop dom4-server.service
+
+Troubleshooting:
+
+If the service isn't running, figure out what's going wrong:
+
+ systemctl status dom4-server.service
+EOF
+ ;;
+esac
diff --git a/dom4-server b/dom4-server
new file mode 100755
index 000000000000..e8537794cc11
--- /dev/null
+++ b/dom4-server
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+game=`cat /usr/share/dom4/current`
+
+if [[ -z "$game" ]]; then
+ echo "No game specified. Use 'dom4 config' to load a game configuration."
+ exit 1
+fi
+
+if [[ ! -s /usr/share/dom4/config/$game.properties ]]; then
+ echo "Tried to load $game but configuration file is missing."
+ exit 1
+fi
+
+# Load config
+
+config="--tcpserver --textonly --noclientstart"
+
+while read -r line; do
+ if [[ -n $line && ! $line = \#* ]]; then
+ echo "Setting $line"
+
+ config="$config --$line"
+ fi
+done < /usr/share/dom4/config/$game.properties
+
+# Start server
+
+export DOM4_CONF=/usr/share/dom4
+
+exec sh /opt/Dominions4/dom4.sh $config $game
diff --git a/dom4-server.install b/dom4-server.install
new file mode 100644
index 000000000000..2fa9e86816fe
--- /dev/null
+++ b/dom4-server.install
@@ -0,0 +1,50 @@
+post_install() {
+ post_upgrade
+
+ systemctl daemon-reload
+}
+
+post_upgrade() {
+ if hash systemd-sysusers &> /dev/null; then
+ systemd-sysusers dom4.conf
+ fi
+
+ if hash systemd-tmpfiles &> /dev/null; then
+ systemd-tmpfiles --create dom4.conf
+ fi
+
+ cat <<EOF
+Post-install tasks:
+
+Ensure Dominions 4 is installed to /opt/Dominions4. If you installed it from the Steam GUI with the default library path, use:
+
+ sudo cp -R ~/.local/share/Steam/steamapps/common/Dominions4 /opt
+
+If you installed it via SteamCMD (see README.md in the Git repository for instructions on doing that if you're starting from scratch):
+
+ sudo cp -R ~/Steam/steamapps/common/Dominions4 /opt
+
+If you can't find it at either of those locations, try 'locate dom4.sh' (if you *just* installed Dominions 4, 'sudo updatedb' first). This should output one line with the full path and filename of 'dom4.sh'. 'sudo cp -R' the path, excluding the filename.
+
+Your install directory must have a 'dom4key' file present containing your Dominions 4 license key. If the file does not already exist, you can create it using the license information from Steam.
+
+To begin setting up hosting, run 'dom4'.
+EOF
+}
+
+post_remove() {
+ if systemctl is-active dom4-server &> /dev/null; then
+ systemctl stop dom4-server
+ fi
+
+ systemctl daemon-reload
+ systemctl reset-failed
+
+ userdel dom4 > /dev/null
+
+ if [[ -s /usr/share/dom4/current ]]; then
+ rm /usr/share/dom4/current
+ fi
+
+ rm -rf /run/dom4
+}
diff --git a/dom4-server.service b/dom4-server.service
new file mode 100644
index 000000000000..45ee40673df8
--- /dev/null
+++ b/dom4-server.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Dominions 4 Headless Server
+After=network.target
+
+[Service]
+ExecStart=/usr/bin/dom4-server
+Type=simple
+RemainAfterExit=yes
+
+[Install]
+WantedBy=multi-user.target
diff --git a/dom4-sysusers.conf b/dom4-sysusers.conf
new file mode 100644
index 000000000000..2997550ca21a
--- /dev/null
+++ b/dom4-sysusers.conf
@@ -0,0 +1 @@
+u dom4 - "Dominions 4 headless server" /usr/share/dom4
diff --git a/dom4-tmpfile.conf b/dom4-tmpfile.conf
new file mode 100644
index 000000000000..c8584b927897
--- /dev/null
+++ b/dom4-tmpfile.conf
@@ -0,0 +1 @@
+d /run/dom4 0755 dom4 dom4 -