opengist/opengist.go

72 lines
1.8 KiB
Go
Raw Normal View History

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"
"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 {
log.Warn().Msg("Git version may be too old, as Opengist has not been tested prior git version 2.20. " +
"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-02 22:30:57 +00:00
if err := db.Setup(filepath.Join(homePath, config.C.DBFilename)); err != nil {
2023-03-14 15:22:52 +00:00
log.Fatal().Err(err).Msg("Failed to initialize database")
}
if err := memdb.Setup(); err != nil {
log.Fatal().Err(err).Msg("Failed to initialize in memory database")
}
2023-03-14 15:22:52 +00:00
}
func main() {
initialize()
go web.Start()
go ssh.Start()
select {}
}