From 5a897706a36ead274cd4474cf76ac327e9d9b1ef Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Wed, 20 Nov 2019 20:58:15 +0000 Subject: [PATCH] Add first time setup nethackrc logic --- deps/Dockerfile | 2 +- nethack-launcher.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/deps/Dockerfile b/deps/Dockerfile index d48f263..e533523 100644 --- a/deps/Dockerfile +++ b/deps/Dockerfile @@ -45,7 +45,7 @@ COPY nethack-launcher / COPY redis.conf / COPY run.sh / COPY chowner.sh /bin/ -COPY nethackrc /hack/.nethackrc +COPY nethackrc /.nethackrc COPY run_nethack.sh / CMD ["/run.sh"] diff --git a/nethack-launcher.go b/nethack-launcher.go index 1191b2a..6cb99bb 100644 --- a/nethack-launcher.go +++ b/nethack-launcher.go @@ -570,6 +570,24 @@ func createInitialFiles() { if _, err := os.Stat(fmt.Sprintf("%s/nhdat", config.NethackLauncher.HackDir)); os.IsNotExist(err) { exec.Command("cp", config.NethackLauncher.NhdatLocation, config.NethackLauncher.HackDir).Run() } + + // make sure initial rcfile exists + hackRCLoc := fmt.Sprintf("%s/.nethackrc", config.NethackLauncher.HackDir) + if _, err := os.Stat(hackRCLoc); os.IsNotExist(err) { + fmt.Printf("initial config file not found at: %s\n", hackRCLoc) + fmt.Printf("%s\n", err) + + // check root and move in if applicable + if _, err := os.Stat("/.nethackrc"); os.IsNotExist(err) { + fmt.Printf("initial config file not found at root\n") + fmt.Printf("%s\n", err) + os.Exit(1) + } else { + // move nethackrc file to proper location + exec.Command("cp", "/.nethackrc", config.NethackLauncher.HackDir).Run() + } + + } } func janitor(redisClient *redis.Client) {