forked from Plemya-x/ALR
wip
This commit is contained in:
133
internal.go
Normal file
133
internal.go
Normal file
@ -0,0 +1,133 @@
|
||||
// ALR - Any Linux Repository
|
||||
// Copyright (C) 2025 Евгений Храмов
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"os"
|
||||
"syscall"
|
||||
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/go-plugin"
|
||||
"github.com/leonelquinteros/gotext"
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/config"
|
||||
database "gitea.plemya-x.ru/Plemya-x/ALR/internal/db"
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/logger"
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/utils"
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/build"
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/manager"
|
||||
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/repos"
|
||||
)
|
||||
|
||||
func InternalBuildCmd() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "_internal-safe-script-executor",
|
||||
HideHelp: true,
|
||||
Hidden: true,
|
||||
Action: func(c *cli.Context) error {
|
||||
logger.SetupForGoPlugin()
|
||||
err := utils.DropCapsToAlrUser()
|
||||
if err != nil {
|
||||
slog.Error("aa", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
slog.Info("",
|
||||
"uid", os.Getuid(),
|
||||
"gid", os.Getgid(),
|
||||
)
|
||||
cfg := config.New()
|
||||
err = cfg.Load()
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error loading config"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logger := hclog.New(&hclog.LoggerOptions{
|
||||
Name: "plugin",
|
||||
Output: os.Stderr,
|
||||
Level: hclog.Debug,
|
||||
JSONFormat: false,
|
||||
DisableTime: true,
|
||||
})
|
||||
plugin.Serve(&plugin.ServeConfig{
|
||||
HandshakeConfig: build.HandshakeConfig,
|
||||
Plugins: map[string]plugin.Plugin{
|
||||
"script-executor": &build.ScriptExecutorPlugin{
|
||||
Impl: build.NewLocalScriptExecutor(cfg),
|
||||
},
|
||||
},
|
||||
Logger: logger,
|
||||
})
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func InternalInstallCmd() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "_internal-installer",
|
||||
HideHelp: true,
|
||||
Hidden: true,
|
||||
Action: func(c *cli.Context) error {
|
||||
logger.SetupForGoPlugin()
|
||||
err := syscall.Setuid(0)
|
||||
if err != nil {
|
||||
slog.Error("err")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
cfg := config.New()
|
||||
err = cfg.Load()
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error loading config"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
db := database.New(cfg)
|
||||
rs := repos.New(cfg, db)
|
||||
err = db.Init(c.Context)
|
||||
if err != nil {
|
||||
slog.Error(gotext.Get("Error initialization database"), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logger := hclog.New(&hclog.LoggerOptions{
|
||||
Name: "plugin",
|
||||
Output: os.Stderr,
|
||||
Level: hclog.Trace,
|
||||
JSONFormat: true,
|
||||
DisableTime: true,
|
||||
})
|
||||
|
||||
plugin.Serve(&plugin.ServeConfig{
|
||||
HandshakeConfig: build.HandshakeConfig,
|
||||
Plugins: map[string]plugin.Plugin{
|
||||
"installer": &build.InstallerPlugin{
|
||||
Impl: build.NewInstaller(
|
||||
rs,
|
||||
manager.Detect(),
|
||||
),
|
||||
},
|
||||
},
|
||||
Logger: logger,
|
||||
})
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user