[19] | 1 | #!/bin/bash
|
---|
| 2 |
|
---|
[258] | 3 | # Copyright 2016 Christian 'Alloc' Illy
|
---|
| 4 | #
|
---|
| 5 | # Licensed under the Apache License, Version 2.0 (the "License");
|
---|
| 6 | # you may not use this file except in compliance with the License.
|
---|
| 7 | # You may obtain a copy of the License at
|
---|
| 8 | #
|
---|
| 9 | # http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 10 | #
|
---|
| 11 | # Unless required by applicable law or agreed to in writing, software
|
---|
| 12 | # distributed under the License is distributed on an "AS IS" BASIS,
|
---|
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
| 14 | # See the License for the specific language governing permissions and
|
---|
| 15 | # limitations under the License.
|
---|
| 16 |
|
---|
| 17 |
|
---|
[19] | 18 |
|
---|
[23] | 19 | #################################
|
---|
| 20 | ## Generic worker functions
|
---|
| 21 |
|
---|
| 22 |
|
---|
| 23 | # Set parameters for current instance that have forced values:
|
---|
| 24 | # - TelnetEnabled must be set so that management scripts can work
|
---|
| 25 | # - AdminFileName is made to point to the local instance admins.xml
|
---|
| 26 | # - SaveGameFolder is made to point to the instance folder
|
---|
[353] | 27 | # - UserDataFolder (for GeneratedWorlds) is made to point to the <user home directory>/serverdata/
|
---|
[23] | 28 | # Params:
|
---|
[19] | 29 | # 1: Instance name
|
---|
| 30 | configSetAutoParameters() {
|
---|
[478] | 31 | setConfigValue "$1" "TelnetEnabled" "true"
|
---|
| 32 | setConfigValue "$1" "AdminFileName" "admins.xml"
|
---|
| 33 | setConfigValue "$1" "SaveGameFolder" "$(getInstancePath "$1")"
|
---|
| 34 | setConfigValue "$1" "UserDataFolder" "$SDTD_BASE/serverdata"
|
---|
[19] | 35 | }
|
---|
| 36 |
|
---|
[23] | 37 | # Query for an instance name (will be saved in $INSTANCE)
|
---|
[19] | 38 | readInstanceName() {
|
---|
| 39 | until [ $(isValidInstanceName "$INSTANCE") -eq 1 ]; do
|
---|
| 40 | read -p "Instance name: " INSTANCE
|
---|
| 41 | if [ $(isValidInstanceName "$INSTANCE") -eq 0 ]; then
|
---|
| 42 | echo "Invalid instance name, may only contain:"
|
---|
| 43 | echo " - letters (A-Z / a-z)"
|
---|
| 44 | echo " - digits (0-9)"
|
---|
| 45 | echo " - underscores (_)"
|
---|
| 46 | echo " - hyphens (-)"
|
---|
| 47 | fi
|
---|
| 48 | done
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 |
|
---|
[23] | 52 | # Check if the config template exists
|
---|
| 53 | # Returns:
|
---|
| 54 | # 0/1: no/yes
|
---|
[19] | 55 | configTemplateExists() {
|
---|
| 56 | if [ -f $SDTD_BASE/templates/config.xml ]; then
|
---|
| 57 | echo 1
|
---|
| 58 | else
|
---|
| 59 | echo 0
|
---|
| 60 | fi
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | # Get a single value from a serverconfig
|
---|
| 64 | # Params:
|
---|
| 65 | # 1: Instance name
|
---|
| 66 | # 2: Property name
|
---|
| 67 | # Returns:
|
---|
| 68 | # Property value
|
---|
| 69 | getConfigValue() {
|
---|
| 70 | local CONF=$(getInstancePath $1)/config.xml
|
---|
| 71 | $XMLSTARLET sel -t -v "/ServerSettings/property[@name='$2']/@value" $CONF
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | # Update a single value in a serverconfig
|
---|
| 75 | # Params:
|
---|
| 76 | # 1: Instance name
|
---|
| 77 | # 2: Property name
|
---|
| 78 | # 3: New value
|
---|
| 79 | setConfigValue() {
|
---|
| 80 | local CONF=$(getInstancePath $1)/config.xml
|
---|
| 81 | $XMLSTARLET ed -L -u "/ServerSettings/property[@name='$2']/@value" -v "$3" $CONF
|
---|
| 82 | }
|
---|