summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Makefile38
-rw-r--r--cache.go10
-rw-r--r--etc/getwtxt.service14
-rw-r--r--etc/revive.toml (renamed from revive.toml)0
-rw-r--r--getwtxt.yml2
-rw-r--r--init.go33
-rw-r--r--main.go1
-rw-r--r--types.go1
8 files changed, 89 insertions, 10 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..b6c522c
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,38 @@
+PREFIX?=/usr/local
+_INSTDIR=$(PREFIX)
+BINDIR?=$(_INSTDIR)/getwtxt
+GOFLAGS?=
+
+GOSRC!=find . -name '*.go'
+GOSRC+=go.mod go.sum
+
+getwtxt: $(GOSRC)
+	go build $(GOFLAGS) \
+		-o $@
+
+RM?=rm -f
+
+clean:
+	$(RM) getwtxt
+
+update:
+	git pull --rebase
+
+install:
+	adduser -home $(BINDIR) --system --group getwtxt
+	mkdir -p $(BINDIR)/assets/tmpl $(BINDIR)/docs
+	install -m755 getwtxt $(BINDIR)
+	install -m644 getwtxt.yml $(BINDIR)
+	install -m644 assets/style.css $(BINDIR)/assets
+	install -m644 assets/tmpl/index.html $(BINDIR)/assets/tmpl
+	install -m644 README.md $(BINDIR)/docs
+	install -m644 LICENSE $(BINDIR)/docs
+	install -m644 etc/getwtxt.service /etc/systemd/system
+	chown -R getwtxt:getwtxt $(BINDIR)
+
+uninstall:
+	systemctl stop getwtxt >/dev/null 2>&1
+	systemctl disable getwtxt >/dev/null 2>&1
+	rm -rf $(BINDIR)
+	rm -f /etc/systemd/system/getwtxt.service
+	userdel getwtxt
diff --git a/cache.go b/cache.go
index 2db0fbb..882c4d8 100644
--- a/cache.go
+++ b/cache.go
@@ -67,12 +67,16 @@ func refreshCache() {
 // pulled back into memory from disk.
 func pingAssets() {
 
-	cssStat, err := os.Stat("assets/style.css")
+	confObj.Mu.RLock()
+	assetsDir := confObj.AssetsDir
+	confObj.Mu.RUnlock()
+
+	cssStat, err := os.Stat(assetsDir + "/style.css")
 	if err != nil {
 		log.Printf("%v\n", err.Error())
 	}
 
-	indexStat, err := os.Stat("assets/tmpl/index.html")
+	indexStat, err := os.Stat(assetsDir + "/tmpl/index.html")
 	if err != nil {
 		log.Printf("%v\n", err.Error())
 	}
@@ -99,7 +103,7 @@ func pingAssets() {
 
 	if !cssMod.Equal(cssStat.ModTime()) {
 
-		css, err := ioutil.ReadFile("assets/style.css")
+		css, err := ioutil.ReadFile(assetsDir + "/style.css")
 		if err != nil {
 			log.Printf("%v\n", err.Error())
 		}
diff --git a/etc/getwtxt.service b/etc/getwtxt.service
new file mode 100644
index 0000000..0d541ff
--- /dev/null
+++ b/etc/getwtxt.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=getwtxt
+
+[Service]
+Type=simple
+ExecStart=/usr/local/getwtxt/getwtxt \
+          --assets /usr/local/getwtxt/assets \
+          --config /usr/local/getwtxt/getwtxt.yml \
+          --db /usr/local/getwtxt/getwtxt.db \
+          --dbtype leveldb
+Restart=always
+
+[Install]
+WantedBy=multi-user.target
diff --git a/revive.toml b/etc/revive.toml
index f9e2405..f9e2405 100644
--- a/revive.toml
+++ b/etc/revive.toml
diff --git a/getwtxt.yml b/getwtxt.yml
index 4c72454..fb05a96 100644
--- a/getwtxt.yml
+++ b/getwtxt.yml
@@ -41,7 +41,7 @@ DatabasePath: "getwtxt.db"
 # requests, to stdout. It will ignore any set log file.
 # Useful for debugging, but you probably want to keep
 # logs.
-StdoutLogging: true
+StdoutLogging: false
 
 # The file getwtxt will append log messages to. Can be a
 # relative or absolute path.
diff --git a/init.go b/init.go
index 076a7ca..18a3d96 100644
--- a/init.go
+++ b/init.go
@@ -25,6 +25,9 @@ var (
 	flagHelp     *bool   = pflag.BoolP("help", "h", false, "Display the quick-help screen.")
 	flagMan      *bool   = pflag.BoolP("manual", "m", false, "Display the configuration manual.")
 	flagConfFile *string = pflag.StringP("config", "c", "", "The name/path of the configuration file you wish to use.")
+	flagAssets   *string = pflag.StringP("assets", "a", "", "The location of the getwtxt assets directory")
+	flagDBPath   *string = pflag.StringP("db", "d", "", "Path to the getwtxt database")
+	flagDBType   *string = pflag.StringP("dbtype", "t", "", "Type of database being used")
 )
 
 var confObj = &Configuration{}
@@ -54,7 +57,7 @@ var staticCache = &struct {
 	cssMod:   time.Time{},
 }
 
-func initGetwtxt() {
+func init() {
 	checkFlags()
 	titleScreen()
 	initConfig()
@@ -122,6 +125,7 @@ func initConfig() {
 	viper.SetDefault("ListenPort", 9001)
 	viper.SetDefault("LogFile", "getwtxt.log")
 	viper.SetDefault("DatabasePath", "getwtxt.db")
+	viper.SetDefault("DatabaseType", "leveldb")
 	viper.SetDefault("StdoutLogging", false)
 	viper.SetDefault("ReCacheInterval", "1h")
 	viper.SetDefault("DatabasePushInterval", "5m")
@@ -137,9 +141,24 @@ func initConfig() {
 	confObj.Port = viper.GetInt("ListenPort")
 	confObj.LogFile = viper.GetString("LogFile")
 
-	confObj.DBType = strings.ToLower(viper.GetString("DatabaseType"))
-	confObj.DBPath = viper.GetString("DatabasePath")
-	log.Printf("Using database: %v\n", confObj.DBPath)
+	if *flagDBType == "" {
+		confObj.DBType = strings.ToLower(viper.GetString("DatabaseType"))
+	} else {
+		confObj.DBType = *flagDBType
+	}
+
+	if *flagDBPath == "" {
+		confObj.DBPath = viper.GetString("DatabasePath")
+	} else {
+		confObj.DBPath = *flagDBPath
+	}
+	log.Printf("Using %v database: %v\n", confObj.DBType, confObj.DBPath)
+
+	if *flagAssets == "" {
+		confObj.AssetsDir = "assets"
+	} else {
+		confObj.AssetsDir = *flagAssets
+	}
 
 	confObj.StdoutLogging = viper.GetBool("StdoutLogging")
 	if confObj.StdoutLogging {
@@ -233,7 +252,11 @@ func rebindConfig() {
 }
 
 func initTemplates() *template.Template {
-	return template.Must(template.ParseFiles("assets/tmpl/index.html"))
+	confObj.Mu.RLock()
+	assetsDir := confObj.AssetsDir
+	confObj.Mu.RUnlock()
+
+	return template.Must(template.ParseFiles(assetsDir + "/tmpl/index.html"))
 }
 
 // Pull DB data into cache, if available.
diff --git a/main.go b/main.go
index a3f0133..2aa8758 100644
--- a/main.go
+++ b/main.go
@@ -11,7 +11,6 @@ import (
 )
 
 func main() {
-	initGetwtxt()
 
 	// StrictSlash(true) allows /api and /api/
 	// to serve the same content without duplicating
diff --git a/types.go b/types.go
index 7e78ae0..b32edd3 100644
--- a/types.go
+++ b/types.go
@@ -20,6 +20,7 @@ type Configuration struct {
 	LogFile       string        `yaml:"LogFile"`
 	DBType        string        `yaml:"DatabaseType"`
 	DBPath        string        `yaml:"DatabasePath"`
+	AssetsDir     string        `yaml:"-"`
 	StdoutLogging bool          `yaml:"StdoutLogging"`
 	Version       string        `yaml:"-"`
 	CacheInterval time.Duration `yaml:"StatusFetchInterval"`
f='#n469'>469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674