3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-26 13:59:44 +01:00
ergo/oragono.go

122 lines
3.5 KiB
Go
Raw Normal View History

// Copyright (c) 2012-2014 Jeremy Latt
// Copyright (c) 2014-2015 Edmund Huber
// Copyright (c) 2016- Daniel Oaks <daniel@danieloaks.net>
// released under the MIT license
2014-02-08 22:18:11 +01:00
package main
import (
2014-02-24 07:21:39 +01:00
"fmt"
2014-02-09 16:53:42 +01:00
"log"
2017-01-14 10:52:47 +01:00
"math/rand"
"syscall"
2017-01-14 10:52:47 +01:00
"time"
2014-03-13 02:57:00 +01:00
"github.com/DanielOaks/oragono/irc"
"github.com/DanielOaks/oragono/irc/logger"
2016-08-12 23:40:58 +02:00
"github.com/DanielOaks/oragono/mkcerts"
"github.com/docopt/docopt-go"
"golang.org/x/crypto/ssh/terminal"
)
2014-03-13 02:57:00 +01:00
func main() {
2016-10-13 09:36:44 +02:00
version := irc.SemVer
usage := `oragono.
Usage:
2016-09-19 14:30:45 +02:00
oragono initdb [--conf <filename>] [--quiet]
oragono upgradedb [--conf <filename>] [--quiet]
oragono genpasswd [--conf <filename>] [--quiet]
oragono mkcerts [--conf <filename>] [--quiet]
oragono run [--conf <filename>] [--quiet]
oragono -h | --help
oragono --version
Options:
--conf <filename> Configuration file to use [default: ircd.yaml].
2016-09-19 14:30:45 +02:00
--quiet Don't show startup/shutdown lines.
-h --help Show this screen.
--version Show version.`
arguments, _ := docopt.Parse(usage, nil, true, version, false)
configfile := arguments["--conf"].(string)
config, err := irc.LoadConfig(configfile)
2014-03-13 02:57:00 +01:00
if err != nil {
log.Fatal("Config file did not load successfully:", err.Error())
2014-03-13 02:57:00 +01:00
}
// assemble separate log configs
var logConfigs []logger.Config
for _, lConfig := range config.Logging {
logConfigs = append(logConfigs, logger.Config{
MethodStderr: lConfig.MethodStderr,
MethodFile: lConfig.MethodFile,
Filename: lConfig.Filename,
Level: lConfig.Level,
Types: lConfig.Types,
ExcludedTypes: lConfig.ExcludedTypes,
})
}
logger, err := logger.NewManager(logConfigs...)
2017-03-06 06:50:23 +01:00
if err != nil {
log.Fatal("Logger did not load successfully:", err.Error())
}
if arguments["genpasswd"].(bool) {
fmt.Print("Enter Password: ")
bytePassword, err := terminal.ReadPassword(int(syscall.Stdin))
if err != nil {
log.Fatal("Error reading password:", err.Error())
}
password := string(bytePassword)
encoded, err := irc.GenerateEncodedPassword(password)
if err != nil {
2017-03-06 06:50:23 +01:00
log.Fatal("encoding error:", err.Error())
}
fmt.Print("\n")
fmt.Println(encoded)
} else if arguments["initdb"].(bool) {
irc.InitDB(config.Datastore.Path)
2016-09-19 14:30:45 +02:00
if !arguments["--quiet"].(bool) {
log.Println("database initialized: ", config.Datastore.Path)
}
} else if arguments["upgradedb"].(bool) {
irc.UpgradeDB(config.Datastore.Path)
2016-09-19 14:30:45 +02:00
if !arguments["--quiet"].(bool) {
log.Println("database upgraded: ", config.Datastore.Path)
}
} else if arguments["mkcerts"].(bool) {
2016-09-19 14:30:45 +02:00
if !arguments["--quiet"].(bool) {
log.Println("making self-signed certificates")
}
2016-06-15 11:31:39 +02:00
for name, conf := range config.Server.TLSListeners {
log.Printf(" making cert for %s listener\n", name)
2016-06-15 11:31:39 +02:00
host := config.Server.Name
2016-08-12 23:40:58 +02:00
err := mkcerts.CreateCert("Oragono", host, conf.Cert, conf.Key)
if err == nil {
2016-09-19 14:30:45 +02:00
if !arguments["--quiet"].(bool) {
log.Printf(" Certificate created at %s : %s\n", conf.Cert, conf.Key)
}
2016-08-12 23:40:58 +02:00
} else {
log.Fatal(" Could not create certificate:", err.Error())
2016-06-15 11:31:39 +02:00
}
}
} else if arguments["run"].(bool) {
2017-01-14 10:52:47 +01:00
rand.Seed(time.Now().UTC().UnixNano())
2017-03-06 11:15:28 +01:00
if !arguments["--quiet"].(bool) {
logger.Info("startup", fmt.Sprintf("Oragono v%s starting", irc.SemVer))
2017-03-06 11:15:28 +01:00
}
2017-03-06 06:50:23 +01:00
server, err := irc.NewServer(configfile, config, logger)
if err != nil {
logger.Error("startup", fmt.Sprintf("Could not load server: %s", err.Error()))
return
}
2016-09-19 14:30:45 +02:00
if !arguments["--quiet"].(bool) {
logger.Info("startup", "Server running")
defer logger.Info("shutdown", fmt.Sprintf("Oragono v%s exiting", irc.SemVer))
2016-09-19 14:30:45 +02:00
}
2014-03-13 02:57:00 +01:00
server.Run()
}
2014-02-08 22:18:11 +01:00
}