[
  {
    "path": ".dockerignore",
    "content": "appdata/"
  },
  {
    "path": ".gitignore",
    "content": "appdata/"
  },
  {
    "path": "Dockerfile",
    "content": "FROM mmmaxwwwell/wine6:latest\n\nCOPY install-winetricks /scripts/\nRUN \\\n  mkdir /wineprefix &&\\\n  chown -R wine:wine /wineprefix &&\\\n  chmod +x /scripts/install-winetricks\nWORKDIR /scripts\nRUN runuser wine bash -c ./install-winetricks\nRUN \\\n  mkdir -p /appdata/space-engineers/bin &&\\\n  mkdir -p /appdata/space-engineers/config\nCOPY entrypoint.bash /entrypoint.bash\nCOPY entrypoint-space_engineers.bash /entrypoint-space_engineers.bash\nRUN chmod +x /entrypoint.bash && chmod +x /entrypoint-space_engineers.bash\n\nCMD /entrypoint.bash\n\n  \n\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2020 mmmaxwwwell\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# [mmmaxwwwell/space-engineers-dedicated-docker-linux](https://github.com/mmmaxwwwell/space-engineers-dedicated-docker-linux)\n\nAll of the space engineers dedicated server on wine containers I found wouldn't build, and I embarked on a journey to create my own.\n\n## Features:\n* Wine 6\n* Debian Buster\n* Installs default star system world on first run\n* Automatically updates ```<LoadWorld>``` element in ```SpaceEngineers-Dedicated.cfg```\n* Supports plugins.\n* Image built and [available on dockerhub](https://hub.docker.com/r/mmmaxwwwell/space-engineers-dedicated-docker-linux)\n* Easy to implement offsite backups, just copy everything in ```./appdata/space-engineers/config``` with your favorite backup tool.\n* Reduced container size (~4gb decompressed).\n\nThank you to:\n* [7thCore](https://github.com/7thCore) for [7thCore/sesrv-script](https://github.com/7thCore/sesrv-script)\n* [Devidian](https://github.com/Devidian) for advancing the docker implementation to a working state!\n* @Inflex for \n* @Tsu, @Aedis, @ebbit, @data, @ReAn, @BloodyIron, @spawnAjak for all around helping when testing and getting this started\n* [@UseAfterFreee](https://github.com/UseAfterFreee), [@woeisme](https:/github.com/woeisme), [@kennethx](https://github.com/kennethx), [@MarkL4YG](https://github.com/MarkL4YG), [@BaIthamel](https://github.com/BaIthamel), [@Tetrino](https://github.com/Tetrino), [@Teacay1](https://github.com/Teacay1), [@Fischchen](https://github.com/Fischchen), [@whodat](https://github.com/whodat), [@msansen](https://github.com/msansen), [@IndexOutOfMJ](https://github.com/IndexOutOfMJ) for opening issues or contributing to an issue conversation that improved the repo.\n\n## Prerequisites:\n* docker\n* docker-compose (recommended, not required to run container)\n* unzip\n\n## Tips:\n* You can copy the entire contents of ./appdata/space-engineers/config to make a backup, including the SpaceEngineers-Dedicated.cfg file.\n* The ```./start``` script will start the server using docker-compose in detached mode, and then attaches to the log output. You can press <kbd>ctrl</kbd>+<kbd>c</kbd> to detach from the logs and keep the server running.\n* If you are running plugins, the first time your run this, check your SpaceEngineers-Dedicated.cfg file for the Plugins element. If it spans multiple lines, you must replace it with ```<Plugins />```, exactly like that. The server will query ./appdata/space-engineers/config/Plugins and update the config file as needed from then on.\n* If you start the docker container without placing SpaceEngineers-Dedicated.cfg in the correct location, docker will create an empty folder where it should be. The container won't run until you stop the container, delete the empty SpaceEngineers-Dedicated.cfg folder, and replace it with the actual file.\n\n## Usage:\n\n### -RECOMENDED- Pull from dockerhub and run with docker-compose\n\n* Clone this repo with ```git clone https://github.com/mmmaxwwwell/space-engineers-dedicated-docker-linux.git```.\n* Change directory into the cloned repo with ```cd space-engineers-dedicated-docker-linux```.\n* Run the start script with ```./start```. This will initialize the ./appdata folder, unzip an empty star system from star-system.zip and start the server.\n\n### Pull and run from dockerhub without docker-compose:\nFrom this directory run :\n\n``` \ndocker run --restart always -p \"27016:27016/udp\" \\\n  -v $(pwd)/appdata/space-engineers/config/World:/appdata/space-engineers/World\\\n  -v $(pwd)/appdata/space-engineers/bins/SpaceEngineersDedicated:/appdata/space-engineers/SpaceEngineersDedicated\\\n  -v $(pwd)/appdata/space-engineers/bins/steamcmd:/home/se/.steam\\\n  -v $(pwd)/appdata/space-engineers/config/SpaceEngineers-Dedicated.cfg:/appdata/space-engineers/SpaceEngineersDedicated/SpaceEngineers-Dedicated.cfg\\\n  mmmaxwwwell/space-engineers-dedicated-docker-linux:latest \n```\n\n## Exit Codes:\n| Exit Code | Reason |\n| - | - |\n| 129 | Container is missing /appdata/space-engineers/World folder, volume mounts are mounted incorrectly. |\n| 130 | Container is missing /appdata/space-engineers/World/Sandbox.sbc, World is not placed in the right folder, or the volume mounts are mounted incorrectly. Ensure your world is in ```./appdata/space-engineers/config/World/```.|\n| 131 | Container is missing the dedicated server config file SpaceEngineers-Dedicated.cfg. Ensure that you have placed SpaceEngineers-Dedicated.cfg at ```./appdata/space-engineers/config/SpaceEngineers-Dedicated.cfg```. |\n\n## Directory Structure:\n```\nSpaceEngineersDedicated contains the dedicated server files\nsteamcmd contains steamcmd\nconfig contains all the user configurable files for the game instance\nWorld contains the world files\n\nappdata\n└── space-engineers\n    ├── bins\n    │   ├── SpaceEngineersDedicated \n    │   └── steamcmd \n    └── config \n        ├── SpaceEngineers-Dedicated.cfg\n        └── World\n            ├── Alien-291759539d120000.vx2\n            ├── EarthLike-1779144428d120000.vx2\n            ├── Europa-595048092d19000.vx2\n            ├── Mars-2044023682d120000.vx2\n            ├── Moon-1353915701d19000.vx2\n            ├── SANDBOX_0_0_0_.sbs\n            ├── Sandbox.sbc\n            ├── Sandbox_config.sbc\n            ├── Titan-2124704365d19000.vx2\n            ├── Triton-12345d80253.vx2\n            └── thumb.jpg\n\n```"
  },
  {
    "path": "docker-compose.yml",
    "content": "version: '3'\n\nservices:\n  se-server:\n    image: mmmaxwwwell/space-engineers-dedicated-docker-linux:latest\n    container_name: space-engineers-dedicated-docker-linux\n    restart: unless-stopped\n    volumes:\n      - ./appdata/space-engineers/config/World:/appdata/space-engineers/World\n      - ./appdata/space-engineers/config/Plugins:/appdata/space-engineers/Plugins\n      - ./appdata/space-engineers/config/SpaceEngineers-Dedicated.cfg:/appdata/space-engineers/SpaceEngineersDedicated/SpaceEngineers-Dedicated.cfg\n      - ./appdata/space-engineers/bins/SpaceEngineersDedicated:/appdata/space-engineers/SpaceEngineersDedicated\n      - ./appdata/space-engineers/bins/steamcmd:/home/wine/.steam\n    ports:\n     - \"27016:27016/udp\"\n"
  },
  {
    "path": "entrypoint-space_engineers.bash",
    "content": "#!/bin/bash\nsource ~/.profile\nsource ~/.bash_profile\ncd /appdata/space-engineers/SpaceEngineersDedicated/DedicatedServer64/\nenv WINEARCH=win64 WINEDEBUG=-all WINEPREFIX=/wineprefix wine /appdata/space-engineers/SpaceEngineersDedicated/DedicatedServer64/SpaceEngineersDedicated.exe -noconsole -path Z:\\\\appdata\\\\space-engineers\\\\SpaceEngineersDedicated -ignorelastsession"
  },
  {
    "path": "entrypoint.bash",
    "content": "#!/bin/bash\n\n# #check if /appdata/space-engineers/config/World is a folder\nif [ ! -d \"/appdata/space-engineers/World\" ]; then\n  echo \"World folder does not exist, exiting\"\n  exit 129\nfi\n\n# #check if /appdata/space-engineers/config/World/Sandbox.sbc exists and is a file\nif [ ! -f \"/appdata/space-engineers/World/Sandbox.sbc\" ]; then\n  echo \"Sandbox.sbc file does not exist, exiting.\"\n  exit 130\nfi\n\n# #check if /appdata/space-engineers/config/SpaceEngineers-Dedicated.cfg is a file\nif [ ! -f \"/appdata/space-engineers/SpaceEngineersDedicated/SpaceEngineers-Dedicated.cfg\" ]; then\n  echo \"SpaceEngineers-Dedicated.cfg file does not exist, exiting.\"\n  exit 131\nfi\n\n#set <LoadWorld> to the correct value\ncat /appdata/space-engineers/SpaceEngineersDedicated/SpaceEngineers-Dedicated.cfg | sed -E '/.*LoadWorld.*/c\\  <LoadWorld>Z:\\\\appdata\\\\space-engineers\\\\World</LoadWorld>' > /tmp/SpaceEngineers-Dedicated.cfg && cat /tmp/SpaceEngineers-Dedicated.cfg > /appdata/space-engineers/SpaceEngineersDedicated/SpaceEngineers-Dedicated.cfg\n\n#set game port to the correct value\n#cat /appdata/space-engineers/SpaceEngineersDedicated/SpaceEngineers-Dedicated.cfg | sed -E '/.*ServerPort.*/c\\  <ServerPort>27016</ServerPort>' > /tmp/SpaceEngineers-Dedicated.cfg && cat /tmp/SpaceEngineers-Dedicated.cfg > /appdata/space-engineers/SpaceEngineersDedicated/SpaceEngineers-Dedicated.cfg\n\n#configure plugins section in SpaceEngineers-Dedicated.cfg\n#get new plugins string\n\nif [ \"$(ls -1 /appdata/space-engineers/Plugins/*.dll | wc -l)\" -gt \"0\" ]; then\n  PLUGINS_STRING=$(ls -1 /appdata/space-engineers/Plugins/*.dll |\\\n  awk '{ print \"<string>\" $0 \"</string>\" }' |\\\n  tr -d '\\n' |\\\n  awk '{ print \"<Plugins>\" $0 \"</Plugins>\" }' )\nelse\n  PLUGINS_STRING=\"<Plugins />\"\nfi\n\nSED_EXPRESSION_EMPTY=\"s/<Plugins \\/>/${PLUGINS_STRING////\\\\/} /g\"\nSED_EXPRESSION_FULL=\"s/<Plugins>.*<\\/Plugins>/${PLUGINS_STRING////\\\\/} /g\"\n\n#find and replace in SpaceEngineers-Dedicated.cfg for empty \"<Plugins />\" element\ncat /appdata/space-engineers/SpaceEngineersDedicated/SpaceEngineers-Dedicated.cfg | sed -E \"$SED_EXPRESSION_EMPTY\" > /tmp/SpaceEngineers-Dedicated.cfg && cat /tmp/SpaceEngineers-Dedicated.cfg > /appdata/space-engineers/SpaceEngineersDedicated/SpaceEngineers-Dedicated.cfg\n\n#find and replace in SpaceEngineers-Dedicated.cfg for filled out \"<Plugins>...</Plugins>\" element\n# sed can't handle multiple lines easily, so everything needs to be on a single line.\ncat /appdata/space-engineers/SpaceEngineersDedicated/SpaceEngineers-Dedicated.cfg | sed -E \"$SED_EXPRESSION_FULL\" > /tmp/SpaceEngineers-Dedicated.cfg && cat /tmp/SpaceEngineers-Dedicated.cfg > /appdata/space-engineers/SpaceEngineersDedicated/SpaceEngineers-Dedicated.cfg\n\n\nrunuser -l wine bash -c 'steamcmd +login anonymous +@sSteamCmdForcePlatformType windows +force_install_dir /appdata/space-engineers/SpaceEngineersDedicated +app_update 298740 +quit'\nrunuser -l wine bash -c '/entrypoint-space_engineers.bash'"
  },
  {
    "path": "install-winetricks",
    "content": "#!/bin/bash\nXvfb :5 -screen 0 1024x768x16 &\nenv WINEARCH=win64 WINEDEBUG=-all WINEDLLOVERRIDES=\"mscoree=d\" WINEPREFIX=/wineprefix wineboot --init /nogui \nenv WINEARCH=win64 WINEDEBUG=-all WINEPREFIX=/wineprefix ./winetricks corefonts \nenv DISPLAY=:5.0 WINEARCH=win64 WINEDEBUG=-all WINEPREFIX=/wineprefix ./winetricks -q vcrun2017 \nenv DISPLAY=:5.0 WINEARCH=win64 WINEDEBUG=-all WINEPREFIX=/wineprefix ./winetricks -q --force dotnet48 \nenv WINEARCH=win64 WINEDEBUG=-all WINEPREFIX=/wineprefix ./winetricks sound=disabled \nenv DISPLAY=:5.0 WINEARCH=win64 WINEDEBUG=-all WINEPREFIX=/wineprefix ./winetricks -q vcrun2013 \nrm -rf ~/.cache"
  },
  {
    "path": "restart",
    "content": "#!/bin/bash\n./stop\n./start"
  },
  {
    "path": "start",
    "content": "#!/bin/bash\nsudo mkdir -p appdata/space-engineers/bins/SpaceEngineersDedicated\nsudo mkdir -p appdata/space-engineers/bins/steamcmd\nsudo mkdir -p appdata/space-engineers/config/World\nsudo mkdir -p appdata/space-engineers/config/Plugins\nif [ ! -f ./appdata/space-engineers/config/World/Sandbox.sbc ]; then\n    echo \"World not found, initalizing empty star system...\"\n    sudo unzip -n star-system.zip -d ./appdata/space-engineers/config\nfi\n\n#container executes server as 1000:1000\nif [ \"$(stat -c '%u' appdata)\" != \"1000\" ]; then\n    echo \"Setting owner of appdata to UID 1000\"\n    sudo chown -R 1000:1000 appdata\nfi\n\nsudo docker-compose up -d \nsudo docker-compose logs -f"
  },
  {
    "path": "stop",
    "content": "#/bin/bash\nsudo docker-compose stop"
  },
  {
    "path": "test",
    "content": "#!/bin/bash\n#docker run -it --rm --entrypoint /bin/bash -p \"27016:27016/udp\" \\\ndocker run -p \"27016:27016/udp\" \\\n  -v $(pwd)/appdata/space-engineers/config/World:/appdata/space-engineers/World\\\n  -v $(pwd)/appdata/space-engineers/config/Plugins:/appdata/space-engineers/Plugins\\\n  -v $(pwd)/appdata/space-engineers/bins/SpaceEngineersDedicated:/appdata/space-engineers/SpaceEngineersDedicated\\\n  -v $(pwd)/appdata/space-engineers/bins/steamcmd:/home/se/.steam\\\n  -v $(pwd)/appdata/space-engineers/config/SpaceEngineers-Dedicated.cfg:/appdata/space-engineers/SpaceEngineersDedicated/SpaceEngineers-Dedicated.cfg\\\n  mmmaxwwwell/space-engineers-dedicated-docker-linux:wine6-plugins"
  }
]