diff --git a/scripts/default/enshrouded-bootstrap-shared b/scripts/default/enshrouded-bootstrap-shared index f84be5e..1139a19 100644 --- a/scripts/default/enshrouded-bootstrap-shared +++ b/scripts/default/enshrouded-bootstrap-shared @@ -44,7 +44,6 @@ updateOrCreateEnshroudedServerConfig() { cat >${install_path}/enshrouded_server.json << EOF { "name": "Enshrouded Server", - "password": "", "saveDirectory": "./savegame", "logDirectory": "./logs", "ip": "0.0.0.0", @@ -58,10 +57,6 @@ EOF echo "$(jq --arg name "$SERVER_NAME" '.name = $name' ${install_path}/enshrouded_server.json)" > ${install_path}/enshrouded_server.json fi - if [[ -n "$SERVER_PASSWORD" ]]; then - echo "$(jq --arg password "$SERVER_PASSWORD" '.password = $password' ${install_path}/enshrouded_server.json)" > ${install_path}/enshrouded_server.json - fi - if [[ -n "$SERVER_SAVE_DIR" ]]; then echo "$(jq --arg saveDirectory "$SERVER_SAVE_DIR" '.saveDirectory = $saveDirectory' ${install_path}/enshrouded_server.json)" > ${install_path}/enshrouded_server.json fi @@ -97,6 +92,8 @@ updateUserGroupConfig() { echo "$(jq '.userGroups = []' ${install_path}/enshrouded_server.json)" > ${install_path}/enshrouded_server.json fi + handleDeprecatedServerPassword + # add missing groups for group_index in $(seq 0 $group_count); do if ! jq -e --argjson group_index "$group_index" '.userGroups | has($group_index)' ${install_path}/enshrouded_server.json >/dev/null; then @@ -143,6 +140,28 @@ updateUserGroupConfig() { done } +handleDeprecatedServerPassword() { + if [[ -n "$SERVER_PASSWORD" ]]; then + warn "SERVER_PASSWORD is deprecated, pls consider using SERVER_ROLE__PASSWORD instead" + warn "falling back to \"Default\" server role password" + + # check if group 0 exists if not create it + if ! jq -e '.userGroups[0]' ${install_path}/enshrouded_server.json >/dev/null; then + debug "default group (index: 0) does not exist, creating default group." + echo "$(jq --argjson group_index "$group_index" '.userGroups += [{"name": "Default", "password": "", "canKickBan": false, "canAccessInventories": false, "canEditBase": false, "canExtendBase": false, "reservedSlots": 0}]' ${install_path}/enshrouded_server.json)" > ${install_path}/enshrouded_server.json + fi + + # check if group 0 name is "Default" if not return + if [[ "$(jq -r '.userGroups[0].name' ${install_path}/enshrouded_server.json)" != "Default" ]]; then + warn "default group (index: 0) has not the name \"Default\". Skipping password update!" + return + fi + + debug "updating default group (index: 0) password to $SERVER_PASSWORD" + echo "$(jq --arg password "$SERVER_PASSWORD" '.userGroups[0].password = $password' ${install_path}/enshrouded_server.json)" > ${install_path}/enshrouded_server.json + fi +} + updateGameSettingsConfig() { if [[ -n "$SERVER_GS_PRESET" ]]; then debug "updating gameSettingsPreset to $SERVER_GS_PRESET"