lure/pkg/build/install.go

73 lines
2.2 KiB
Go
Raw Normal View History

2023-09-20 22:38:22 +00:00
/*
* LURE - Linux User REpository
* Copyright (C) 2023 Elara Musayelyan
*
* 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/>.
*/
2023-09-19 21:28:05 +00:00
package build
import (
"context"
"path/filepath"
2023-10-08 00:34:39 +00:00
"lure.sh/lure/internal/config"
"lure.sh/lure/internal/db"
"lure.sh/lure/internal/types"
"lure.sh/lure/pkg/loggerctx"
2023-09-19 21:28:05 +00:00
)
2023-09-21 23:18:18 +00:00
// InstallPkgs installs native packages via the package manager,
// then builds and installs the LURE packages
2023-09-19 21:28:05 +00:00
func InstallPkgs(ctx context.Context, lurePkgs []db.Package, nativePkgs []string, opts types.BuildOpts) {
2023-10-06 21:21:12 +00:00
log := loggerctx.From(ctx)
2023-09-19 21:28:05 +00:00
if len(nativePkgs) > 0 {
err := opts.Manager.Install(nil, nativePkgs...)
if err != nil {
log.Fatal("Error installing native packages").Err(err).Send()
}
}
2023-10-06 21:21:12 +00:00
InstallScripts(ctx, GetScriptPaths(ctx, lurePkgs), opts)
2023-09-19 21:28:05 +00:00
}
2023-09-21 23:18:18 +00:00
// GetScriptPaths returns a slice of script paths corresponding to the
2023-09-19 21:28:05 +00:00
// given packages
2023-10-06 21:21:12 +00:00
func GetScriptPaths(ctx context.Context, pkgs []db.Package) []string {
2023-09-19 21:28:05 +00:00
var scripts []string
for _, pkg := range pkgs {
2023-10-06 21:21:12 +00:00
scriptPath := filepath.Join(config.GetPaths(ctx).RepoDir, pkg.Repository, pkg.Name, "lure.sh")
2023-09-19 21:28:05 +00:00
scripts = append(scripts, scriptPath)
}
return scripts
}
2023-09-21 23:18:18 +00:00
// InstallScripts builds and installs the given LURE build scripts
2023-09-19 21:28:05 +00:00
func InstallScripts(ctx context.Context, scripts []string, opts types.BuildOpts) {
2023-10-06 21:21:12 +00:00
log := loggerctx.From(ctx)
2023-09-19 21:28:05 +00:00
for _, script := range scripts {
opts.Script = script
builtPkgs, _, err := BuildPackage(ctx, opts)
if err != nil {
log.Fatal("Error building package").Err(err).Send()
}
err = opts.Manager.InstallLocal(nil, builtPkgs...)
if err != nil {
log.Fatal("Error installing package").Err(err).Send()
}
}
}