3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-23 03:02:48 +01:00
ergo/ergonomadic.go

82 lines
1.9 KiB
Go
Raw Normal View History

2014-02-08 22:18:11 +01:00
package main
import (
2014-02-24 07:21:39 +01:00
"flag"
"fmt"
2014-02-08 22:18:11 +01:00
"github.com/jlatt/ergonomadic/irc"
2014-02-09 16:53:42 +01:00
"log"
"os"
"path/filepath"
2014-02-08 22:18:11 +01:00
)
2014-03-13 02:57:00 +01:00
func usage() {
fmt.Fprintln(os.Stderr, "ergonomadic <run|genpasswd|initdb|upgradedb> [options]")
fmt.Fprintln(os.Stderr, " run -conf <config> -- run server")
fmt.Fprintln(os.Stderr, " initdb -conf <config> -- initialize database")
fmt.Fprintln(os.Stderr, " upgrade -conf <config> -- upgrade database")
fmt.Fprintln(os.Stderr, " genpasswd <password> -- bcrypt a password")
2014-03-22 07:24:33 +01:00
fmt.Fprintln(os.Stderr)
fmt.Fprintln(os.Stderr, "software version:", irc.SEM_VER)
2014-03-13 02:57:00 +01:00
flag.PrintDefaults()
}
func loadConfig(conf string) *irc.Config {
config, err := irc.LoadConfig(conf)
if err != nil {
log.Fatalln("error loading config:", err)
}
err = os.Chdir(filepath.Dir(conf))
if err != nil {
log.Fatalln("chdir error:", err)
}
return config
}
func genPasswd() {
}
2014-02-08 22:18:11 +01:00
func main() {
2014-03-13 02:57:00 +01:00
var conf string
flag.Usage = usage
runFlags := flag.NewFlagSet("run", flag.ExitOnError)
runFlags.Usage = usage
runFlags.StringVar(&conf, "conf", "ergonomadic.conf", "ergonomadic config file")
2014-02-24 07:21:39 +01:00
flag.Parse()
2014-03-13 02:57:00 +01:00
switch flag.Arg(0) {
case "genpasswd":
encoded, err := irc.GenerateEncodedPassword(flag.Arg(1))
if err != nil {
2014-03-13 02:57:00 +01:00
log.Fatalln("encoding error:", err)
}
fmt.Println(encoded)
2014-02-24 07:21:39 +01:00
2014-03-13 02:57:00 +01:00
case "initdb":
runFlags.Parse(flag.Args()[1:])
config := loadConfig(conf)
irc.InitDB(config.Server.Database)
2014-03-08 03:14:02 +01:00
log.Println("database initialized: ", config.Server.Database)
2014-03-13 02:57:00 +01:00
case "upgradedb":
runFlags.Parse(flag.Args()[1:])
config := loadConfig(conf)
2014-03-08 03:14:02 +01:00
irc.UpgradeDB(config.Server.Database)
log.Println("database upgraded: ", config.Server.Database)
2014-02-09 16:53:42 +01:00
2014-03-15 20:47:05 +01:00
case "run":
2014-03-13 02:57:00 +01:00
runFlags.Parse(flag.Args()[1:])
config := loadConfig(conf)
irc.Log.SetLevel(config.Server.Log)
server := irc.NewServer(config)
log.Println(irc.SEM_VER, "running")
defer log.Println(irc.SEM_VER, "exiting")
server.Run()
2014-03-15 20:47:05 +01:00
default:
usage()
2014-03-13 02:57:00 +01:00
}
2014-02-08 22:18:11 +01:00
}