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"
|
2014-02-25 20:11:34 +01:00
|
|
|
"os"
|
2014-03-02 06:51:52 +01:00
|
|
|
"path/filepath"
|
2014-02-08 22:18:11 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2014-03-06 08:51:32 +01:00
|
|
|
conf := flag.String("conf", "ergonomadic.conf", "ergonomadic config file")
|
2014-02-25 20:11:34 +01:00
|
|
|
initdb := flag.Bool("initdb", false, "initialize database")
|
2014-03-08 03:14:02 +01:00
|
|
|
upgradedb := flag.Bool("upgradedb", false, "update database")
|
2014-02-24 07:21:39 +01:00
|
|
|
passwd := flag.String("genpasswd", "", "bcrypt a password")
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if *passwd != "" {
|
2014-03-02 00:10:04 +01:00
|
|
|
encoded, err := irc.GenerateEncodedPassword(*passwd)
|
|
|
|
if err != nil {
|
2014-03-06 08:07:55 +01:00
|
|
|
log.Fatal("encoding error: ", err)
|
2014-03-02 00:10:04 +01:00
|
|
|
}
|
|
|
|
fmt.Println(encoded)
|
2014-02-24 07:21:39 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
config, err := irc.LoadConfig(*conf)
|
2014-02-09 16:53:42 +01:00
|
|
|
if err != nil {
|
2014-03-06 08:07:55 +01:00
|
|
|
log.Fatal("error loading config: ", err)
|
2014-02-25 20:11:34 +01:00
|
|
|
}
|
2014-03-02 06:51:52 +01:00
|
|
|
err = os.Chdir(filepath.Dir(*conf))
|
|
|
|
if err != nil {
|
2014-03-06 08:07:55 +01:00
|
|
|
log.Fatal("chdir error: ", err)
|
2014-03-02 06:51:52 +01:00
|
|
|
}
|
2014-02-25 20:11:34 +01:00
|
|
|
|
|
|
|
if *initdb {
|
2014-03-02 20:41:24 +01:00
|
|
|
irc.InitDB(config.Server.Database)
|
2014-03-08 03:14:02 +01:00
|
|
|
log.Println("database initialized: ", config.Server.Database)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if *upgradedb {
|
|
|
|
irc.UpgradeDB(config.Server.Database)
|
|
|
|
log.Println("database upgraded: ", config.Server.Database)
|
2014-02-09 16:53:42 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-03-09 00:01:15 +01:00
|
|
|
irc.Log.SetLevel(config.Server.Log)
|
2014-03-08 20:59:34 +01:00
|
|
|
server := irc.NewServer(config)
|
2014-03-06 20:56:32 +01:00
|
|
|
log.Println(irc.SEM_VER, "running")
|
2014-03-08 20:59:34 +01:00
|
|
|
defer log.Println(irc.SEM_VER, "exiting")
|
|
|
|
server.Run()
|
2014-02-08 22:18:11 +01:00
|
|
|
}
|