Ignore:
Timestamp:
Nov 14, 2023, 2:48:08 PM (12 months ago)
Author:
alloc
Message:

Scripts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • scripts/usr/local/lib/7dtd/serverconfig.sh

    r478 r481  
    2020## Generic worker functions
    2121
    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
    27 #  - UserDataFolder (for GeneratedWorlds) is made to point to the <user home directory>/serverdata/
    28 # Params:
    29 #   1: Instance name
    30 configSetAutoParameters() {
    31         setConfigValue "$1" "TelnetEnabled" "true"
    32         setConfigValue "$1" "AdminFileName" "admins.xml"
    33         setConfigValue "$1" "SaveGameFolder" "$(getInstancePath "$1")"
    34         setConfigValue "$1" "UserDataFolder" "$SDTD_BASE/serverdata"
    35 }
    3622
    3723# Query for an instance name (will be saved in $INSTANCE)
     
    7864#   3: New value
    7965setConfigValue() {
     66        local XMLSTARLET_OPTS="-L -P"
    8067        local CONF=$(getInstancePath $1)/config.xml
    81         $XMLSTARLET ed -L -u "/ServerSettings/property[@name='$2']/@value" -v "$3" $CONF
     68        local XPATHBASE="//property[@name='$2']"
     69       
     70        if [ -z $($XMLSTARLET sel -t -v "$XPATHBASE/@name" $CONF) ]; then
     71                $XMLSTARLET ed $XMLSTARLET_OPTS \
     72                        -s "/*[1]" -t elem -n "property" \
     73                        -i "//property[not(@name)]" -t attr -n "name" -v "$2" \
     74                        -i "$XPATHBASE" -t attr -n "value" -v "$3" \
     75                        $CONF
     76        else
     77                $XMLSTARLET ed $XMLSTARLET_OPTS -u "$XPATHBASE/@value" -v "$3" $CONF
     78        fi
    8279}
Note: See TracChangeset for help on using the changeset viewer.