main.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. "os"
  9. "log"
  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. err := libamuse.TouchWantlist()
  43. if err != nil {
  44. os.Exit(1)
  45. } else {
  46. return
  47. }
  48. }
  49. route(config.Port)
  50. }
  51. func validateState() {
  52. _, err := os.Readlink(config.DataHome + "/i18n/default.toml")
  53. if err != nil {
  54. log.Println("WARN: i18n/default.toml is not a symbolic link; translations fallback will not work")
  55. }
  56. if config.TmdbApiKey == "" {
  57. log.Fatalln("ERR: TmdbApiKey not specified in config")
  58. }
  59. }