Compare commits
5 Commits
8fb2c2aeb2
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7aa0793075 | |||
| 6ef8f280a8 | |||
| 783008bfb6 | |||
| cf71d956d2 | |||
| bb65f409b4 |
91
README.md
Normal file
91
README.md
Normal 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
|
||||
|
||||
@@ -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
|
||||
|
||||
BIN
factoryman
BIN
factoryman
Binary file not shown.
2
main.go
2
main.go
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user