main.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package main
  2. import (
  3. "notabug.org/apiote/amuse/config"
  4. "notabug.org/apiote/amuse/db"
  5. "notabug.org/apiote/amuse/libamuse"
  6. "flag"
  7. "fmt"
  8. "log"
  9. "os"
  10. )
  11. func main() {
  12. port := flag.Int("p", -1, "port to run amuse on")
  13. address := flag.String("a", "", "address to run amuse on")
  14. dataHome := flag.String("d", "", "data directory")
  15. manage := flag.String("m", "", "manage command")
  16. configPath := flag.String("c", "/etc/amuse.toml", "configPath")
  17. flag.Parse()
  18. config.ReadConfig(*configPath)
  19. if *dataHome != "" {
  20. config.DataHome = *dataHome
  21. }
  22. if *port > 0 {
  23. config.Port = uint(*port)
  24. }
  25. if *address != "" {
  26. config.Address = *address
  27. }
  28. validateState()
  29. db.Migrate()
  30. switch *manage {
  31. case "makeadmin":
  32. var username string
  33. fmt.Printf("Username: ")
  34. fmt.Scanf("%s", &username)
  35. err := libamuse.MakeAdmin(username)
  36. if err != nil {
  37. os.Exit(1)
  38. } else {
  39. return
  40. }
  41. case "touch":
  42. libamuse.TouchWantlist()
  43. os.Exit(0)
  44. }
  45. route(config.Port)
  46. }
  47. func validateState() {
  48. _, err := os.Readlink(config.DataHome + "/i18n/default.toml")
  49. if err != nil {
  50. log.Println("WARN: i18n/default.toml is not a symbolic link; translations fallback will not work")
  51. }
  52. if config.TmdbApiKey == "" {
  53. log.Fatalln("ERR: TmdbApiKey not specified in config")
  54. }
  55. }