setup.sh.jinja 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. {% macro setup_script(values, tpl) -%}
  2. #!/bin/bash
  3. {%- set cfg = "%s/Pal/Saved/Config/LinuxServer" | format(values.consts.server_path) %}
  4. {%- set cfg_file = "%s/PalWorldSettings.ini" | format(cfg) %}
  5. if [ ! -d {{ cfg }} ]; then
  6. echo "Config directory not found, creating..."
  7. mkdir -p {{ cfg }}
  8. fi
  9. if [ ! -f {{ cfg_file }} ]; then
  10. echo "Config file not found, fetching..."
  11. # -- Fetch the config file if it doesn't exist, just like the container does
  12. wget -qO {{ cfg_file }} https://github.com/ich777/docker-steamcmd-server/raw/palworld/config/PalWorldSettings.ini || { echo "Failed to fetch config file"; exit 1; }
  13. fi
  14. set_ini_value() {
  15. local key="${1}"
  16. local value="${2}"
  17. local quote="${3:-false}"
  18. local print="${4:-true}"
  19. # -- Escape special characters for sed
  20. escaped_value=$(printf '%s\n' "$value" | sed 's/[&/\]/\\&/g')
  21. if [ "$quote" = true ]; then
  22. escaped_value="\"${escaped_value}\""
  23. fi
  24. echo -n "Setting ${key}..."
  25. # Check if the key already exists
  26. if grep -q "^OptionSettings=\(.*${key}=.*\)$" "{{ cfg_file }}"; then
  27. # Key exists, update its value using the original logic
  28. sed -i "s|\(${key}=\)[^,]*|\1${escaped_value}|g" "{{ cfg_file }}" || { echo "Failed to update ${key}"; exit 1; }
  29. else
  30. # Key doesn't exist, append it right after "OptionSettings=("
  31. sed -i "s|^\(OptionSettings=(\)|\1${key}=${escaped_value}, |" "{{ cfg_file }}" || { echo "Failed to append ${key}"; exit 1; }
  32. fi
  33. if [ "$print" = true ]; then
  34. echo " Set to $(grep -Po "(?<=${key}=)[^,]*" "{{ cfg_file }}")" || { echo "Failed to print ${key}"; exit 1; }
  35. else
  36. echo " Set, but value is marked as private"
  37. fi
  38. }
  39. set_ini_value "RCONEnabled" True
  40. set_ini_value "RCONPort" {{ values.network.rcon_port.port_number }}
  41. set_ini_value "PublicPort" {{ values.network.server_port.port_number }}
  42. set_ini_value "ServerName" "{{ values.palworld.server.name }}" true
  43. set_ini_value "ServerDescription" "{{ values.palworld.server.description }}" true
  44. set_ini_value "ServerPassword" '{{ values.palworld.server.password }}' true false
  45. set_ini_value "AdminPassword" '{{ values.palworld.admin_password }}' true false
  46. set_ini_value "AllowConnectPlatform" '{{ values.palworld.allow_platform }}' false
  47. echo "Setting user defined ini keys..."
  48. {%- for item in values.palworld.ini_keys %}
  49. {%- set key = item.key %}
  50. {%- set value = item.value|string %}
  51. {%- if tpl.funcs.is_number(value) %}
  52. echo "Value of [{{ key }}] is a number, setting without quotes"
  53. set_ini_value "{{ key }}" {{ value }}
  54. {%- elif tpl.funcs.is_boolean(value) %}
  55. echo "Value of [{{ key }}] is a boolean, setting without quotes"
  56. set_ini_value "{{ key }}" {{ tpl.funcs.camel_case(value) }}
  57. {%- else %}
  58. echo "Value of [{{ key }}] is a string, setting with quotes"
  59. set_ini_value "{{ key }}" "{{ value }}" true
  60. {%- endif %}
  61. {%- endfor %}
  62. {%- endmacro %}