Bisa / factorio-init

Factorio init script
MIT License
414 stars 82 forks source link
factorio

Factorio Init

A factorio init script in bash

Requirements

Debugging

If you find yourself wondering why stuff is not working the way you expect:

Install

Notes for users with an OS that has a older glibc version

The config has options for declaring an alternate glibc root. The user millisa over on the factorio forums has created a wonderful guide to follow on creating this alternate glibc root (side by side).

First-run

Autocompletion

# either symlink:
ln -s /opt/factorio-init/extras/bash_autocomplete /etc/bash_completion.d/factorio
# or source:
echo "source /opt/factorio-init/extras/bash_autocomplete" >> ~/.bashrc

# then ensure factorio-init is added to your PATH, ie by:
ln -s /opt/factorio-init/factorio /usr/local/bin/factorio

# restart your shell to verify that it worked

Systemd

cp /opt/factorio-init/extras/factorio.service.example /etc/systemd/system/factorio.service
# Edit the service file to suit your environment then reload systemd
systemctl daemon-reload
systemctl start factorio
systemctl status -l factorio
# Remember to enable the service at startup if you want that:
systemctl enable factorio

Note that systemd won't be able to keep track of the server process if you use this script to restart during updates. Use the config option UPDATE_PREVENT_RESTART=1 and implement your own stop/start logic to work around this.

SysvInit

ln -s /opt/factorio-init/factorio /etc/init.d/factorio
# Make the script executable:
chmod +x /opt/factorio-init/factorio
# Try it out:
service factorio help
# Do not forget to enable the service at boot if you want that.

Contributing

When contributing to this repo, please ensure your contribution is covered by at least one test in test/factorio.bats or the very least: do not create pull requests with failing tests, thank you.

Test the code

Testing is done using bats-core, bats-assert and bats-support.

@test "DEBUG=1 produces output" {
    # To access functions within ./factorio, source it then use the run command:
    source ./factorio
    export DEBUG=1
    run debug "TEST"
    # use the various asserts from bats-assert
    assert_output "DEBUG: TEST"
}
git submodule init
git submodule update

With .githooks

git config --local core.hooksPath extras/.githooks

The extras/.githooks/pre-push will run shellcheck, local tests as well as docker tests with and without resources.

With Docker

docker build --build-arg ubuntu_version=20.04 \
             --build-arg factorio_version=1.1.61 \
             --tag ubuntu-finit:latest - < extras/docker/Dockerfile.ubuntu
docker build --build-arg centos_version=centos8 \
             --build-arg factorio_version=1.1.61 \
             --tag centos-finit:latest - < extras/docker/Dockerfile.centos

Adding --target no-test-resources to the build command will avoid downloading test resources online but it will also skip tests that rely on the resources(!)

docker run -it --rm -v "$(pwd):/opt/factorio-init" --workdir /opt/factorio-init ubuntu-finit:latest extras/test
docker run -it --rm -v "$(pwd):/opt/factorio-init" --workdir /opt/factorio-init centos-finit:latest extras/test

Manually

Please note that some tests will be skipped unless you run them with the docker image or via .githooks, but running them manually is a quick way to get started.

./extras/test/libs/bats-core/bin/bats extras/test

Using parallel, adding --jobs 10 to the above (adjust the number accordingly) will allow you to execute more tests in parallel and in turn possibly decrease the total time required to complete the run.

Thank You

You are all a great source of motivation, thank you.

License

This code is realeased with the MIT license, see the LICENSE file.