|
1 | | -# Factorio Init Script |
2 | | -A factorio init script for linux |
| 1 | +# Factorio Init |
3 | 2 |
|
4 | | -# Dependencies |
5 | | - Among others: |
6 | | - - cURL |
| 3 | +A factorio init script in bash |
7 | 4 |
|
8 | | -# Debugging |
9 | | - If you find yourself wondering why stuff is not working the way you expect: |
10 | | - - Check the logs, I suggest you `tail -f /opt/factorio/factorio-current.log` in a separate session |
11 | | - - Enable debugging in the config and/or: |
12 | | - - Try running the same commands as the factorio user (`/opt/factorio-init/factorio invocation` will tell you what the factorio user tries to run at start) |
| 5 | +## Requirements |
| 6 | + |
| 7 | +The following software packages need to be installed: |
| 8 | + |
| 9 | +- Wget |
| 10 | +- cURL |
| 11 | +- bash-completion (optional but recomended) |
| 12 | + |
| 13 | +- for yum based systems do the following: |
| 14 | + |
| 15 | +```bash |
| 16 | +sudo yum install curl wget bash-completion |
| 17 | +``` |
| 18 | + |
| 19 | +- for dnf based systems do the following: |
| 20 | + |
| 21 | +```bash |
| 22 | +sudo dnf install curl wget bash-completion |
| 23 | +``` |
| 24 | + |
| 25 | +- for apt-get based systems do the following: |
| 26 | + |
| 27 | +```bash |
| 28 | +sudo apt-get install curl wget bash-completion |
| 29 | +``` |
| 30 | + |
| 31 | +## Debugging |
| 32 | + |
| 33 | +If you find yourself wondering why stuff is not working the way you expect: |
| 34 | + |
| 35 | +- Check the logs, I suggest you `tail -f /opt/factorio/factorio-current.log` in a separate session |
| 36 | +- Enable debugging in the config and/or: |
| 37 | +- Try running the same commands as the factorio user (`/opt/factorio-init/factorio invocation` will tell you what the factorio user tries to run at start) |
13 | 38 |
|
14 | 39 | ```bash |
15 | | - $ /opt/factorio-init/factorio invocation |
| 40 | + /opt/factorio-init/factorio invocation |
16 | 41 | # Run this as the factorio user, example: |
17 | | - $ sudo -u factorio 'whatever invocation gave you' |
| 42 | + sudo -u factorio 'whatever invocation gave you' |
18 | 43 | # You should see some output in your terminal here, hopefully giving |
19 | 44 | # you a hint of what is going wrong |
20 | 45 | ``` |
21 | 46 |
|
22 | | -# Install |
| 47 | +## Install |
| 48 | + |
23 | 49 | - Create a directory where you want to store this script along with configuration. (either copy-paste the files or clone from github): |
24 | 50 |
|
25 | 51 | ```bash |
26 | | - $ cd '/opt' |
27 | | - $ git clone https://github.com/Bisa/factorio-init.git |
| 52 | + cd '/opt' |
| 53 | + git clone https://github.com/Bisa/factorio-init.git |
28 | 54 | ``` |
29 | | -- Rename config.example to config and modify the values within according to your setup. |
30 | 55 |
|
31 | | -## Notes for users with an OS that has a older glibc version: |
| 56 | +- Rename or copy `config.example` to `config` and modify the values within according to your setup. |
| 57 | + |
| 58 | +- Unless you need files from the `extras` dir (check the below sections) you can safely remove it. |
| 59 | + |
| 60 | +### Notes for users with an OS that has a older glibc version |
32 | 61 |
|
33 | | -- The config has options for declaring a 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 ) here: |
34 | | -https://forums.factorio.com/viewtopic.php?t=54654#p324493 |
| 62 | +The config has options for declaring an alternate glibc root. The user millisa over on the factorio forums has created a wonderful [guide](https://forums.factorio.com/viewtopic.php?t=54654#p324493) to follow on creating this alternate glibc root (side by side). |
| 63 | + |
| 64 | +### First-run |
35 | 65 |
|
36 | | -## First-run |
37 | 66 | - If you don't have Factorio installed already, use the `install` command: |
38 | 67 |
|
39 | 68 | ```bash |
40 | | - $ /opt/factorio-init/factorio install # see help for options |
| 69 | + /opt/factorio-init/factorio install # see help for options |
41 | 70 | ``` |
42 | 71 |
|
43 | 72 | - The installation routine creates Factorio's `config.ini` automatically. |
44 | 73 |
|
45 | 74 | - If you previously ran Factorio without this script, the existing `config.ini` should work fine. |
46 | 75 |
|
47 | | -## Autocompletion |
48 | | -- Copy/Symlink or source the bash_autocompletion file |
| 76 | +### Autocompletion |
49 | 77 |
|
50 | | - ```bash |
51 | | - $ ln -s /opt/factorio-init/bash_autocomplete /etc/bash_completion.d/factorio |
52 | | - # OR: |
53 | | - $ echo "source /opt/factorio-init/bash_autocomplete" >> ~/.bashrc |
54 | | - # restart your shell to verify that it worked |
55 | | - ``` |
| 78 | +- Copy/symlink or source the bash_autocompletion file |
| 79 | +- Ensure the factorio script is in your path |
| 80 | + |
| 81 | +```bash |
| 82 | +# either symlink: |
| 83 | +ln -s /opt/factorio-init/extras/bash_autocomplete /etc/bash_completion.d/factorio |
| 84 | +# or source: |
| 85 | +echo "source /opt/factorio-init/extras/bash_autocomplete" >> ~/.bashrc |
| 86 | + |
| 87 | +# then ensure factorio-init is added to your PATH, ie by: |
| 88 | +ln -s /opt/factorio-init/factorio /usr/local/bin/factorio |
| 89 | + |
| 90 | +# restart your shell to verify that it worked |
| 91 | +``` |
| 92 | + |
| 93 | +### Systemd |
56 | 94 |
|
57 | | -## Systemd |
58 | 95 | - Copy the example service, adjust & reload |
59 | 96 |
|
60 | | - ```bash |
61 | | - $ cp /opt/factorio-init/factorio.service.example /etc/systemd/system/factorio.service |
62 | | - # Edit the service file to suit your environment then reload systemd |
63 | | - $ systemctl daemon-reload |
64 | | - ``` |
| 97 | +```bash |
| 98 | +cp /opt/factorio-init/extras/factorio.service.example /etc/systemd/system/factorio.service |
| 99 | +# Edit the service file to suit your environment then reload systemd |
| 100 | +systemctl daemon-reload |
| 101 | +``` |
65 | 102 |
|
66 | 103 | - Verify that the server starts |
67 | 104 |
|
68 | | - ```bash |
69 | | - $ systemctl start factorio |
70 | | - $ systemctl status -l factorio |
71 | | - # Remember to enable the service at startup if you want that: |
72 | | - $ systemctl enable factorio |
73 | | - ``` |
| 105 | +```bash |
| 106 | +systemctl start factorio |
| 107 | +systemctl status -l factorio |
| 108 | +# Remember to enable the service at startup if you want that: |
| 109 | +systemctl enable factorio |
| 110 | +``` |
| 111 | + |
| 112 | +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. |
| 113 | + |
| 114 | +### SysvInit |
74 | 115 |
|
75 | | -## SysvInit |
76 | 116 | - Symlink the init script: |
77 | 117 |
|
78 | | - ```bash |
79 | | - $ ln -s /opt/factorio-init/factorio /etc/init.d/factorio |
80 | | - # Make the script executable: |
81 | | - $ chmod +x /opt/factorio-init/factorio |
82 | | - # Try it out: |
83 | | - $ service factorio help |
84 | | - # Do not forget to enable the service at boot if you want that. |
85 | | - ``` |
| 118 | +```bash |
| 119 | +ln -s /opt/factorio-init/factorio /etc/init.d/factorio |
| 120 | +# Make the script executable: |
| 121 | +chmod +x /opt/factorio-init/factorio |
| 122 | +# Try it out: |
| 123 | +service factorio help |
| 124 | +# Do not forget to enable the service at boot if you want that. |
| 125 | +``` |
| 126 | + |
| 127 | +## Contributing |
| 128 | + |
| 129 | +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. |
| 130 | + |
| 131 | +### Test the code |
| 132 | + |
| 133 | +Testing is done using [bats-core](https://github.com/bats-core/bats-core), [bats-assert](https://github.com/ztombol/bats-assert) and [bats-support](https://github.com/ztombol/bats-support). |
| 134 | + |
| 135 | +- Write a test case, example: |
| 136 | + |
| 137 | +```bash |
| 138 | +@test "DEBUG=1 produces output" { |
| 139 | + # To access functions within ./factorio, source it then use the run command: |
| 140 | + source ./factorio |
| 141 | + export DEBUG=1 |
| 142 | + run debug "TEST" |
| 143 | + # use the various asserts from bats-assert |
| 144 | + assert_output "DEBUG: TEST" |
| 145 | +} |
| 146 | +``` |
| 147 | + |
| 148 | +- init and update the submodules (if you did not already) |
| 149 | + |
| 150 | +```bash |
| 151 | +git submodule init |
| 152 | +git submodule update |
| 153 | +``` |
| 154 | + |
| 155 | +- Then run the tests, see the following sections: |
| 156 | + |
| 157 | +#### With .githooks |
| 158 | + |
| 159 | +- Set the hooks path to our .githooks directory |
| 160 | + |
| 161 | +```bash |
| 162 | +git config --local core.hooksPath extras/.githooks |
| 163 | +``` |
| 164 | + |
| 165 | +The ```extras/.githooks/pre-commit``` will run shellcheck, local tests as well as docker tests with and without resources. |
| 166 | + |
| 167 | +#### With Docker |
| 168 | + |
| 169 | +- Build the docker image(s) (a slightly modified ubuntu/centos) |
| 170 | + |
| 171 | +```bash |
| 172 | +docker build --build-arg ubuntu_version=20.04 \ |
| 173 | + --build-arg factorio_version=1.1.30 \ |
| 174 | + --tag ubuntu-finit:latest - < extras/docker/Dockerfile.ubuntu |
| 175 | +docker build --build-arg centos_version=centos8 \ |
| 176 | + --build-arg factorio_version=1.1.30 \ |
| 177 | + --tag centos-finit:latest - < extras/docker/Dockerfile.centos |
| 178 | +``` |
| 179 | + |
| 180 | +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(!) |
| 181 | + |
| 182 | +- Then run the image, mounting the current directory and removing the container once it's done |
| 183 | + |
| 184 | +```bash |
| 185 | +docker run -it --rm -v "$(pwd):/opt/factorio-init" --workdir /opt/factorio-init ubuntu-finit:latest extras/test |
| 186 | +docker run -it --rm -v "$(pwd):/opt/factorio-init" --workdir /opt/factorio-init centos-finit:latest extras/test |
| 187 | +``` |
| 188 | + |
| 189 | +#### Manually |
| 190 | + |
| 191 | +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. |
| 192 | + |
| 193 | +- run the tests |
| 194 | + |
| 195 | +```bash |
| 196 | +./extras/test/libs/bats-core/bin/bats test |
| 197 | +``` |
| 198 | + |
| 199 | +Using [parallel](https://www.gnu.org/software/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. |
| 200 | + |
| 201 | +## Thank You |
86 | 202 |
|
87 | | -# Thank You |
88 | 203 | - To all who find this script useful in one way or the other |
89 | | -- A big thank you to [Wube](https://www.factorio.com/team) for making [Factorio](https://www.factorio.com/) |
| 204 | +- A big thank you to [Wube](https://www.factorio.com/game/about) for making [Factorio](https://www.factorio.com/) |
90 | 205 | - A special thanks to NoPantsMcDance, Oxyd, HanziQ, TheFactorioCube and all other frequent users of the [#factorio](irc://irc.esper.net/#factorio) channel @ esper.net |
91 | 206 | - Thank you to Salzig for pointing me in the right direction when it comes to input redirection |
92 | 207 | - At last, but not least; Thank you to all [contributors](https://github.com/Bisa/factorio-init/graphs/contributors) and users posting [issues](https://github.com/Bisa/factorio-init/issues) in my [github](https://github.com/Bisa/factorio-init/) project or on the [factorio forums](https://forums.factorio.com/viewtopic.php?f=133&t=13874) |
93 | 208 |
|
94 | 209 | You are all a great source of motivation, thank you. |
95 | 210 |
|
96 | | -# License |
| 211 | +## License |
| 212 | + |
97 | 213 | This code is realeased with the MIT license, see the LICENSE file. |
0 commit comments