Compare commits

...

5 Commits

Author SHA1 Message Date
7aa0793075 Merge pull request 'Added README' (#2) from develop into main
Reviewed-on: #2
2026-05-04 16:05:49 +00:00
6ef8f280a8 Added README 2026-05-04 10:02:18 -06:00
783008bfb6 Merge pull request 'Added Mod and server downloader' (#1) from develop into main
Reviewed-on: #1
2026-05-04 13:47:15 +00:00
cf71d956d2 Minor changes
Spelling error
modified headlessQuery string removing Sprint
2026-05-04 07:35:57 -06:00
bb65f409b4 Better way to download and extract server 2026-05-03 14:25:45 -06:00
5 changed files with 125 additions and 24 deletions

91
README.md Normal file
View File

@@ -0,0 +1,91 @@
# FactoryMan
A simple Factorio server manager for linux systems.
* Download and install headless factorio server (requires api key)
* Download and install mods directly from mod-list.json
* Start and stop factorio in a screen session, great for remote servers
* Backup saves and server
### Commands
```shell
$> ./factoryman download server
```
Run this command to download factorio-headless_linux_latest.
It will install to path in serverFolder in ``config.yml``
*NOTE: username and apitoken are required in ``config.yml``>factoryman*
---
```shell
$> ./factoryman download mod
```
Run this to download mods directly from ``$serverFolder/mods/mod-list.json``
*NOTE: username and apitoken are required in ``config.yml``>factoryman*
---
```shell
$> ./factoryman start
```
Start factorio server (in screen session by default)
---
```shell
$> ./factoryman stop
```
Stop factorio server (in screen session)
---
```shell
$> ./factoryman backup saves
```
Backup saves to path in ``config.yml``>factoryman>backupDir
---
```shell
$> ./factoryman backup full
```
Backup Full serverDir to backupDir
---
*Note:*
use ``$> screen -LS`` to view server terminal
### Simple Config
```config.yml```
```yaml
server:
serverFolder: "factorio"
worldFile: ""
serverSettings: "factorio/data/server-settings.json"
serverExec: "factorio/bin/x64/factorio"
port: 34197
factoryman:
screen: True
screenName: "Factorio"
backupDir: "factorio/backups"
username: ""
apitoken: ""
```
Default config assumes you have used factoryman to download the server

View File

@@ -1,6 +1,6 @@
server:
serverFolder: "factorio"
worldFile: "factorio/saves/test.zip"
worldFile: ""
serverSettings: "factorio/data/server-settings.json"
serverExec: "factorio/bin/x64/factorio"
port: 34197

Binary file not shown.

View File

@@ -7,7 +7,7 @@ import (
func main() {
if len(os.Args) == 1 {
fmt.Println("Use 'start', 'stop', or 'backup' command\nex. factoryman start\nTo configure edit 'conifg.yml'")
fmt.Println("Use 'start', 'stop', or 'backup' command\nex. factoryman start\nTo configure edit 'config.yml'")
} else {
cliToolMode()
}

View File

@@ -1,35 +1,45 @@
package main
import (
"fmt"
"archive/tar"
"io"
"log"
"net/http"
"os"
"os/exec"
"path/filepath"
"github.com/therootcompany/xz"
)
func downloadHeadless() {
var c = readCfg("config.yml")
headlessQuery := fmt.Sprintf("https://www.factorio.com/get-download/latest/headless/linux64?username=%s&token=%s", c.Factoryman.UserName, c.Factoryman.ApiToken)
headlessQuery := "https://www.factorio.com/get-download/latest/headless/linux64"
dlerr := download("./factorio.tar.xz", headlessQuery)
if dlerr != nil {
log.Fatalf("Unable to download: %v", dlerr)
url := headlessQuery
resp, err := http.Get(url)
if err != nil || resp.StatusCode != http.StatusOK {
log.Fatal("Download failed")
}
defer resp.Body.Close()
// Wrap stream in XZ and Tar readers
xzReader, _ := xz.NewReader(resp.Body, 0)
tr := tar.NewReader(xzReader)
for {
header, err := tr.Next()
if err == io.EOF {
break
}
err := os.MkdirAll(c.Server.ServDir, os.ModePerm)
if err != nil {
fmt.Printf("Error creating directory: %v\n", err)
return
target := filepath.Join(".", header.Name)
switch header.Typeflag {
case tar.TypeDir:
os.MkdirAll(target, 0755)
case tar.TypeReg:
os.MkdirAll(filepath.Dir(target), 0755)
outFile, _ := os.Create(target)
io.Copy(outFile, tr)
outFile.Close()
}
fmt.Println("tar", "-xf", "factorio.tar.xz", "-C", c.Server.ServDir+"/")
cmd := exec.Command("tar", "-xf", "factorio.tar.xz", "-C")
// 2. Run and capture Standard Output
out, err := cmd.Output()
if err != nil {
log.Fatal(err)
}
fmt.Println(err)
fmt.Println(string(out))
}