Skip to content

Commit

Permalink
WIP Add to PostInstall;
Browse files Browse the repository at this point in the history
  • Loading branch information
Renegade-Master committed Jan 28, 2024
1 parent e25601d commit 713f863
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ jobs:
podman-compose.yaml
${{ steps.volumes.outputs.configdir }}/Server/GitHubActionTest.ini
${{ steps.volumes.outputs.configdir }}/Server/GitHubActionTest_SandboxVars.lua
ZomboidDedicatedServer/ProjectZomboid64.json
${{ steps.volumes.outputs.installdir }}/ProjectZomboid64.json
dedicated-server-install-listing.txt
dedicated-server-config-listing.txt
root-fs-listing.txt
Expand All @@ -138,7 +138,6 @@ jobs:
strategy:
matrix:
system: [ podman ]
#system: [ docker, docker-compose, podman ]
steps:
- name: Checkout Repository
uses: actions/checkout@v3
Expand Down Expand Up @@ -196,11 +195,11 @@ jobs:
- name: Test - Server JVM Configuration Applied
run: |
check_for_config() {
if ! grep -q -iE "$1" "./ZomboidDedicatedServer/ProjectZomboid64.json"; then
printf "Could not find [%s] in [%s]\n" "$1" "./ZomboidDedicatedServer/ProjectZomboid64.json"
if ! grep -q -iE "$1" "${{ steps.volumes.outputs.installdir }}/ProjectZomboid64.json"; then
printf "Could not find [%s] in [%s]\n" "$1" "${{ steps.volumes.outputs.installdir }}/ProjectZomboid64.json"
exit 1
else
printf "Found [%s] in [%s]\n" "$1" "./ZomboidDedicatedServer/ProjectZomboid64.json"
printf "Found [%s] in [%s]\n" "$1" "${{ steps.volumes.outputs.installdir }}/ProjectZomboid64.json"
fi
}
Expand All @@ -209,7 +208,7 @@ jobs:
- name: Test - Server Configuration Applied
run: |
install_directory="./ZomboidDedicatedServer"
install_directory="${{ steps.volumes.outputs.installdir }}"
workshop_directory="${install_directory}/steamapps/workshop"
mods_directory="${workshop_directory}/content/108600/522891356/mods"
bedford_maps="${mods_directory}/Bedford Falls/media/maps"
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module renegade-master/zomboid-dedicated-server
go 1.21.0

require (
github.com/buger/jsonparser v1.1.1
github.com/mitchellh/go-ps v1.0.0
gopkg.in/ini.v1 v1.67.0
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc=
Expand Down
37 changes: 32 additions & 5 deletions internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package internal

import (
"github.com/buger/jsonparser"
"github.com/mitchellh/go-ps"
"gopkg.in/ini.v1"
"log"
Expand Down Expand Up @@ -135,20 +136,46 @@ func TestFirstRun() {

func ApplyPostInstallConfig() {
log.Println("Applying PostInstall Config")
configFile := configDir + "Server/" + os.Getenv("SERVER_NAME") + ".ini"
serverConfigFile := configDir + "Server/" + os.Getenv("SERVER_NAME") + ".ini"
jvmConfigFile := baseGameDir + "ProjectZomboid64.json"
ini.PrettyFormat = false

if cfg, err := ini.Load(configFile); err != nil {
log.Fatalf("Could not open Server Config File [%s]. Error:\n%s\n", configFile, err)
if cfg, err := ini.Load(serverConfigFile); err != nil {
log.Fatalf("Could not open Server Config File [%s]. Error:\n%s\n", serverConfigFile, err)
} else {
cfg.Section("").Key("RCONPort").SetValue(os.Getenv("RCON_PORT"))
cfg.Section("").Key("RCONPassword").SetValue(os.Getenv("RCON_PASSWORD"))

if err := cfg.SaveTo(configFile); err != nil {
log.Fatalf("Could not save changes to Server Config File [%s]. Error:\n%s\n", configFile, err)
if err := cfg.SaveTo(serverConfigFile); err != nil {
log.Fatalf("Could not save changes to Server Config File [%s]. Error:\n%s\n", serverConfigFile, err)
}
}

values := map[string]string{
"-Xmx.*": "-Xmx" + os.Getenv("MAX_RAM"),
}

if file, err := os.ReadFile(jvmConfigFile); err != nil {
log.Fatalf("Could not open File [%s] for editing. Error:\n%s\n", jvmConfigFile, err)
} else {
idx := 0

if offset, err := jsonparser.ArrayEach(file, func(value []byte, dataType jsonparser.ValueType, offset int, err error) {
log.Printf("Found Key: [%s] at Index [%d] position [%d]\n", value, idx, offset)
jsonparser.Set(file)

idx++
}, "vmArgs"); err != nil {
log.Fatalf("Error encountered when Parsing JSON:\n%s\n", err)
} else {
log.Printf("Found Key at position [%d]\n", offset)
}

//if err := os.WriteFile(jvmConfigFile, newFile, 0444); err != nil {
// log.Fatalf("Could not write new content [%s] to file [%s]. Error:\n%s\n", newFile, jvmConfigFile, err)
//}
}

log.Println("PostInstall Config Applied!")
}

Expand Down

0 comments on commit 713f863

Please sign in to comment.