1
0
Fork 0
mirror of https://github.com/thomiceli/opengist.git synced 2025-01-24 07:00:32 +00:00
opengist/opengist.go

69 lines
1.6 KiB
Go
Raw Normal View History

2023-03-14 16:22:52 +01:00
package main
import (
"flag"
2023-03-24 14:41:08 +01:00
"fmt"
2023-03-14 16:22:52 +01:00
"github.com/rs/zerolog/log"
2023-05-15 21:07:29 +02:00
"github.com/thomiceli/opengist/internal/config"
"github.com/thomiceli/opengist/internal/git"
"github.com/thomiceli/opengist/internal/models"
"github.com/thomiceli/opengist/internal/ssh"
"github.com/thomiceli/opengist/internal/web"
2023-03-14 16:22:52 +01:00
"os"
"path/filepath"
)
func initialize() {
2023-04-07 01:52:56 +02:00
fmt.Println("Opengist v" + config.OpengistVersion)
2023-04-07 23:58:06 +02:00
configPath := flag.String("config", "", "Path to a config file in YML format")
2023-03-14 16:22:52 +01:00
flag.Parse()
2023-04-07 23:58:06 +02:00
if err := config.InitConfig(*configPath); err != nil {
2023-03-14 16:22:52 +01:00
panic(err)
}
if err := os.MkdirAll(filepath.Join(config.GetHomeDir()), 0755); err != nil {
panic(err)
}
config.InitLog()
2023-03-24 14:41:08 +01: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 16:22:52 +01: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))
if err := models.Setup(filepath.Join(homePath, config.C.DBFilename)); err != nil {
log.Fatal().Err(err).Msg("Failed to initialize database")
}
2023-03-24 14:41:08 +01:00
2023-04-06 11:47:30 +02:00
web.EmbedFS = dirFS
2023-03-14 16:22:52 +01:00
}
func main() {
initialize()
go web.Start()
go ssh.Start()
select {}
}