From c479033fc987926549b1f658f200e428159041b0 Mon Sep 17 00:00:00 2001 From: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Date: Tue, 30 Jan 2024 14:06:10 +0200 Subject: [PATCH] palworld - allow additional config (#2100) * palworld - allow additional config * bump version * test actual keys * dont print passwords * handle bools * lint * handle bools * only create dirs if not exist * bypass bools on sh * handle weird cases with quoting --- library/ix-dev/community/palworld/Chart.yaml | 2 +- .../community/palworld/ci/basic-values.yaml | 13 +++- .../ix-dev/community/palworld/questions.yaml | 31 +++++++-- .../palworld/templates/_palworld.tpl | 68 ++++++++++++------- .../community/palworld/templates/_params.tpl | 11 +++ library/ix-dev/community/palworld/values.yaml | 1 + 6 files changed, 95 insertions(+), 31 deletions(-) diff --git a/library/ix-dev/community/palworld/Chart.yaml b/library/ix-dev/community/palworld/Chart.yaml index 2650f3eb8c..02dbbc87ad 100644 --- a/library/ix-dev/community/palworld/Chart.yaml +++ b/library/ix-dev/community/palworld/Chart.yaml @@ -3,7 +3,7 @@ description: Palworld is a multiplayer, open-world survival crafting game where annotations: title: Palworld type: application -version: 1.0.2 +version: 1.0.3 apiVersion: v2 appVersion: palworld kubeVersion: '>=1.16.0-0' diff --git a/library/ix-dev/community/palworld/ci/basic-values.yaml b/library/ix-dev/community/palworld/ci/basic-values.yaml index f1c0dc6193..9a418b5d1d 100644 --- a/library/ix-dev/community/palworld/ci/basic-values.yaml +++ b/library/ix-dev/community/palworld/ci/basic-values.yaml @@ -13,8 +13,19 @@ palworldStorage: type: pvc palworldConfig: - adminPassword: sec!@#%-_ret123@#%-_!@#% + adminPassword: asdfhjfgk7!@^&$1asdf backup: enabled: true interval: 60 keep: 3 + iniKeys: + - key: PlayerDamageRateAttack + value: 1.000000 + - key: DropItemMaxNum + value: 4000 + - key: Region + value: "" + - key: PalEggDefaultHatchingTime + value: 72.450000 + - key: bEnablePlayerToPlayerDamage + value: true diff --git a/library/ix-dev/community/palworld/questions.yaml b/library/ix-dev/community/palworld/questions.yaml index 23b2931e78..749c36498b 100644 --- a/library/ix-dev/community/palworld/questions.yaml +++ b/library/ix-dev/community/palworld/questions.yaml @@ -25,9 +25,6 @@ questions: private: true required: true default: "" - valid_chars: "[a-zA-Z0-9!@#%-_]*" - valid_chars_error: | - Can contain at numbers, letters, and the following characters: !@#%-_ - variable: server label: Server Configuration description: Configure the server for Palworld @@ -56,9 +53,31 @@ questions: type: string private: true default: "" - valid_chars: "[a-zA-Z0-9!@#%-_]*" - valid_chars_error: | - Can contain at numbers, letters, and the following characters: !@#%-_ + - variable: iniKeys + label: Configure INI Keys + description: | + Enter your INI keys
+ Updates the keys in PalWorldSettings.ini + schema: + type: list + default: [] + items: + - variable: iniKey + label: INI Key + schema: + type: dict + attrs: + - variable: key + label: Key + schema: + type: string + default: "" + required: true + - variable: value + label: Value + schema: + type: string + default: "" - variable: backup label: Backup description: Configure the backup for Palworld diff --git a/library/ix-dev/community/palworld/templates/_palworld.tpl b/library/ix-dev/community/palworld/templates/_palworld.tpl index f8b286845d..2aafc444f3 100644 --- a/library/ix-dev/community/palworld/templates/_palworld.tpl +++ b/library/ix-dev/community/palworld/templates/_palworld.tpl @@ -88,32 +88,54 @@ workload: - | config={{ $srvDir }}/Pal/Saved/Config/LinuxServer cfgFile=${config}/PalWorldSettings.ini - mkdir -p ${config} + if [ ! -d ${config} ]; then + echo "Config directory not found, creating..." + mkdir -p ${config} + fi if [ ! -f ${cfgFile} ]; then echo "Config file not found, fetching..." - # Fetch the config file if it doesn't exist, just like the container does + # -- Fetch the config file if it doesn't exist, just like the container does wget -qO ${cfgFile} https://github.com/ich777/docker-steamcmd-server/raw/palworld/config/PalWorldSettings.ini fi - echo "Setting RCON status..." - sed -i 's/\(RCONEnabled=\)[^,]*/\1True/g' ${cfgFile} - echo "Set to [$(grep -Po 'RCONEnabled=[^,]*' ${cfgFile})]" - echo "Setting RCON Port..." - sed -i 's/\(RCONPort=\)[^,]*/\1{{ .Values.palworldNetwork.rconPort }}/g' ${cfgFile} - echo "Set to [$(grep -Po 'RCONPort=[^,]*' ${cfgFile})]" - echo "Setting Game Port..." - sed -i 's/\(PublicPort=\)[^,]*/\1{{ .Values.palworldNetwork.serverPort }}/g' ${cfgFile} - echo "Set to [$(grep -Po 'PublicPort=[^,]*' ${cfgFile})]" - echo "Setting Server Name..." - sed -i 's/\(ServerName=\)[^,]*/\1{{ .Values.palworldConfig.server.name | quote }}/g' ${cfgFile} - echo "Set to [$(grep -Po 'ServerName=[^,]*' ${cfgFile})]" - echo "Setting Server Description..." - sed -i 's/\(ServerDescription=\)[^,]*/\1{{ .Values.palworldConfig.server.description | quote }}/g' ${cfgFile} - echo "Set to [$(grep -Po 'ServerDescription=[^,]*' ${cfgFile})]" - echo "Setting Server Password..." - sed -i 's/\(ServerPassword=\)[^,]*/\1{{ .Values.palworldConfig.server.password | quote }}/g' ${cfgFile} - echo "Server Password set..." - echo "Setting Admin Password..." - sed -i 's/\(AdminPassword=\)[^,]*/\1{{ .Values.palworldConfig.adminPassword | quote }}/g' ${cfgFile} - echo "Admin Password set..." + + set_ini_value() { + local key="${1}" + local value="${2}" + local quote="${3:-false}" + local print="${4:-true}" + # -- Escape special characters for sed + escaped_value=$(printf '%s\n' "$value" | sed 's/[&/\]/\\&/g') + if [ "$quote" = true ]; then + escaped_value="\"${escaped_value}\"" + fi + + echo "Setting ${key}..." + sed -i "s|\(${key}=\)[^,]*|\1${escaped_value}|g" "${cfgFile}" + if [ "$print" = true ]; then + echo "Set to $(grep -Po "(?<=${key}=)[^,]*" "${cfgFile}")" + fi + } + + set_ini_value "RCONEnabled" True + set_ini_value "RCONPort" {{ .Values.palworldNetwork.rconPort }} + set_ini_value "PublicPort" {{ .Values.palworldNetwork.serverPort }} + set_ini_value "ServerName" {{ .Values.palworldConfig.server.name | quote }} true + set_ini_value "ServerDescription" {{ .Values.palworldConfig.server.description | quote }} true + set_ini_value "ServerPassword" {{ .Values.palworldConfig.server.password | squote }} true false + set_ini_value "AdminPassword" {{ .Values.palworldConfig.adminPassword | squote }} true false + + {{- range $item := .Values.palworldConfig.iniKeys }} + {{- if mustHas (kindOf $item.value) (list "int" "int64" "float64") }} + echo "Key {{ $item.key }} is a {{ kindOf $item.value }}, setting without quotes..." + set_ini_value "{{ $item.key }}" {{ $item.value }} + {{- else if or (eq ((toString $item.value) | lower) "true") (eq ((toString $item.value) | lower) "false") }} + echo "Key {{ $item.key }} is a boolean, setting without quotes..." + set_ini_value "{{ $item.key }}" {{ (toString $item.value) | camelcase }} + {{- else }} + echo "Key {{ $item.key }} is a {{ kindOf $item.value }}, setting with quotes..." + set_ini_value "{{ $item.key }}" {{ $item.value | quote }} true + {{- end }} + {{- end }} + echo "Done!" {{- end -}} diff --git a/library/ix-dev/community/palworld/templates/_params.tpl b/library/ix-dev/community/palworld/templates/_params.tpl index 95de5bd598..85a4db9b63 100644 --- a/library/ix-dev/community/palworld/templates/_params.tpl +++ b/library/ix-dev/community/palworld/templates/_params.tpl @@ -15,4 +15,15 @@ {{- if not .Values.palworldConfig.backup -}} {{- $_ := set .Values.palworldConfig "backup" dict -}} {{- end -}} + + {{- $reservedKeys := list + "RCONEnabled" "RCONPort" "PublicPort" "ServerName" + "ServerDescription" "ServerPassword" "AdminPassword" + -}} + + {{- range $item := .Values.palworldConfig.iniKeys }} + {{- if (mustHas $item.key $reservedKeys) -}} + {{- fail (printf "PalWorld - [%v] is a reserved key." $item.key) -}} + {{- end -}} + {{- end -}} {{- end -}} diff --git a/library/ix-dev/community/palworld/values.yaml b/library/ix-dev/community/palworld/values.yaml index 9c199faeee..dcd9794f72 100644 --- a/library/ix-dev/community/palworld/values.yaml +++ b/library/ix-dev/community/palworld/values.yaml @@ -24,6 +24,7 @@ palworldConfig: - -useperfthreads - -NoAsyncLoadingThread - -UseMultithreadForDS + iniKeys: [] updatePublicIP: false validate: false username: ''