New Feature: Creating a default Variables JSON from environment variables (#469)
This commit is contained in:
1 parent
bd08ec22c7
commit
2623a85783
2 files changed
+52
No files matched your search
@@ -109,6 +109,7 @@ Typically, each property is configured instead by the UPPER_SNAKE_CASE equivalen
|
|||||||
- `EMIT_SERVER_TELEMETRY`
|
- `EMIT_SERVER_TELEMETRY`
|
||||||
- `MSA_GAMERTAGS_ONLY`
|
- `MSA_GAMERTAGS_ONLY`
|
||||||
- `ITEM_TRANSACTION_LOGGING_ENABLED`
|
- `ITEM_TRANSACTION_LOGGING_ENABLED`
|
||||||
|
- `VARIABLES`
|
||||||
|
|
||||||
For example, to configure a flat, creative server instead of the default use:
|
For example, to configure a flat, creative server instead of the default use:
|
||||||
|
|
||||||
@@ -191,6 +192,29 @@ There are various tools to look XUIDs up online and they are also printed to the
|
|||||||
-e ALLOW_LIST_USERS="player1:1234567890,player2:0987654321"
|
-e ALLOW_LIST_USERS="player1:1234567890,player2:0987654321"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Variables
|
||||||
|
|
||||||
|
Custom server variables are supported by Bedrock. Details and usage instructions can be found on the official bedrock documentation, located here:
|
||||||
|
|
||||||
|
- [Variables & Secrets - Minecraft Creator Docs](https://learn.microsoft.com/en-us/minecraft/creator/documents/scriptingservers?view=minecraft-bedrock-stable#variables-and-secrets)
|
||||||
|
- [Variables & Secrets - minecraft/server-admin example](https://learn.microsoft.com/en-us/minecraft/creator/scriptapi/minecraft/server-admin/serversecrets?view=minecraft-bedrock-experimental#getplayerprofilets-1)
|
||||||
|
|
||||||
|
Custom server variables are passed in as comma-separated simple key-value pairs or as a full JSON string.
|
||||||
|
|
||||||
|
Server variables are parsed into their most likely type (number-like turn into numbers, all other inputs are treated as string) using [jq's `fromjson` command](https://jqlang.github.io/jq/manual/#convert-to-from-json). In the example below, `var1` is a string, `var2` is a number, and `var3` is a string.
|
||||||
|
|
||||||
|
For greater control on types, users can provide a full string JSON representation that is used as-is.
|
||||||
|
|
||||||
|
All variables are written to the variables file located at `config/default/variables.json`. There is no support for Module-specific variable handling at this time.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
# passing in simple expressions
|
||||||
|
-e VARIABLES="var1=customStringValue,var2=1234,var3=true"
|
||||||
|
|
||||||
|
# pass in a full json object:
|
||||||
|
-e VARIABLES='{"mobSpawnRate":22,"enableCheats":true,"worldArray":["My World", "Abc", 123]}'
|
||||||
|
```
|
||||||
|
|
||||||
## Mods Addons
|
## Mods Addons
|
||||||
|
|
||||||
Also known as behavior or resource packs, in order to add mods into your server you can follow these steps, tested with [OPS (One Player Sleep)](https://foxynotail.com/addons/ops/) and [bedrocktweaks](https://bedrocktweaks.net/resource-packs/)
|
Also known as behavior or resource packs, in order to add mods into your server you can follow these steps, tested with [OPS (One Player Sleep)](https://foxynotail.com/addons/ops/) and [bedrocktweaks](https://bedrocktweaks.net/resource-packs/)
|
||||||
|
|||||||
@@ -179,6 +179,34 @@ if [[ -n "$ALLOW_LIST_USERS" || -n "$WHITE_LIST_USERS" ]]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$VARIABLES" ]]; then
|
||||||
|
echo "Setting variables"
|
||||||
|
mkdir -p config/default
|
||||||
|
|
||||||
|
# Try to parse VARIABLES as JSON
|
||||||
|
if echo "$VARIABLES" | jq empty >/dev/null 2>&1; then
|
||||||
|
# VARIABLES is valid JSON
|
||||||
|
echo "$VARIABLES" | jq '.' > "config/default/variables.json"
|
||||||
|
else
|
||||||
|
# VARIABLES is not valid JSON, attempt to parse as custom format
|
||||||
|
echo "VARIABLES is not valid JSON, attempting to parse as custom format"
|
||||||
|
|
||||||
|
# Parse the VARIABLES using custom format (key:value,key:value)
|
||||||
|
# Note: Values should not contain unescaped commas or colons
|
||||||
|
jq -n --arg vars "$VARIABLES" '
|
||||||
|
$vars
|
||||||
|
| split(",")
|
||||||
|
| map(
|
||||||
|
split("=") as $kv |
|
||||||
|
{ ($kv[0]): ($kv[1] | fromjson? // $kv[1]) }
|
||||||
|
)
|
||||||
|
| add
|
||||||
|
' > "config/default/variables.json"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# prevent issue with bind mounted server.properties which can not be moved (sed tries to move the file when '-i' is used)
|
# prevent issue with bind mounted server.properties which can not be moved (sed tries to move the file when '-i' is used)
|
||||||
_SERVER_PROPERTIES=$(sed '/^white-list=.*/d' server.properties) #Removes white-list= line from server.properties
|
_SERVER_PROPERTIES=$(sed '/^white-list=.*/d' server.properties) #Removes white-list= line from server.properties
|
||||||
echo "${_SERVER_PROPERTIES}" > server.properties
|
echo "${_SERVER_PROPERTIES}" > server.properties
|
||||||
|
|||||||
Reference in new issue
Block a user