2023-03-14 15:22:52 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2023-03-24 13:41:08 +00:00
|
|
|
"fmt"
|
2023-03-14 15:22:52 +00:00
|
|
|
"github.com/rs/zerolog/log"
|
2023-05-15 19:07:29 +00:00
|
|
|
"github.com/thomiceli/opengist/internal/config"
|
2023-09-02 22:30:57 +00:00
|
|
|
"github.com/thomiceli/opengist/internal/db"
|
2023-05-15 19:07:29 +00:00
|
|
|
"github.com/thomiceli/opengist/internal/git"
|
2024-01-04 02:38:15 +00:00
|
|
|
"github.com/thomiceli/opengist/internal/index"
|
2023-09-09 17:39:57 +00:00
|
|
|
"github.com/thomiceli/opengist/internal/memdb"
|
2023-05-15 19:07:29 +00:00
|
|
|
"github.com/thomiceli/opengist/internal/ssh"
|
|
|
|
"github.com/thomiceli/opengist/internal/web"
|
2023-03-14 15:22:52 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
)
|
|
|
|
|
|
|
|
func initialize() {
|
2023-04-06 23:52:56 +00:00
|
|
|
fmt.Println("Opengist v" + config.OpengistVersion)
|
|
|
|
|
2023-04-07 21:58:06 +00:00
|
|
|
configPath := flag.String("config", "", "Path to a config file in YML format")
|
2023-03-14 15:22:52 +00:00
|
|
|
flag.Parse()
|
2023-04-07 21:58:06 +00:00
|
|
|
|
|
|
|
if err := config.InitConfig(*configPath); err != nil {
|
2023-03-14 15:22:52 +00:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
if err := os.MkdirAll(filepath.Join(config.GetHomeDir()), 0755); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
config.InitLog()
|
|
|
|
|
2023-03-24 13:41:08 +00:00
|
|
|
gitVersion, err := git.GetGitVersion()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal().Err(err).Send()
|
|
|
|
}
|
|
|
|
|
|
|
|
if ok, err := config.CheckGitVersion(gitVersion); err != nil {
|
|
|
|
log.Fatal().Err(err).Send()
|
|
|
|
} else if !ok {
|
2023-12-27 16:30:42 +00:00
|
|
|
log.Warn().Msg("Git version may be too old, as Opengist has not been tested prior git version 2.28 and some features would not work. " +
|
2023-03-24 13:41:08 +00:00
|
|
|
"Current git version: " + gitVersion)
|
|
|
|
}
|
2023-03-14 15:22:52 +00:00
|
|
|
|
|
|
|
homePath := config.GetHomeDir()
|
|
|
|
log.Info().Msg("Data directory: " + homePath)
|
|
|
|
|
|
|
|
if err := os.MkdirAll(filepath.Join(homePath, "repos"), 0755); err != nil {
|
|
|
|
log.Fatal().Err(err).Send()
|
|
|
|
}
|
|
|
|
if err := os.MkdirAll(filepath.Join(homePath, "tmp", "repos"), 0755); err != nil {
|
|
|
|
log.Fatal().Err(err).Send()
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info().Msg("Database file: " + filepath.Join(homePath, config.C.DBFilename))
|
2023-09-16 22:59:47 +00:00
|
|
|
if err := db.Setup(filepath.Join(homePath, config.C.DBFilename), false); err != nil {
|
2023-03-14 15:22:52 +00:00
|
|
|
log.Fatal().Err(err).Msg("Failed to initialize database")
|
|
|
|
}
|
2023-09-09 17:39:57 +00:00
|
|
|
|
|
|
|
if err := memdb.Setup(); err != nil {
|
|
|
|
log.Fatal().Err(err).Msg("Failed to initialize in memory database")
|
|
|
|
}
|
2024-01-04 02:38:15 +00:00
|
|
|
|
|
|
|
if config.C.IndexEnabled {
|
|
|
|
log.Info().Msg("Index directory: " + filepath.Join(homePath, config.C.IndexDirname))
|
|
|
|
if err := index.Open(filepath.Join(homePath, config.C.IndexDirname)); err != nil {
|
|
|
|
log.Fatal().Err(err).Msg("Failed to open index")
|
|
|
|
}
|
|
|
|
}
|
2023-03-14 15:22:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
initialize()
|
|
|
|
|
2023-09-16 22:59:47 +00:00
|
|
|
go web.NewServer(os.Getenv("OG_DEV") == "1").Start()
|
2023-03-14 15:22:52 +00:00
|
|
|
go ssh.Start()
|
|
|
|
|
|
|
|
select {}
|
|
|
|
}
|