Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
41e3d8119f | |||
cf804ec66b | |||
6773d51caf |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -12,3 +12,5 @@
|
|||||||
e2e-tests/alr
|
e2e-tests/alr
|
||||||
CLAUDE.md
|
CLAUDE.md
|
||||||
commit_msg.txt
|
commit_msg.txt
|
||||||
|
/scripts/.claude/settings.local.json
|
||||||
|
/ALR
|
||||||
|
7
build.go
7
build.go
@@ -197,6 +197,13 @@ func BuildCmd() *cli.Command {
|
|||||||
|
|
||||||
for _, pkg := range res {
|
for _, pkg := range res {
|
||||||
name := filepath.Base(pkg.Path)
|
name := filepath.Base(pkg.Path)
|
||||||
|
|
||||||
|
// Проверяем, существует ли файл перед перемещением
|
||||||
|
if _, err := os.Stat(pkg.Path); os.IsNotExist(err) {
|
||||||
|
slog.Info("Package file already moved or removed, skipping", "path", pkg.Path)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
err = osutils.Move(pkg.Path, filepath.Join(wd, name))
|
err = osutils.Move(pkg.Path, filepath.Join(wd, name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cliutils.FormatCliExit(gotext.Get("Error moving the package"), err)
|
return cliutils.FormatCliExit(gotext.Get("Error moving the package"), err)
|
||||||
|
@@ -167,15 +167,30 @@ func (e *LocalScriptExecutor) ExecuteSecondPass(
|
|||||||
pkgName := packager.ConventionalFileName(pkgInfo) // Получаем имя файла пакета
|
pkgName := packager.ConventionalFileName(pkgInfo) // Получаем имя файла пакета
|
||||||
pkgPath := filepath.Join(dirs.BaseDir, pkgName) // Определяем путь к пакету
|
pkgPath := filepath.Join(dirs.BaseDir, pkgName) // Определяем путь к пакету
|
||||||
|
|
||||||
|
slog.Info("Creating package file", "path", pkgPath, "name", pkgName)
|
||||||
|
|
||||||
pkgFile, err := os.Create(pkgPath)
|
pkgFile, err := os.Create(pkgPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
slog.Error("Failed to create package file", "path", pkgPath, "error", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer pkgFile.Close()
|
||||||
|
|
||||||
|
slog.Info("Packaging with nfpm", "format", pkgFormat)
|
||||||
|
err = packager.Package(pkgInfo, pkgFile)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("Failed to create package", "path", pkgPath, "error", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = packager.Package(pkgInfo, pkgFile)
|
slog.Info("Package created successfully", "path", pkgPath)
|
||||||
if err != nil {
|
|
||||||
|
// Проверяем, что файл действительно существует
|
||||||
|
if _, err := os.Stat(pkgPath); err != nil {
|
||||||
|
slog.Error("Package file not found after creation", "path", pkgPath, "error", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
slog.Info("Package file verified to exist", "path", pkgPath)
|
||||||
|
|
||||||
builtDeps = append(builtDeps, &BuiltDep{
|
builtDeps = append(builtDeps, &BuiltDep{
|
||||||
Name: vars.Name,
|
Name: vars.Name,
|
||||||
|
@@ -49,12 +49,15 @@ import (
|
|||||||
|
|
||||||
// Функция prepareDirs подготавливает директории для сборки.
|
// Функция prepareDirs подготавливает директории для сборки.
|
||||||
func prepareDirs(dirs types.Directories) error {
|
func prepareDirs(dirs types.Directories) error {
|
||||||
// Пробуем удалить базовую директорию, если она существует
|
// Удаляем только директории источников и упаковки, не трогаем файлы пакетов в BaseDir
|
||||||
err := os.RemoveAll(dirs.BaseDir)
|
err := os.RemoveAll(dirs.SrcDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Если не можем удалить (например, принадлежит root), логируем и продолжаем
|
slog.Debug("Failed to remove src directory", "path", dirs.SrcDir, "error", err)
|
||||||
// Новые директории будут созданы или перезаписаны
|
}
|
||||||
slog.Debug("Failed to remove base directory", "path", dirs.BaseDir, "error", err)
|
|
||||||
|
err = os.RemoveAll(dirs.PkgDir)
|
||||||
|
if err != nil {
|
||||||
|
slog.Debug("Failed to remove pkg directory", "path", dirs.PkgDir, "error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Создаем базовую директорию для пакета с setgid битом
|
// Создаем базовую директорию для пакета с setgid битом
|
||||||
|
@@ -177,3 +177,333 @@ func filesFindCmd(hc interp.HandlerContext, cmd string, args []string) error {
|
|||||||
|
|
||||||
return outputFiles(hc, foundFiles)
|
return outputFiles(hc, foundFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func filesFindBinCmd(hc interp.HandlerContext, cmd string, args []string) error {
|
||||||
|
namePattern := "*"
|
||||||
|
if len(args) > 0 {
|
||||||
|
namePattern = args[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
binPath := "./usr/bin/"
|
||||||
|
realPath := path.Join(hc.Dir, binPath)
|
||||||
|
|
||||||
|
if err := validateDir(realPath, "files-find-bin"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var binFiles []string
|
||||||
|
err := filepath.Walk(realPath, func(p string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !info.IsDir() && matchNamePattern(info.Name(), namePattern) {
|
||||||
|
relPath, relErr := makeRelativePath(hc.Dir, p)
|
||||||
|
if relErr != nil {
|
||||||
|
return relErr
|
||||||
|
}
|
||||||
|
binFiles = append(binFiles, relPath)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("files-find-bin: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputFiles(hc, binFiles)
|
||||||
|
}
|
||||||
|
|
||||||
|
func filesFindLibCmd(hc interp.HandlerContext, cmd string, args []string) error {
|
||||||
|
namePattern := "*"
|
||||||
|
if len(args) > 0 {
|
||||||
|
namePattern = args[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
libPaths := []string{"./usr/lib/", "./usr/lib64/"}
|
||||||
|
var libFiles []string
|
||||||
|
|
||||||
|
for _, libPath := range libPaths {
|
||||||
|
realPath := path.Join(hc.Dir, libPath)
|
||||||
|
if _, err := os.Stat(realPath); os.IsNotExist(err) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
err := filepath.Walk(realPath, func(p string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !info.IsDir() && matchNamePattern(info.Name(), namePattern) {
|
||||||
|
relPath, relErr := makeRelativePath(hc.Dir, p)
|
||||||
|
if relErr != nil {
|
||||||
|
return relErr
|
||||||
|
}
|
||||||
|
libFiles = append(libFiles, relPath)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("files-find-lib: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputFiles(hc, libFiles)
|
||||||
|
}
|
||||||
|
|
||||||
|
func filesFindIncludeCmd(hc interp.HandlerContext, cmd string, args []string) error {
|
||||||
|
namePattern := "*"
|
||||||
|
if len(args) > 0 {
|
||||||
|
namePattern = args[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
includePath := "./usr/include/"
|
||||||
|
realPath := path.Join(hc.Dir, includePath)
|
||||||
|
|
||||||
|
if err := validateDir(realPath, "files-find-include"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var includeFiles []string
|
||||||
|
err := filepath.Walk(realPath, func(p string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !info.IsDir() && matchNamePattern(info.Name(), namePattern) {
|
||||||
|
relPath, relErr := makeRelativePath(hc.Dir, p)
|
||||||
|
if relErr != nil {
|
||||||
|
return relErr
|
||||||
|
}
|
||||||
|
includeFiles = append(includeFiles, relPath)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("files-find-include: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputFiles(hc, includeFiles)
|
||||||
|
}
|
||||||
|
|
||||||
|
func filesFindShareCmd(hc interp.HandlerContext, cmd string, args []string) error {
|
||||||
|
namePattern := "*"
|
||||||
|
sharePath := "./usr/share/"
|
||||||
|
|
||||||
|
if len(args) > 0 {
|
||||||
|
if len(args) == 1 {
|
||||||
|
sharePath = "./usr/share/" + args[0] + "/"
|
||||||
|
} else {
|
||||||
|
sharePath = "./usr/share/" + args[0] + "/"
|
||||||
|
namePattern = args[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
realPath := path.Join(hc.Dir, sharePath)
|
||||||
|
|
||||||
|
if err := validateDir(realPath, "files-find-share"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var shareFiles []string
|
||||||
|
err := filepath.Walk(realPath, func(p string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !info.IsDir() && matchNamePattern(info.Name(), namePattern) {
|
||||||
|
relPath, relErr := makeRelativePath(hc.Dir, p)
|
||||||
|
if relErr != nil {
|
||||||
|
return relErr
|
||||||
|
}
|
||||||
|
shareFiles = append(shareFiles, relPath)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("files-find-share: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputFiles(hc, shareFiles)
|
||||||
|
}
|
||||||
|
|
||||||
|
func filesFindManCmd(hc interp.HandlerContext, cmd string, args []string) error {
|
||||||
|
namePattern := "*"
|
||||||
|
manSection := "*"
|
||||||
|
|
||||||
|
if len(args) > 0 {
|
||||||
|
if len(args) == 1 {
|
||||||
|
manSection = args[0]
|
||||||
|
} else {
|
||||||
|
manSection = args[0]
|
||||||
|
namePattern = args[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
manPath := "./usr/share/man/man" + manSection + "/"
|
||||||
|
realPath := path.Join(hc.Dir, manPath)
|
||||||
|
|
||||||
|
if err := validateDir(realPath, "files-find-man"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var manFiles []string
|
||||||
|
err := filepath.Walk(realPath, func(p string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !info.IsDir() && matchNamePattern(info.Name(), namePattern) {
|
||||||
|
relPath, relErr := makeRelativePath(hc.Dir, p)
|
||||||
|
if relErr != nil {
|
||||||
|
return relErr
|
||||||
|
}
|
||||||
|
manFiles = append(manFiles, relPath)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("files-find-man: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputFiles(hc, manFiles)
|
||||||
|
}
|
||||||
|
|
||||||
|
func filesFindConfigCmd(hc interp.HandlerContext, cmd string, args []string) error {
|
||||||
|
namePattern := "*"
|
||||||
|
if len(args) > 0 {
|
||||||
|
namePattern = args[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
configPath := "./etc/"
|
||||||
|
realPath := path.Join(hc.Dir, configPath)
|
||||||
|
|
||||||
|
if err := validateDir(realPath, "files-find-config"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var configFiles []string
|
||||||
|
err := filepath.Walk(realPath, func(p string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !info.IsDir() && matchNamePattern(info.Name(), namePattern) {
|
||||||
|
relPath, relErr := makeRelativePath(hc.Dir, p)
|
||||||
|
if relErr != nil {
|
||||||
|
return relErr
|
||||||
|
}
|
||||||
|
configFiles = append(configFiles, relPath)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("files-find-config: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputFiles(hc, configFiles)
|
||||||
|
}
|
||||||
|
|
||||||
|
func filesFindSystemdCmd(hc interp.HandlerContext, cmd string, args []string) error {
|
||||||
|
namePattern := "*"
|
||||||
|
if len(args) > 0 {
|
||||||
|
namePattern = args[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
systemdPath := "./usr/lib/systemd/system/"
|
||||||
|
realPath := path.Join(hc.Dir, systemdPath)
|
||||||
|
|
||||||
|
if err := validateDir(realPath, "files-find-systemd"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var systemdFiles []string
|
||||||
|
err := filepath.Walk(realPath, func(p string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !info.IsDir() && matchNamePattern(info.Name(), namePattern) {
|
||||||
|
relPath, relErr := makeRelativePath(hc.Dir, p)
|
||||||
|
if relErr != nil {
|
||||||
|
return relErr
|
||||||
|
}
|
||||||
|
systemdFiles = append(systemdFiles, relPath)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("files-find-systemd: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputFiles(hc, systemdFiles)
|
||||||
|
}
|
||||||
|
|
||||||
|
func filesFindSystemdUserCmd(hc interp.HandlerContext, cmd string, args []string) error {
|
||||||
|
namePattern := "*"
|
||||||
|
if len(args) > 0 {
|
||||||
|
namePattern = args[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
systemdUserPath := "./usr/lib/systemd/user/"
|
||||||
|
realPath := path.Join(hc.Dir, systemdUserPath)
|
||||||
|
|
||||||
|
if err := validateDir(realPath, "files-find-systemd-user"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var systemdUserFiles []string
|
||||||
|
err := filepath.Walk(realPath, func(p string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !info.IsDir() && matchNamePattern(info.Name(), namePattern) {
|
||||||
|
relPath, relErr := makeRelativePath(hc.Dir, p)
|
||||||
|
if relErr != nil {
|
||||||
|
return relErr
|
||||||
|
}
|
||||||
|
systemdUserFiles = append(systemdUserFiles, relPath)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("files-find-systemd-user: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputFiles(hc, systemdUserFiles)
|
||||||
|
}
|
||||||
|
|
||||||
|
func filesFindLicenseCmd(hc interp.HandlerContext, cmd string, args []string) error {
|
||||||
|
namePattern := "*"
|
||||||
|
if len(args) > 0 {
|
||||||
|
namePattern = args[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
licensePath := "./usr/share/licenses/"
|
||||||
|
realPath := path.Join(hc.Dir, licensePath)
|
||||||
|
|
||||||
|
if err := validateDir(realPath, "files-find-license"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var licenseFiles []string
|
||||||
|
err := filepath.Walk(realPath, func(p string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !info.IsDir() && matchNamePattern(info.Name(), namePattern) {
|
||||||
|
relPath, relErr := makeRelativePath(hc.Dir, p)
|
||||||
|
if relErr != nil {
|
||||||
|
return relErr
|
||||||
|
}
|
||||||
|
licenseFiles = append(licenseFiles, relPath)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("files-find-license: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputFiles(hc, licenseFiles)
|
||||||
|
}
|
||||||
|
@@ -59,6 +59,15 @@ var Helpers = handlers.ExecFuncs{
|
|||||||
"files-find": filesFindCmd,
|
"files-find": filesFindCmd,
|
||||||
"files-find-lang": filesFindLangCmd,
|
"files-find-lang": filesFindLangCmd,
|
||||||
"files-find-doc": filesFindDocCmd,
|
"files-find-doc": filesFindDocCmd,
|
||||||
|
"files-find-bin": filesFindBinCmd,
|
||||||
|
"files-find-lib": filesFindLibCmd,
|
||||||
|
"files-find-include": filesFindIncludeCmd,
|
||||||
|
"files-find-share": filesFindShareCmd,
|
||||||
|
"files-find-man": filesFindManCmd,
|
||||||
|
"files-find-config": filesFindConfigCmd,
|
||||||
|
"files-find-systemd": filesFindSystemdCmd,
|
||||||
|
"files-find-systemd-user": filesFindSystemdUserCmd,
|
||||||
|
"files-find-license": filesFindLicenseCmd,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restricted contains restricted read-only helper commands
|
// Restricted contains restricted read-only helper commands
|
||||||
@@ -68,6 +77,15 @@ var Restricted = handlers.ExecFuncs{
|
|||||||
"files-find": filesFindCmd,
|
"files-find": filesFindCmd,
|
||||||
"files-find-lang": filesFindLangCmd,
|
"files-find-lang": filesFindLangCmd,
|
||||||
"files-find-doc": filesFindDocCmd,
|
"files-find-doc": filesFindDocCmd,
|
||||||
|
"files-find-bin": filesFindBinCmd,
|
||||||
|
"files-find-lib": filesFindLibCmd,
|
||||||
|
"files-find-include": filesFindIncludeCmd,
|
||||||
|
"files-find-share": filesFindShareCmd,
|
||||||
|
"files-find-man": filesFindManCmd,
|
||||||
|
"files-find-config": filesFindConfigCmd,
|
||||||
|
"files-find-systemd": filesFindSystemdCmd,
|
||||||
|
"files-find-systemd-user": filesFindSystemdUserCmd,
|
||||||
|
"files-find-license": filesFindLicenseCmd,
|
||||||
}
|
}
|
||||||
|
|
||||||
func installHelperCmd(prefix string, perms os.FileMode) handlers.ExecFunc {
|
func installHelperCmd(prefix string, perms os.FileMode) handlers.ExecFunc {
|
||||||
|
Reference in New Issue
Block a user