Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c2d48c1a13 | |||
| 72cdfcaa4b | |||
| c9c8397856 | |||
| 107075e8ef | |||
| 41e3d8119f | |||
| cf804ec66b | |||
| 6773d51caf | |||
| 4a616f2137 | |||
| 9efebbc02a | |||
| ef41d682a1 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -12,3 +12,6 @@
|
|||||||
e2e-tests/alr
|
e2e-tests/alr
|
||||||
CLAUDE.md
|
CLAUDE.md
|
||||||
commit_msg.txt
|
commit_msg.txt
|
||||||
|
/scripts/.claude/settings.local.json
|
||||||
|
/ALR
|
||||||
|
.claude/settings.local.json
|
||||||
|
|||||||
BIN
assets/logo.png
BIN
assets/logo.png
Binary file not shown.
|
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 17 KiB |
9
build.go
9
build.go
@@ -63,7 +63,7 @@ func BuildCmd() *cli.Command {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
if err := utils.EnuseIsPrivilegedGroupMember(); err != nil {
|
if err := utils.CheckUserPrivileges(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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(gotext.Get("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)
|
||||||
|
|||||||
18
config.go
18
config.go
@@ -38,6 +38,24 @@ func ConfigCmd() *cli.Command {
|
|||||||
ShowCmd(),
|
ShowCmd(),
|
||||||
SetConfig(),
|
SetConfig(),
|
||||||
GetConfig(),
|
GetConfig(),
|
||||||
|
ConfigHelpCmd(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ConfigHelpCmd() *cli.Command {
|
||||||
|
return &cli.Command{
|
||||||
|
Name: "help",
|
||||||
|
Aliases: []string{"h"},
|
||||||
|
Usage: gotext.Get("Shows a list of commands or help for one command"),
|
||||||
|
ArgsUsage: "[command]",
|
||||||
|
Action: func(cCtx *cli.Context) error {
|
||||||
|
args := cCtx.Args()
|
||||||
|
if args.Present() {
|
||||||
|
return cli.ShowCommandHelp(cCtx, args.First())
|
||||||
|
}
|
||||||
|
cli.ShowSubcommandHelp(cCtx)
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,17 +45,17 @@ func TestE2EIssue130Install(t *testing.T) {
|
|||||||
)
|
)
|
||||||
runMatrixSuite(
|
runMatrixSuite(
|
||||||
t,
|
t,
|
||||||
"alr install {package}+alr-{repo}",
|
"alr install {package}+{repo}",
|
||||||
COMMON_SYSTEMS,
|
COMMON_SYSTEMS,
|
||||||
func(t *testing.T, r capytest.Runner) {
|
func(t *testing.T, r capytest.Runner) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
defaultPrepare(t, r)
|
defaultPrepare(t, r)
|
||||||
|
|
||||||
r.Command("sudo", "alr", "in", fmt.Sprintf("foo-pkg+alr-%s", REPO_NAME_FOR_E2E_TESTS)).
|
r.Command("sudo", "alr", "in", fmt.Sprintf("foo-pkg+%s", REPO_NAME_FOR_E2E_TESTS)).
|
||||||
ExpectSuccess().
|
ExpectSuccess().
|
||||||
Run(t)
|
Run(t)
|
||||||
|
|
||||||
r.Command("sudo", "alr", "in", fmt.Sprintf("bar-pkg+alr-%s", "NOT_REPO_NAME_FOR_E2E_TESTS")).
|
r.Command("sudo", "alr", "in", fmt.Sprintf("bar-pkg+%s", "NOT_REPO_NAME_FOR_E2E_TESTS")).
|
||||||
ExpectFailure().
|
ExpectFailure().
|
||||||
Run(t)
|
Run(t)
|
||||||
},
|
},
|
||||||
|
|||||||
32
fix.go
32
fix.go
@@ -131,22 +131,22 @@ func FixCmd() *cli.Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Создаем базовый каталог /tmp/alr с владельцем root:wheel и правами 775
|
// Создаем базовый каталог /tmp/alr с владельцем root:wheel и правами 2775
|
||||||
err = utils.EnsureTempDirWithRootOwner(tmpDir, 0o775)
|
err = utils.EnsureTempDirWithRootOwner(tmpDir, 0o2775)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Warn(gotext.Get("Unable to create temporary directory"), "error", err)
|
slog.Warn(gotext.Get("Unable to create temporary directory"), "error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Создаем каталог dl с правами для группы wheel
|
// Создаем каталог dl с правами для группы wheel
|
||||||
dlDir := filepath.Join(tmpDir, "dl")
|
dlDir := filepath.Join(tmpDir, "dl")
|
||||||
err = utils.EnsureTempDirWithRootOwner(dlDir, 0o775)
|
err = utils.EnsureTempDirWithRootOwner(dlDir, 0o2775)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Warn(gotext.Get("Unable to create download directory"), "error", err)
|
slog.Warn(gotext.Get("Unable to create download directory"), "error", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Создаем каталог pkgs с правами для группы wheel
|
// Создаем каталог pkgs с правами для группы wheel
|
||||||
pkgsDir := filepath.Join(tmpDir, "pkgs")
|
pkgsDir := filepath.Join(tmpDir, "pkgs")
|
||||||
err = utils.EnsureTempDirWithRootOwner(pkgsDir, 0o775)
|
err = utils.EnsureTempDirWithRootOwner(pkgsDir, 0o2775)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Warn(gotext.Get("Unable to create packages directory"), "error", err)
|
slog.Warn(gotext.Get("Unable to create packages directory"), "error", err)
|
||||||
}
|
}
|
||||||
@@ -158,7 +158,8 @@ func FixCmd() *cli.Command {
|
|||||||
// Проверяем, есть ли файлы в директории
|
// Проверяем, есть ли файлы в директории
|
||||||
entries, err := os.ReadDir(tmpDir)
|
entries, err := os.ReadDir(tmpDir)
|
||||||
if err == nil && len(entries) > 0 {
|
if err == nil && len(entries) > 0 {
|
||||||
fixCmd := execWithPrivileges("chown", "-R", "root:wheel", tmpDir)
|
group := utils.GetPrivilegedGroup()
|
||||||
|
fixCmd := execWithPrivileges("chown", "-R", "root:"+group, tmpDir)
|
||||||
if fixErr := fixCmd.Run(); fixErr != nil {
|
if fixErr := fixCmd.Run(); fixErr != nil {
|
||||||
slog.Warn(gotext.Get("Unable to fix file ownership"), "error", fixErr)
|
slog.Warn(gotext.Get("Unable to fix file ownership"), "error", fixErr)
|
||||||
}
|
}
|
||||||
@@ -172,28 +173,13 @@ func FixCmd() *cli.Command {
|
|||||||
|
|
||||||
slog.Info(gotext.Get("Rebuilding cache"))
|
slog.Info(gotext.Get("Rebuilding cache"))
|
||||||
|
|
||||||
// Пробуем создать директорию кэша
|
// Создаем директорию кэша с правильными правами
|
||||||
err = os.MkdirAll(paths.CacheDir, 0o775)
|
slog.Info(gotext.Get("Creating cache directory"))
|
||||||
|
err = utils.EnsureTempDirWithRootOwner(paths.CacheDir, 0o2775)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Если не получилось, пробуем через sudo с правильными правами для группы wheel
|
|
||||||
slog.Info(gotext.Get("Creating cache directory with sudo"))
|
|
||||||
sudoCmd := execWithPrivileges("mkdir", "-p", paths.CacheDir)
|
|
||||||
if sudoErr := sudoCmd.Run(); sudoErr != nil {
|
|
||||||
return cliutils.FormatCliExit(gotext.Get("Unable to create new cache directory"), err)
|
return cliutils.FormatCliExit(gotext.Get("Unable to create new cache directory"), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Устанавливаем права 775 и группу wheel
|
|
||||||
chmodCmd := execWithPrivileges("chmod", "775", paths.CacheDir)
|
|
||||||
if chmodErr := chmodCmd.Run(); chmodErr != nil {
|
|
||||||
return cliutils.FormatCliExit(gotext.Get("Unable to set cache directory permissions"), chmodErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
chgrpCmd := execWithPrivileges("chgrp", "wheel", paths.CacheDir)
|
|
||||||
if chgrpErr := chgrpCmd.Run(); chgrpErr != nil {
|
|
||||||
return cliutils.FormatCliExit(gotext.Get("Unable to set cache directory group"), chgrpErr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
deps, err = appbuilder.
|
deps, err = appbuilder.
|
||||||
New(ctx).
|
New(ctx).
|
||||||
WithConfig().
|
WithConfig().
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -4,6 +4,7 @@ go 1.24.4
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
gitea.plemya-x.ru/Plemya-x/fakeroot v0.0.2-0.20250408104831-427aaa7713c3
|
gitea.plemya-x.ru/Plemya-x/fakeroot v0.0.2-0.20250408104831-427aaa7713c3
|
||||||
|
gitea.plemya-x.ru/xpamych/vercmp v0.0.1
|
||||||
github.com/AlecAivazis/survey/v2 v2.3.7
|
github.com/AlecAivazis/survey/v2 v2.3.7
|
||||||
github.com/PuerkitoBio/purell v1.2.0
|
github.com/PuerkitoBio/purell v1.2.0
|
||||||
github.com/alecthomas/chroma/v2 v2.9.1
|
github.com/alecthomas/chroma/v2 v2.9.1
|
||||||
@@ -36,7 +37,6 @@ require (
|
|||||||
github.com/vmihailenco/msgpack/v5 v5.3.5
|
github.com/vmihailenco/msgpack/v5 v5.3.5
|
||||||
go.alt-gnome.ru/capytest v0.0.3-0.20250706082755-f20413e052f9
|
go.alt-gnome.ru/capytest v0.0.3-0.20250706082755-f20413e052f9
|
||||||
go.alt-gnome.ru/capytest/providers/podman v0.0.3-0.20250706082755-f20413e052f9
|
go.alt-gnome.ru/capytest/providers/podman v0.0.3-0.20250706082755-f20413e052f9
|
||||||
go.elara.ws/vercmp v0.0.0-20230622214216-0b2b067575c4
|
|
||||||
golang.org/x/crypto v0.36.0
|
golang.org/x/crypto v0.36.0
|
||||||
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
|
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
|
||||||
golang.org/x/sys v0.33.0
|
golang.org/x/sys v0.33.0
|
||||||
|
|||||||
6
go.sum
6
go.sum
@@ -21,6 +21,8 @@ gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGq
|
|||||||
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU=
|
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a/go.mod h1:EXuID2Zs0pAQhH8yz+DNjUbjppKQzKFAn28TMYPB6IU=
|
||||||
gitea.plemya-x.ru/Plemya-x/fakeroot v0.0.2-0.20250408104831-427aaa7713c3 h1:56BjRJJ2Sv50DfSvNUydUMJwwFuiBMWC1uYtH2GYjk8=
|
gitea.plemya-x.ru/Plemya-x/fakeroot v0.0.2-0.20250408104831-427aaa7713c3 h1:56BjRJJ2Sv50DfSvNUydUMJwwFuiBMWC1uYtH2GYjk8=
|
||||||
gitea.plemya-x.ru/Plemya-x/fakeroot v0.0.2-0.20250408104831-427aaa7713c3/go.mod h1:iKQM6uttMJgE5CFrPw6SQqAV7TKtlJNICRAie/dTciw=
|
gitea.plemya-x.ru/Plemya-x/fakeroot v0.0.2-0.20250408104831-427aaa7713c3/go.mod h1:iKQM6uttMJgE5CFrPw6SQqAV7TKtlJNICRAie/dTciw=
|
||||||
|
gitea.plemya-x.ru/xpamych/vercmp v0.0.1 h1:tFQzsPfnQQDQ3jrqW0UwUSbK+HwJuq0sA0GfnvIkatw=
|
||||||
|
gitea.plemya-x.ru/xpamych/vercmp v0.0.1/go.mod h1:z9qQ4QJDou1AULVKPIW5blu/jT+O3O5HpTV8aujWSIM=
|
||||||
github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ=
|
github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ=
|
||||||
github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
|
github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo=
|
||||||
github.com/AlekSi/pointer v1.2.0 h1:glcy/gc4h8HnG2Z3ZECSzZ1IX1x2JxRVuDzaJwQE0+w=
|
github.com/AlekSi/pointer v1.2.0 h1:glcy/gc4h8HnG2Z3ZECSzZ1IX1x2JxRVuDzaJwQE0+w=
|
||||||
@@ -432,14 +434,10 @@ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsr
|
|||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
gitlab.com/digitalxero/go-conventional-commit v1.0.7 h1:8/dO6WWG+98PMhlZowt/YjuiKhqhGlOCwlIV8SqqGh8=
|
gitlab.com/digitalxero/go-conventional-commit v1.0.7 h1:8/dO6WWG+98PMhlZowt/YjuiKhqhGlOCwlIV8SqqGh8=
|
||||||
gitlab.com/digitalxero/go-conventional-commit v1.0.7/go.mod h1:05Xc2BFsSyC5tKhK0y+P3bs0AwUtNuTp+mTpbCU/DZ0=
|
gitlab.com/digitalxero/go-conventional-commit v1.0.7/go.mod h1:05Xc2BFsSyC5tKhK0y+P3bs0AwUtNuTp+mTpbCU/DZ0=
|
||||||
go.alt-gnome.ru/capytest v0.0.2 h1:clmvIqmYS86hhA1rsvivSSPpfOFkJTpbn38EQP7I3E8=
|
|
||||||
go.alt-gnome.ru/capytest v0.0.2/go.mod h1:lvxPx3H6h+LPnStBFblgoT2wkjv0wbug3S14troykEg=
|
|
||||||
go.alt-gnome.ru/capytest v0.0.3-0.20250706082755-f20413e052f9 h1:NST+V5LV/eLgs0p6PsuvfHiZ4UrIWqftCdifO8zgg0g=
|
go.alt-gnome.ru/capytest v0.0.3-0.20250706082755-f20413e052f9 h1:NST+V5LV/eLgs0p6PsuvfHiZ4UrIWqftCdifO8zgg0g=
|
||||||
go.alt-gnome.ru/capytest v0.0.3-0.20250706082755-f20413e052f9/go.mod h1:qiM8LARP+JBZr5mrDoVylOoqjrN0MAzvZ21NR9qMc0Y=
|
go.alt-gnome.ru/capytest v0.0.3-0.20250706082755-f20413e052f9/go.mod h1:qiM8LARP+JBZr5mrDoVylOoqjrN0MAzvZ21NR9qMc0Y=
|
||||||
go.alt-gnome.ru/capytest/providers/podman v0.0.3-0.20250706082755-f20413e052f9 h1:VZclgdJxARvhZ6PIWWW2hQ6Ge4XeE36pzUr/U/y62bE=
|
go.alt-gnome.ru/capytest/providers/podman v0.0.3-0.20250706082755-f20413e052f9 h1:VZclgdJxARvhZ6PIWWW2hQ6Ge4XeE36pzUr/U/y62bE=
|
||||||
go.alt-gnome.ru/capytest/providers/podman v0.0.3-0.20250706082755-f20413e052f9/go.mod h1:Wpq1Ny3eMzADJpMJArA2TZGZbsviUBmawtEPcxnoerg=
|
go.alt-gnome.ru/capytest/providers/podman v0.0.3-0.20250706082755-f20413e052f9/go.mod h1:Wpq1Ny3eMzADJpMJArA2TZGZbsviUBmawtEPcxnoerg=
|
||||||
go.elara.ws/vercmp v0.0.0-20230622214216-0b2b067575c4 h1:Ep54XceQlKhcCHl9awG+wWP4kz4kIP3c3Lzw/Gc/zwY=
|
|
||||||
go.elara.ws/vercmp v0.0.0-20230622214216-0b2b067575c4/go.mod h1:/7PNW7nFnDR5W7UXZVc04gdVLR/wBNgkm33KgIz0OBk=
|
|
||||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||||
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
||||||
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
||||||
|
|||||||
18
helper.go
18
helper.go
@@ -49,11 +49,26 @@ func HelperCmd() *cli.Command {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
helperHelpCmd := &cli.Command{
|
||||||
|
Name: "help",
|
||||||
|
Aliases: []string{"h"},
|
||||||
|
Usage: gotext.Get("Shows a list of commands or help for one command"),
|
||||||
|
ArgsUsage: "[command]",
|
||||||
|
Action: func(cCtx *cli.Context) error {
|
||||||
|
args := cCtx.Args()
|
||||||
|
if args.Present() {
|
||||||
|
return cli.ShowCommandHelp(cCtx, args.First())
|
||||||
|
}
|
||||||
|
cli.ShowSubcommandHelp(cCtx)
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
return &cli.Command{
|
return &cli.Command{
|
||||||
Name: "helper",
|
Name: "helper",
|
||||||
Usage: gotext.Get("Run a ALR helper command"),
|
Usage: gotext.Get("Run a ALR helper command"),
|
||||||
ArgsUsage: `<helper_name|"list">`,
|
ArgsUsage: `<helper_name|"list">`,
|
||||||
Subcommands: []*cli.Command{helperListCmd},
|
Subcommands: []*cli.Command{helperListCmd, helperHelpCmd},
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "dest-dir",
|
Name: "dest-dir",
|
||||||
@@ -100,7 +115,6 @@ func HelperCmd() *cli.Command {
|
|||||||
|
|
||||||
return helper(hc, c.Args().First(), c.Args().Slice()[1:])
|
return helper(hc, c.Args().First(), c.Args().Slice()[1:])
|
||||||
},
|
},
|
||||||
CustomHelpTemplate: cli.CommandHelpTemplate,
|
|
||||||
BashComplete: func(ctx *cli.Context) {
|
BashComplete: func(ctx *cli.Context) {
|
||||||
for name := range helpers.Helpers {
|
for name := range helpers.Helpers {
|
||||||
fmt.Println(name)
|
fmt.Println(name)
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import (
|
|||||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/config"
|
"gitea.plemya-x.ru/Plemya-x/ALR/internal/config"
|
||||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/logger"
|
"gitea.plemya-x.ru/Plemya-x/ALR/internal/logger"
|
||||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/manager"
|
"gitea.plemya-x.ru/Plemya-x/ALR/internal/manager"
|
||||||
|
"gitea.plemya-x.ru/Plemya-x/ALR/internal/translations"
|
||||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/utils"
|
"gitea.plemya-x.ru/Plemya-x/ALR/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -42,6 +43,7 @@ func InternalBuildCmd() *cli.Command {
|
|||||||
Hidden: true,
|
Hidden: true,
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
logger.SetupForGoPlugin()
|
logger.SetupForGoPlugin()
|
||||||
|
translations.Setup()
|
||||||
|
|
||||||
slog.Debug("start _internal-safe-script-executor", "uid", syscall.Getuid(), "gid", syscall.Getgid())
|
slog.Debug("start _internal-safe-script-executor", "uid", syscall.Getuid(), "gid", syscall.Getgid())
|
||||||
|
|
||||||
@@ -81,7 +83,7 @@ func InternalReposCmd() *cli.Command {
|
|||||||
Hidden: true,
|
Hidden: true,
|
||||||
Action: utils.RootNeededAction(func(ctx *cli.Context) error {
|
Action: utils.RootNeededAction(func(ctx *cli.Context) error {
|
||||||
logger.SetupForGoPlugin()
|
logger.SetupForGoPlugin()
|
||||||
|
translations.Setup()
|
||||||
|
|
||||||
deps, err := appbuilder.
|
deps, err := appbuilder.
|
||||||
New(ctx.Context).
|
New(ctx.Context).
|
||||||
@@ -115,6 +117,7 @@ func InternalInstallCmd() *cli.Command {
|
|||||||
Hidden: true,
|
Hidden: true,
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
logger.SetupForGoPlugin()
|
logger.SetupForGoPlugin()
|
||||||
|
translations.Setup()
|
||||||
|
|
||||||
// Запуск от текущего пользователя, повышение прав будет через sudo при необходимости
|
// Запуск от текущего пользователя, повышение прав будет через sudo при необходимости
|
||||||
|
|
||||||
|
|||||||
@@ -583,6 +583,12 @@ func (b *Builder) BuildALRDeps(
|
|||||||
input.BuildOpts().Interactive,
|
input.BuildOpts().Interactive,
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
pkgs, err = b.installerExecutor.FilterPackagesByVersion(ctx, pkgs, input.OSRelease())
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, fmt.Errorf("failed to filter packages by version: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
type item struct {
|
type item struct {
|
||||||
pkg *alrsh.Package
|
pkg *alrsh.Package
|
||||||
packages []string
|
packages []string
|
||||||
|
|||||||
@@ -18,8 +18,16 @@ package build
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
|
|
||||||
|
"github.com/leonelquinteros/gotext"
|
||||||
|
"gitea.plemya-x.ru/xpamych/vercmp"
|
||||||
|
|
||||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/manager"
|
"gitea.plemya-x.ru/Plemya-x/ALR/internal/manager"
|
||||||
|
"gitea.plemya-x.ru/Plemya-x/ALR/internal/overrides"
|
||||||
|
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/alrsh"
|
||||||
|
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/distro"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewInstaller(mgr manager.Manager) *Installer {
|
func NewInstaller(mgr manager.Manager) *Installer {
|
||||||
@@ -58,3 +66,44 @@ func (i *Installer) RemoveAlreadyInstalled(ctx context.Context, pkgs []string) (
|
|||||||
|
|
||||||
return filteredPackages, nil
|
return filteredPackages, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i *Installer) FilterPackagesByVersion(ctx context.Context, packages []alrsh.Package, osRelease *distro.OSRelease) ([]alrsh.Package, error) {
|
||||||
|
installedPkgs, err := i.mgr.ListInstalled(nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to list installed packages: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var filteredPackages []alrsh.Package
|
||||||
|
|
||||||
|
for _, pkg := range packages {
|
||||||
|
alrPkgName := fmt.Sprintf("%s+%s", pkg.Name, pkg.Repository)
|
||||||
|
installedVer, isInstalled := installedPkgs[alrPkgName]
|
||||||
|
|
||||||
|
if !isInstalled {
|
||||||
|
filteredPackages = append(filteredPackages, pkg)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
repoVer := pkg.Version
|
||||||
|
releaseStr := overrides.ReleasePlatformSpecific(pkg.Release, osRelease)
|
||||||
|
|
||||||
|
if pkg.Release != 0 && pkg.Epoch == 0 {
|
||||||
|
repoVer = fmt.Sprintf("%s-%s", pkg.Version, releaseStr)
|
||||||
|
} else if pkg.Release != 0 && pkg.Epoch != 0 {
|
||||||
|
repoVer = fmt.Sprintf("%d:%s-%s", pkg.Epoch, pkg.Version, releaseStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmp := vercmp.Compare(repoVer, installedVer)
|
||||||
|
|
||||||
|
if cmp > 0 {
|
||||||
|
slog.Info(gotext.Get("Package %s is installed with older version %s, will rebuild with version %s", alrPkgName, installedVer, repoVer))
|
||||||
|
filteredPackages = append(filteredPackages, pkg)
|
||||||
|
} else if cmp == 0 {
|
||||||
|
slog.Info(gotext.Get("Package %s is already installed with version %s, skipping build", alrPkgName, installedVer))
|
||||||
|
} else {
|
||||||
|
slog.Info(gotext.Get("Package %s is installed with newer version %s (repo has %s), skipping build", alrPkgName, installedVer, repoVer))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return filteredPackages, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import (
|
|||||||
|
|
||||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/manager"
|
"gitea.plemya-x.ru/Plemya-x/ALR/internal/manager"
|
||||||
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/alrsh"
|
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/alrsh"
|
||||||
|
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/distro"
|
||||||
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/types"
|
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -34,6 +35,7 @@ type InstallerExecutor interface {
|
|||||||
Install(ctx context.Context, pkgs []string, opts *manager.Opts) error
|
Install(ctx context.Context, pkgs []string, opts *manager.Opts) error
|
||||||
Remove(ctx context.Context, pkgs []string, opts *manager.Opts) error
|
Remove(ctx context.Context, pkgs []string, opts *manager.Opts) error
|
||||||
RemoveAlreadyInstalled(ctx context.Context, pkgs []string) ([]string, error)
|
RemoveAlreadyInstalled(ctx context.Context, pkgs []string) ([]string, error)
|
||||||
|
FilterPackagesByVersion(ctx context.Context, packages []alrsh.Package, osRelease *distro.OSRelease) ([]alrsh.Package, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ScriptExecutor interface {
|
type ScriptExecutor interface {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/manager"
|
"gitea.plemya-x.ru/Plemya-x/ALR/internal/manager"
|
||||||
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/alrsh"
|
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/alrsh"
|
||||||
|
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/distro"
|
||||||
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/types"
|
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/types"
|
||||||
"github.com/hashicorp/go-plugin"
|
"github.com/hashicorp/go-plugin"
|
||||||
)
|
)
|
||||||
@@ -205,6 +206,38 @@ func (s *InstallerExecutorRPCServer) RemoveAlreadyInstalled(args *InstallerExecu
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type InstallerExecutorFilterPackagesByVersionArgs struct {
|
||||||
|
Packages []alrsh.Package
|
||||||
|
OsRelease *distro.OSRelease
|
||||||
|
}
|
||||||
|
|
||||||
|
type InstallerExecutorFilterPackagesByVersionResp struct {
|
||||||
|
Result0 []alrsh.Package
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *InstallerExecutorRPC) FilterPackagesByVersion(ctx context.Context, packages []alrsh.Package, osRelease *distro.OSRelease) ([]alrsh.Package, error) {
|
||||||
|
var resp *InstallerExecutorFilterPackagesByVersionResp
|
||||||
|
err := s.client.Call("Plugin.FilterPackagesByVersion", &InstallerExecutorFilterPackagesByVersionArgs{
|
||||||
|
Packages: packages,
|
||||||
|
OsRelease: osRelease,
|
||||||
|
}, &resp)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return resp.Result0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *InstallerExecutorRPCServer) FilterPackagesByVersion(args *InstallerExecutorFilterPackagesByVersionArgs, resp *InstallerExecutorFilterPackagesByVersionResp) error {
|
||||||
|
result0, err := s.Impl.FilterPackagesByVersion(context.Background(), args.Packages, args.OsRelease)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*resp = InstallerExecutorFilterPackagesByVersionResp{
|
||||||
|
Result0: result0,
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
type ScriptExecutorReadScriptArgs struct {
|
type ScriptExecutorReadScriptArgs struct {
|
||||||
ScriptPath string
|
ScriptPath string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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(gotext.Get("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(gotext.Get("Failed to create package file"), "path", pkgPath, "error", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer pkgFile.Close()
|
||||||
|
|
||||||
|
slog.Info(gotext.Get("Packaging with nfpm"), "format", pkgFormat)
|
||||||
|
err = packager.Package(pkgInfo, pkgFile)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error(gotext.Get("Failed to create package"), "path", pkgPath, "error", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = packager.Package(pkgInfo, pkgFile)
|
slog.Info(gotext.Get("Package created successfully"), "path", pkgPath)
|
||||||
if err != nil {
|
|
||||||
|
// Проверяем, что файл действительно существует
|
||||||
|
if _, err := os.Stat(pkgPath); err != nil {
|
||||||
|
slog.Error(gotext.Get("Package file not found after creation"), "path", pkgPath, "error", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
slog.Info(gotext.Get("Package file verified to exist"), "path", pkgPath)
|
||||||
|
|
||||||
builtDeps = append(builtDeps, &BuiltDep{
|
builtDeps = append(builtDeps, &BuiltDep{
|
||||||
Name: vars.Name,
|
Name: vars.Name,
|
||||||
|
|||||||
@@ -49,12 +49,21 @@ 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 битом
|
||||||
|
err = utils.EnsureTempDirWithRootOwner(dirs.BaseDir, 0o2775)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Создаем директории с правильным владельцем для /tmp/alr с setgid битом
|
// Создаем директории с правильным владельцем для /tmp/alr с setgid битом
|
||||||
@@ -169,7 +178,7 @@ func normalizeContents(contents []*files.Content) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var RegexpALRPackageName = regexp.MustCompile(`^(?P<package>[^+]+)\+alr-(?P<repo>.+)$`)
|
var RegexpALRPackageName = regexp.MustCompile(`^(?P<package>[^+]+)\+(?P<repo>.+)$`)
|
||||||
|
|
||||||
func getBasePkgInfo(vars *alrsh.Package, input interface {
|
func getBasePkgInfo(vars *alrsh.Package, input interface {
|
||||||
RepositoryProvider
|
RepositoryProvider
|
||||||
@@ -177,12 +186,8 @@ func getBasePkgInfo(vars *alrsh.Package, input interface {
|
|||||||
},
|
},
|
||||||
) *nfpm.Info {
|
) *nfpm.Info {
|
||||||
repo := input.Repository()
|
repo := input.Repository()
|
||||||
// Избегаем дублирования "alr-" префикса
|
|
||||||
if strings.HasPrefix(repo, "alr-") {
|
|
||||||
repo = repo[4:] // убираем "alr-" префикс
|
|
||||||
}
|
|
||||||
return &nfpm.Info{
|
return &nfpm.Info{
|
||||||
Name: fmt.Sprintf("%s+alr-%s", vars.Name, repo),
|
Name: fmt.Sprintf("%s+%s", vars.Name, repo),
|
||||||
Arch: cpu.Arch(),
|
Arch: cpu.Arch(),
|
||||||
Version: vars.Version,
|
Version: vars.Version,
|
||||||
Release: overrides.ReleasePlatformSpecific(vars.Release, input.OSRelease()),
|
Release: overrides.ReleasePlatformSpecific(vars.Release, input.OSRelease()),
|
||||||
|
|||||||
158
internal/build/utils_test.go
Normal file
158
internal/build/utils_test.go
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
// ALR - Any Linux Repository
|
||||||
|
// Copyright (C) 2025 The ALR Authors
|
||||||
|
//
|
||||||
|
// 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 build
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/alrsh"
|
||||||
|
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/distro"
|
||||||
|
)
|
||||||
|
|
||||||
|
type mockInput struct {
|
||||||
|
repo string
|
||||||
|
osInfo *distro.OSRelease
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockInput) Repository() string {
|
||||||
|
return m.repo
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mockInput) OSRelease() *distro.OSRelease {
|
||||||
|
return m.osInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetBasePkgInfo(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
packageName string
|
||||||
|
repoName string
|
||||||
|
expectedName string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "обычный репозиторий",
|
||||||
|
packageName: "test-package",
|
||||||
|
repoName: "default",
|
||||||
|
expectedName: "test-package+default",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "репозиторий с alr- префиксом",
|
||||||
|
packageName: "test-package",
|
||||||
|
repoName: "alr-default",
|
||||||
|
expectedName: "test-package+alr-default",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "репозиторий с двойным alr- префиксом",
|
||||||
|
packageName: "test-package",
|
||||||
|
repoName: "alr-alr-repo",
|
||||||
|
expectedName: "test-package+alr-alr-repo",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
pkg := &alrsh.Package{
|
||||||
|
Name: tt.packageName,
|
||||||
|
Version: "1.0.0",
|
||||||
|
Release: 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
input := &mockInput{
|
||||||
|
repo: tt.repoName,
|
||||||
|
osInfo: &distro.OSRelease{
|
||||||
|
ID: "test",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
info := getBasePkgInfo(pkg, input)
|
||||||
|
|
||||||
|
if info.Name != tt.expectedName {
|
||||||
|
t.Errorf("getBasePkgInfo() имя пакета = %v, ожидается %v", info.Name, tt.expectedName)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRegexpALRPackageName(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
packageName string
|
||||||
|
expectedPkg string
|
||||||
|
expectedRepo string
|
||||||
|
shouldMatch bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "новый формат - обычный репозиторий",
|
||||||
|
packageName: "test-package+default",
|
||||||
|
expectedPkg: "test-package",
|
||||||
|
expectedRepo: "default",
|
||||||
|
shouldMatch: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "новый формат - alr-default репозиторий",
|
||||||
|
packageName: "test-package+alr-default",
|
||||||
|
expectedPkg: "test-package",
|
||||||
|
expectedRepo: "alr-default",
|
||||||
|
shouldMatch: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "новый формат - двойной alr- префикс",
|
||||||
|
packageName: "test-package+alr-alr-repo",
|
||||||
|
expectedPkg: "test-package",
|
||||||
|
expectedRepo: "alr-alr-repo",
|
||||||
|
shouldMatch: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "некорректный формат - без плюса",
|
||||||
|
packageName: "test-package",
|
||||||
|
shouldMatch: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "некорректный формат - пустое имя пакета",
|
||||||
|
packageName: "+repo",
|
||||||
|
shouldMatch: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
matches := RegexpALRPackageName.FindStringSubmatch(tt.packageName)
|
||||||
|
|
||||||
|
if tt.shouldMatch {
|
||||||
|
if matches == nil {
|
||||||
|
t.Errorf("RegexpALRPackageName должен найти совпадение для %q", tt.packageName)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
packageName := matches[RegexpALRPackageName.SubexpIndex("package")]
|
||||||
|
repoName := matches[RegexpALRPackageName.SubexpIndex("repo")]
|
||||||
|
|
||||||
|
if packageName != tt.expectedPkg {
|
||||||
|
t.Errorf("RegexpALRPackageName извлеченное имя пакета = %v, ожидается %v", packageName, tt.expectedPkg)
|
||||||
|
}
|
||||||
|
|
||||||
|
if repoName != tt.expectedRepo {
|
||||||
|
t.Errorf("RegexpALRPackageName извлеченное имя репозитория = %v, ожидается %v", repoName, tt.expectedRepo)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if matches != nil {
|
||||||
|
t.Errorf("RegexpALRPackageName не должен найти совпадение для %q", tt.packageName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -42,7 +42,7 @@ type AppDeps struct {
|
|||||||
func (d *AppDeps) Defer() {
|
func (d *AppDeps) Defer() {
|
||||||
if d.DB != nil {
|
if d.DB != nil {
|
||||||
if err := d.DB.Close(); err != nil {
|
if err := d.DB.Close(); err != nil {
|
||||||
slog.Warn("failed to close db", "err", err)
|
slog.Warn(gotext.Get("failed to close db"), "err", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,3 +100,28 @@ func GetCommandHelpTemplate() string {
|
|||||||
gotext.Get("OPTIONS"),
|
gotext.Get("OPTIONS"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetSubcommandHelpTemplate() string {
|
||||||
|
return fmt.Sprintf(`%s:
|
||||||
|
{{template "helpNameTemplate" .}}
|
||||||
|
|
||||||
|
%s:
|
||||||
|
{{.HelpName}} %s [%s] {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[%s...]{{end}}
|
||||||
|
{{if .Description}}
|
||||||
|
|
||||||
|
%s:
|
||||||
|
{{template "descriptionTemplate" .}}{{end}}
|
||||||
|
{{- if len .Authors}}
|
||||||
|
|
||||||
|
%s{{template "authorsTemplate" .}}{{end}}{{if .VisibleCommands}}
|
||||||
|
|
||||||
|
%s:{{template "visibleCommandCategoryTemplate" .}}{{end}}{{if .VisibleFlagCategories}}
|
||||||
|
|
||||||
|
%s:{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}}
|
||||||
|
|
||||||
|
%s:{{template "visibleFlagTemplate" .}}{{end}}{{if .Copyright}}
|
||||||
|
|
||||||
|
%s:
|
||||||
|
{{template "copyrightTemplate" .}}{{end}}
|
||||||
|
`, gotext.Get("NAME"), gotext.Get("USAGE"), gotext.Get("command"), gotext.Get("command options"), gotext.Get("arguments"), gotext.Get("DESCRIPTION"), gotext.Get("AUTHOR"), gotext.Get("COMMANDS"), gotext.Get("OPTIONS"), gotext.Get("OPTIONS"), gotext.Get("COPYRIGHT"))
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import (
|
|||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
|
|
||||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/config"
|
"gitea.plemya-x.ru/Plemya-x/ALR/internal/config"
|
||||||
|
"gitea.plemya-x.ru/Plemya-x/ALR/internal/fsutils"
|
||||||
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/alrsh"
|
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/alrsh"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -62,10 +63,10 @@ func (d *Database) Connect() error {
|
|||||||
dbDir := filepath.Dir(dsn)
|
dbDir := filepath.Dir(dsn)
|
||||||
if _, err := os.Stat(dbDir); err != nil {
|
if _, err := os.Stat(dbDir); err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
// Директория не существует - пытаемся создать
|
// Директория не существует - создаем автоматически
|
||||||
if mkErr := os.MkdirAll(dbDir, 0775); mkErr != nil {
|
slog.Info(gotext.Get("Cache directory does not exist, creating it"))
|
||||||
// Не смогли создать - вернём ошибку, пользователь должен использовать alr fix
|
if err := fsutils.EnsureTempDirWithRootOwner(dbDir, 0o2775); err != nil {
|
||||||
return fmt.Errorf("cache directory does not exist, please run 'alr fix' to create it: %w", mkErr)
|
return fmt.Errorf("failed to create cache directory: %w", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("failed to check database directory: %w", err)
|
return fmt.Errorf("failed to check database directory: %w", err)
|
||||||
|
|||||||
100
internal/fsutils/dirs.go
Normal file
100
internal/fsutils/dirs.go
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
// ALR - Any Linux Repository
|
||||||
|
// Copyright (C) 2025 The ALR Authors
|
||||||
|
//
|
||||||
|
// 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 fsutils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// EnsureTempDirWithRootOwner создает каталог в /tmp/alr или /var/cache/alr с правами для привилегированной группы
|
||||||
|
// Все каталоги в /tmp/alr и /var/cache/alr принадлежат root:привилегированная_группа с правами 2775
|
||||||
|
// Для других каталогов использует стандартные права
|
||||||
|
func EnsureTempDirWithRootOwner(path string, mode os.FileMode) error {
|
||||||
|
needsElevation := strings.HasPrefix(path, "/tmp/alr") || strings.HasPrefix(path, "/var/cache/alr")
|
||||||
|
|
||||||
|
if needsElevation {
|
||||||
|
// В CI или если мы уже root, не нужно использовать sudo
|
||||||
|
isRoot := os.Geteuid() == 0
|
||||||
|
isCI := os.Getenv("CI") == "true"
|
||||||
|
|
||||||
|
// В CI создаем директории с обычными правами
|
||||||
|
if isCI {
|
||||||
|
err := os.MkdirAll(path, mode)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// В CI не используем группу wheel и не меняем права
|
||||||
|
// Устанавливаем базовые права 777 для временных каталогов
|
||||||
|
chmodCmd := exec.Command("chmod", "777", path)
|
||||||
|
chmodCmd.Run() // Игнорируем ошибки
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Для обычной работы устанавливаем права и привилегированную группу
|
||||||
|
permissions := "2775"
|
||||||
|
group := GetPrivilegedGroup()
|
||||||
|
|
||||||
|
var mkdirCmd, chmodCmd, chownCmd *exec.Cmd
|
||||||
|
if isRoot {
|
||||||
|
// Выполняем команды напрямую без sudo
|
||||||
|
mkdirCmd = exec.Command("mkdir", "-p", path)
|
||||||
|
chmodCmd = exec.Command("chmod", permissions, path)
|
||||||
|
chownCmd = exec.Command("chown", "root:"+group, path)
|
||||||
|
} else {
|
||||||
|
// Используем sudo для всех операций с привилегированными каталогами
|
||||||
|
mkdirCmd = exec.Command("sudo", "mkdir", "-p", path)
|
||||||
|
chmodCmd = exec.Command("sudo", "chmod", permissions, path)
|
||||||
|
chownCmd = exec.Command("sudo", "chown", "root:"+group, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Создаем директорию через sudo если нужно
|
||||||
|
err := mkdirCmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
// Игнорируем ошибку если директория уже существует
|
||||||
|
if !isRoot {
|
||||||
|
// Проверяем существует ли директория
|
||||||
|
if _, statErr := os.Stat(path); statErr != nil {
|
||||||
|
return fmt.Errorf("не удалось создать директорию %s: %w", path, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Устанавливаем права с setgid битом для наследования группы
|
||||||
|
err = chmodCmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
if !isRoot {
|
||||||
|
return fmt.Errorf("не удалось установить права на %s: %w", path, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Устанавливаем владельца root:группа
|
||||||
|
err = chownCmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
if !isRoot {
|
||||||
|
return fmt.Errorf("не удалось установить владельца на %s: %w", path, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Для остальных каталогов обычное создание
|
||||||
|
return os.MkdirAll(path, mode)
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package utils
|
package fsutils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
@@ -47,9 +47,9 @@ func (rs *Repos) FindPkgs(ctx context.Context, pkgs []string) (map[string][]alrs
|
|||||||
name := parts[1]
|
name := parts[1]
|
||||||
result, err = rs.db.GetPkgs(ctx, "name = ? AND repository = ?", name, repo)
|
result, err = rs.db.GetPkgs(ctx, "name = ? AND repository = ?", name, repo)
|
||||||
|
|
||||||
case strings.Contains(pkgName, "+alr-"):
|
case strings.Contains(pkgName, "+"):
|
||||||
// pkg+alr-repo
|
// pkg+repo
|
||||||
parts := strings.SplitN(pkgName, "+alr-", 2)
|
parts := strings.SplitN(pkgName, "+", 2)
|
||||||
name := parts[0]
|
name := parts[0]
|
||||||
repo := parts[1]
|
repo := parts[1]
|
||||||
result, err = rs.db.GetPkgs(ctx, "name = ? AND repository = ?", name, repo)
|
result, err = rs.db.GetPkgs(ctx, "name = ? AND repository = ?", name, repo)
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import (
|
|||||||
"github.com/go-git/go-git/v5/plumbing"
|
"github.com/go-git/go-git/v5/plumbing"
|
||||||
"github.com/leonelquinteros/gotext"
|
"github.com/leonelquinteros/gotext"
|
||||||
"github.com/pelletier/go-toml/v2"
|
"github.com/pelletier/go-toml/v2"
|
||||||
"go.elara.ws/vercmp"
|
"gitea.plemya-x.ru/xpamych/vercmp"
|
||||||
"mvdan.cc/sh/v3/expand"
|
"mvdan.cc/sh/v3/expand"
|
||||||
"mvdan.cc/sh/v3/interp"
|
"mvdan.cc/sh/v3/interp"
|
||||||
"mvdan.cc/sh/v3/syntax"
|
"mvdan.cc/sh/v3/syntax"
|
||||||
@@ -420,13 +420,13 @@ func (rs *Repos) processRepoChanges(ctx context.Context, repo types.Repo, r *git
|
|||||||
case actionDelete:
|
case actionDelete:
|
||||||
scriptFl, err := oldCommit.File(action.File)
|
scriptFl, err := oldCommit.File(action.File)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Warn("Failed to get deleted file from old commit", "file", action.File, "error", err)
|
slog.Warn(gotext.Get("Failed to get deleted file from old commit"), "file", action.File, "error", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := scriptFl.Reader()
|
r, err := scriptFl.Reader()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Warn("Failed to read deleted file", "file", action.File, "error", err)
|
slog.Warn(gotext.Get("Failed to read deleted file"), "file", action.File, "error", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,13 +445,13 @@ func (rs *Repos) processRepoChanges(ctx context.Context, repo types.Repo, r *git
|
|||||||
case actionUpdate:
|
case actionUpdate:
|
||||||
scriptFl, err := newCommit.File(action.File)
|
scriptFl, err := newCommit.File(action.File)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Warn("Failed to get updated file from new commit", "file", action.File, "error", err)
|
slog.Warn(gotext.Get("Failed to get updated file from new commit"), "file", action.File, "error", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := scriptFl.Reader()
|
r, err := scriptFl.Reader()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Warn("Failed to read updated file", "file", action.File, "error", err)
|
slog.Warn(gotext.Get("Failed to read updated file"), "file", action.File, "error", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -505,7 +505,7 @@ func (rs *Repos) processRepoFull(ctx context.Context, repo types.Repo, repoDir s
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(matches) == 0 {
|
if len(matches) == 0 {
|
||||||
slog.Warn("No alr.sh files found in repository", "repo", repo.Name)
|
slog.Warn(gotext.Get("No alr.sh files found in repository"), "repo", repo.Name)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -341,7 +341,7 @@ msgstr "Выберите, какой пакет использовать для
|
|||||||
|
|
||||||
#: internal/cliutils/prompt.go:156
|
#: internal/cliutils/prompt.go:156
|
||||||
msgid "Choose which optional package(s) to install"
|
msgid "Choose which optional package(s) to install"
|
||||||
msgstr "Выберите, какой дополнительный пакет(ы) следует установить"
|
msgstr "Выберите дополнительные пакеты для установки"
|
||||||
|
|
||||||
#: internal/cliutils/template.go:74 internal/cliutils/template.go:93
|
#: internal/cliutils/template.go:74 internal/cliutils/template.go:93
|
||||||
msgid "NAME"
|
msgid "NAME"
|
||||||
@@ -501,10 +501,14 @@ msgstr "Аргументы, которые будут переданы мене
|
|||||||
msgid "Enable interactive questions and prompts"
|
msgid "Enable interactive questions and prompts"
|
||||||
msgstr "Включение интерактивных вопросов и запросов"
|
msgstr "Включение интерактивных вопросов и запросов"
|
||||||
|
|
||||||
#: main.go:148
|
#: main.go:147
|
||||||
msgid "Show help"
|
msgid "Show help"
|
||||||
msgstr "Показать справку"
|
msgstr "Показать справку"
|
||||||
|
|
||||||
|
#: main.go:148
|
||||||
|
msgid "Shows a list of commands or help for one command"
|
||||||
|
msgstr "Показывает список команд или справку по одной команде"
|
||||||
|
|
||||||
#: main.go:152
|
#: main.go:152
|
||||||
msgid "Error while running app"
|
msgid "Error while running app"
|
||||||
msgstr "Ошибка при запуске приложения"
|
msgstr "Ошибка при запуске приложения"
|
||||||
@@ -551,7 +555,7 @@ msgstr "<имя>"
|
|||||||
|
|
||||||
#: repo.go:103 repo.go:465 repo.go:568
|
#: repo.go:103 repo.go:465 repo.go:568
|
||||||
msgid "Repo \"%s\" does not exist"
|
msgid "Repo \"%s\" does not exist"
|
||||||
msgstr "Репозитория \"%s\" не существует"
|
msgstr "Репозиторий \"%s\" не существует"
|
||||||
|
|
||||||
#: repo.go:110
|
#: repo.go:110
|
||||||
msgid "Error removing repo directory"
|
msgid "Error removing repo directory"
|
||||||
@@ -620,7 +624,7 @@ msgstr "URL \"%s\" не существует в репозитории \"%s\""
|
|||||||
|
|
||||||
#: repo.go:508 repo.go:580
|
#: repo.go:508 repo.go:580
|
||||||
msgid "Removed %d mirrors from repo \"%s\"\n"
|
msgid "Removed %d mirrors from repo \"%s\"\n"
|
||||||
msgstr "Удалены зеркала %d из репозитория \"%s\"\n"
|
msgstr "Удалено %d зеркал из репозитория \"%s\"\n"
|
||||||
|
|
||||||
#: repo.go:520
|
#: repo.go:520
|
||||||
msgid "Remove all mirrors from the repository"
|
msgid "Remove all mirrors from the repository"
|
||||||
@@ -636,7 +640,7 @@ msgstr "URL-адрес нового репозитория"
|
|||||||
|
|
||||||
#: repo.go:632
|
#: repo.go:632
|
||||||
msgid "Name of the repo to be deleted"
|
msgid "Name of the repo to be deleted"
|
||||||
msgstr "Название репозитория удалён"
|
msgstr "Название репозитория для удаления"
|
||||||
|
|
||||||
#: search.go:40
|
#: search.go:40
|
||||||
msgid "Search packages"
|
msgid "Search packages"
|
||||||
@@ -656,7 +660,7 @@ msgstr "Искать по репозиторию"
|
|||||||
|
|
||||||
#: search.go:66
|
#: search.go:66
|
||||||
msgid "Search by provides"
|
msgid "Search by provides"
|
||||||
msgstr "Иcкать по provides"
|
msgstr "Искать по provides"
|
||||||
|
|
||||||
#: search.go:130
|
#: search.go:130
|
||||||
msgid "Error while executing search"
|
msgid "Error while executing search"
|
||||||
@@ -672,7 +676,107 @@ msgstr "Ошибка при проверке обновлений"
|
|||||||
|
|
||||||
#: upgrade.go:126
|
#: upgrade.go:126
|
||||||
msgid "There is nothing to do."
|
msgid "There is nothing to do."
|
||||||
msgstr "Здесь нечего делать."
|
msgstr "Действия не требуются."
|
||||||
|
|
||||||
|
#: internal/build/installer.go:88
|
||||||
|
msgid "Package %s is installed with older version %s, will rebuild with version %s"
|
||||||
|
msgstr "Пакет %s установлен с устаревшей версией %s, будет пересобран с версией %s"
|
||||||
|
|
||||||
|
#: internal/build/installer.go:96
|
||||||
|
msgid "Package %s is already installed with version %s, skipping build"
|
||||||
|
msgstr "Пакет %s уже установлен с версией %s, пропуск сборки"
|
||||||
|
|
||||||
|
#: internal/build/installer.go:102
|
||||||
|
msgid "Package %s is installed with newer version %s (repo has %s), skipping build"
|
||||||
|
msgstr "Пакет %s установлен с более новой версией %s (в репозитории %s), пропуск сборки"
|
||||||
|
|
||||||
|
#: internal/build/script_executor.go:170
|
||||||
|
msgid "Creating package file"
|
||||||
|
msgstr "Создание файла пакета"
|
||||||
|
|
||||||
|
#: internal/build/script_executor.go:174
|
||||||
|
msgid "Failed to create package file"
|
||||||
|
msgstr "Не удалось создать файл пакета"
|
||||||
|
|
||||||
|
#: internal/build/script_executor.go:179
|
||||||
|
msgid "Packaging with nfpm"
|
||||||
|
msgstr "Упаковка с помощью nfpm"
|
||||||
|
|
||||||
|
#: internal/build/script_executor.go:182
|
||||||
|
msgid "Failed to create package"
|
||||||
|
msgstr "Не удалось создать пакет"
|
||||||
|
|
||||||
|
#: internal/build/script_executor.go:186
|
||||||
|
msgid "Package created successfully"
|
||||||
|
msgstr "Пакет успешно создан"
|
||||||
|
|
||||||
|
#: internal/build/script_executor.go:190
|
||||||
|
msgid "Package file not found after creation"
|
||||||
|
msgstr "Файл пакета не найден после создания"
|
||||||
|
|
||||||
|
#: internal/build/script_executor.go:193
|
||||||
|
msgid "Package file verified to exist"
|
||||||
|
msgstr "Наличие файла пакета подтверждено"
|
||||||
|
|
||||||
|
#: internal/repos/pull.go:423
|
||||||
|
msgid "Failed to get deleted file from old commit"
|
||||||
|
msgstr "Не удалось получить удалённый файл из старого коммита"
|
||||||
|
|
||||||
|
#: internal/repos/pull.go:429
|
||||||
|
msgid "Failed to read deleted file"
|
||||||
|
msgstr "Не удалось прочитать удалённый файл"
|
||||||
|
|
||||||
|
#: internal/repos/pull.go:448
|
||||||
|
msgid "Failed to get updated file from new commit"
|
||||||
|
msgstr "Не удалось получить обновлённый файл из нового коммита"
|
||||||
|
|
||||||
|
#: internal/repos/pull.go:454
|
||||||
|
msgid "Failed to read updated file"
|
||||||
|
msgstr "Не удалось прочитать обновлённый файл"
|
||||||
|
|
||||||
|
#: internal/repos/pull.go:508
|
||||||
|
msgid "No alr.sh files found in repository"
|
||||||
|
msgstr "Файлы alr.sh не найдены в репозитории"
|
||||||
|
|
||||||
|
#: internal/cliutils/app_builder/builder.go:45
|
||||||
|
msgid "failed to close db"
|
||||||
|
msgstr "не удалось закрыть БД"
|
||||||
|
|
||||||
|
#: internal/build/build.go:342
|
||||||
|
msgid "Using cached package"
|
||||||
|
msgstr "Используется кешированный пакет"
|
||||||
|
|
||||||
|
#: upgrade.go:89
|
||||||
|
msgid "Updating system packages..."
|
||||||
|
msgstr "Обновление системных пакетов..."
|
||||||
|
|
||||||
|
#: upgrade.go:97
|
||||||
|
msgid "System packages updated successfully"
|
||||||
|
msgstr "Системные пакеты успешно обновлены"
|
||||||
|
|
||||||
|
#: build.go:203
|
||||||
|
msgid "Package file already moved or removed, skipping"
|
||||||
|
msgstr "Файл пакета уже перемещён или удалён, пропускаем"
|
||||||
|
|
||||||
|
#: fix.go:75
|
||||||
|
msgid "Clearing cache and temporary directories"
|
||||||
|
msgstr "Очистка кэша и временных директорий"
|
||||||
|
|
||||||
|
#: fix.go:119
|
||||||
|
msgid "Clearing temporary directory"
|
||||||
|
msgstr "Очистка временной директории"
|
||||||
|
|
||||||
|
#: fix.go:126
|
||||||
|
msgid "Unable to remove temporary directory as current user, trying with sudo"
|
||||||
|
msgstr "Невозможно удалить временную директорию от текущего пользователя, попытка через sudo"
|
||||||
|
|
||||||
|
#: fix.go:156
|
||||||
|
msgid "Fixing permissions on temporary files"
|
||||||
|
msgstr "Исправление прав доступа к временным файлам"
|
||||||
|
|
||||||
|
#: fix.go:177
|
||||||
|
msgid "Creating cache directory"
|
||||||
|
msgstr "Создание директории кэша"
|
||||||
|
|
||||||
#, fuzzy
|
#, fuzzy
|
||||||
#~ msgid "Failed to clear contents of cache directory"
|
#~ msgid "Failed to clear contents of cache directory"
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ package utils
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/user"
|
|
||||||
|
|
||||||
"github.com/leonelquinteros/gotext"
|
"github.com/leonelquinteros/gotext"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
@@ -33,40 +32,10 @@ func IsNotRoot() bool {
|
|||||||
return os.Getuid() != 0
|
return os.Getuid() != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnuseIsPrivilegedGroupMember проверяет, что пользователь является членом привилегированной группы (wheel)
|
// EnuseIsPrivilegedGroupMember проверяет, что пользователь является членом привилегированной группы (wheel/sudo)
|
||||||
|
// DEPRECATED: используйте CheckUserPrivileges() из utils.go
|
||||||
func EnuseIsPrivilegedGroupMember() error {
|
func EnuseIsPrivilegedGroupMember() error {
|
||||||
// В CI пропускаем проверку группы wheel
|
return CheckUserPrivileges()
|
||||||
if os.Getenv("CI") == "true" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Если пользователь root, пропускаем проверку
|
|
||||||
if os.Geteuid() == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
currentUser, err := user.Current()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
privilegedGroup := GetPrivilegedGroup()
|
|
||||||
group, err := user.LookupGroup(privilegedGroup)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
groups, err := currentUser.GroupIds()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, gid := range groups {
|
|
||||||
if gid == group.Gid {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cliutils.FormatCliExit(gotext.Get("You need to be a %s member to perform this action", privilegedGroup), nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func RootNeededAction(f cli.ActionFunc) cli.ActionFunc {
|
func RootNeededAction(f cli.ActionFunc) cli.ActionFunc {
|
||||||
|
|||||||
@@ -17,10 +17,11 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/user"
|
||||||
"strings"
|
|
||||||
|
|
||||||
|
"gitea.plemya-x.ru/Plemya-x/ALR/internal/fsutils"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -28,66 +29,71 @@ func NoNewPrivs() error {
|
|||||||
return unix.Prctl(unix.PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)
|
return unix.Prctl(unix.PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnsureTempDirWithRootOwner создает каталог в /tmp/alr с правами для привилегированной группы
|
// EnsureTempDirWithRootOwner создает каталог в /tmp/alr или /var/cache/alr с правами для привилегированной группы
|
||||||
// Все каталоги в /tmp/alr принадлежат root:привилегированная_группа с правами 775
|
// Обёртка для обратной совместимости, делегирует вызов в fsutils
|
||||||
// Для других каталогов использует стандартные права
|
|
||||||
func EnsureTempDirWithRootOwner(path string, mode os.FileMode) error {
|
func EnsureTempDirWithRootOwner(path string, mode os.FileMode) error {
|
||||||
if strings.HasPrefix(path, "/tmp/alr") {
|
return fsutils.EnsureTempDirWithRootOwner(path, mode)
|
||||||
// Сначала создаем директорию обычным способом
|
}
|
||||||
err := os.MkdirAll(path, mode)
|
|
||||||
if err != nil {
|
// GetPrivilegedGroup возвращает привилегированную группу для текущей системы
|
||||||
return err
|
// Обёртка для обратной совместимости, делегирует вызов в fsutils
|
||||||
}
|
func GetPrivilegedGroup() string {
|
||||||
|
return fsutils.GetPrivilegedGroup()
|
||||||
// В CI или если мы уже root, не нужно использовать sudo
|
}
|
||||||
isRoot := os.Geteuid() == 0
|
|
||||||
isCI := os.Getenv("CI") == "true"
|
// IsUserInGroup проверяет, состоит ли пользователь в указанной группе
|
||||||
|
func IsUserInGroup(username, groupname string) bool {
|
||||||
// В CI создаем директории с обычными правами
|
u, err := user.Lookup(username)
|
||||||
if isCI {
|
if err != nil {
|
||||||
// В CI не используем группу wheel и не меняем права
|
return false
|
||||||
// Устанавливаем базовые права 777 для временных каталогов
|
}
|
||||||
chmodCmd := exec.Command("chmod", "777", path)
|
|
||||||
chmodCmd.Run() // Игнорируем ошибки
|
groups, err := u.GroupIds()
|
||||||
return nil
|
if err != nil {
|
||||||
}
|
return false
|
||||||
|
}
|
||||||
// Для обычной работы устанавливаем права и привилегированную группу
|
|
||||||
permissions := "2775"
|
targetGroup, err := user.LookupGroup(groupname)
|
||||||
group := GetPrivilegedGroup()
|
if err != nil {
|
||||||
|
return false
|
||||||
var chmodCmd, chownCmd *exec.Cmd
|
}
|
||||||
if isRoot {
|
|
||||||
// Выполняем команды напрямую без sudo
|
for _, gid := range groups {
|
||||||
chmodCmd = exec.Command("chmod", permissions, path)
|
if gid == targetGroup.Gid {
|
||||||
chownCmd = exec.Command("chown", "root:"+group, path)
|
return true
|
||||||
} else {
|
}
|
||||||
// Используем sudo для обычных пользователей
|
}
|
||||||
chmodCmd = exec.Command("sudo", "chmod", permissions, path)
|
return false
|
||||||
chownCmd = exec.Command("sudo", "chown", "root:"+group, path)
|
}
|
||||||
}
|
|
||||||
|
// CheckUserPrivileges проверяет, что пользователь имеет необходимые привилегии для работы с ALR
|
||||||
// Устанавливаем права с setgid битом
|
// Пользователь должен быть root или состоять в группе wheel/sudo
|
||||||
err = chmodCmd.Run()
|
func CheckUserPrivileges() error {
|
||||||
if err != nil {
|
// Если пользователь root - все в порядке
|
||||||
// Для root игнорируем ошибки, если группа не существует
|
if os.Geteuid() == 0 {
|
||||||
if !isRoot {
|
return nil
|
||||||
return err
|
}
|
||||||
}
|
|
||||||
}
|
// В CI не проверяем привилегии
|
||||||
|
if os.Getenv("CI") == "true" {
|
||||||
// Устанавливаем владельца root:wheel
|
return nil
|
||||||
err = chownCmd.Run()
|
}
|
||||||
if err != nil {
|
|
||||||
// Для root игнорируем ошибки, если группа не существует
|
currentUser, err := user.Current()
|
||||||
if !isRoot {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("не удалось получить информацию о текущем пользователе: %w", err)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
privilegedGroup := fsutils.GetPrivilegedGroup()
|
||||||
return nil
|
|
||||||
}
|
// Проверяем членство в привилегированной группе
|
||||||
|
if !IsUserInGroup(currentUser.Username, privilegedGroup) {
|
||||||
// Для остальных каталогов обычное создание
|
return fmt.Errorf("пользователь %s не имеет необходимых привилегий для работы с ALR.\n"+
|
||||||
return os.MkdirAll(path, mode)
|
"Для работы с ALR необходимо быть пользователем root или состоять в группе %s.\n"+
|
||||||
|
"Выполните команду: sudo usermod -a -G %s %s\n"+
|
||||||
|
"Затем перезайдите в систему или выполните: newgrp %s",
|
||||||
|
currentUser.Username, privilegedGroup, privilegedGroup, currentUser.Username, privilegedGroup)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
18
main.go
18
main.go
@@ -50,6 +50,22 @@ func VersionCmd() *cli.Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func HelpCmd() *cli.Command {
|
||||||
|
return &cli.Command{
|
||||||
|
Name: "help",
|
||||||
|
Aliases: []string{"h"},
|
||||||
|
Usage: gotext.Get("Shows a list of commands or help for one command"),
|
||||||
|
ArgsUsage: "[command]",
|
||||||
|
Action: func(cCtx *cli.Context) error {
|
||||||
|
args := cCtx.Args()
|
||||||
|
if args.Present() {
|
||||||
|
return cli.ShowCommandHelp(cCtx, args.First())
|
||||||
|
}
|
||||||
|
return cli.ShowAppHelp(cCtx)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func GetApp() *cli.App {
|
func GetApp() *cli.App {
|
||||||
return &cli.App{
|
return &cli.App{
|
||||||
Name: "alr",
|
Name: "alr",
|
||||||
@@ -88,6 +104,7 @@ func GetApp() *cli.App {
|
|||||||
InternalBuildCmd(),
|
InternalBuildCmd(),
|
||||||
InternalInstallCmd(),
|
InternalInstallCmd(),
|
||||||
InternalReposCmd(),
|
InternalReposCmd(),
|
||||||
|
HelpCmd(),
|
||||||
},
|
},
|
||||||
Before: func(c *cli.Context) error {
|
Before: func(c *cli.Context) error {
|
||||||
if trimmed := strings.TrimSpace(c.String("pm-args")); trimmed != "" {
|
if trimmed := strings.TrimSpace(c.String("pm-args")); trimmed != "" {
|
||||||
@@ -144,6 +161,7 @@ func main() {
|
|||||||
// Make the application more internationalized
|
// Make the application more internationalized
|
||||||
cli.AppHelpTemplate = cliutils.GetAppCliTemplate()
|
cli.AppHelpTemplate = cliutils.GetAppCliTemplate()
|
||||||
cli.CommandHelpTemplate = cliutils.GetCommandHelpTemplate()
|
cli.CommandHelpTemplate = cliutils.GetCommandHelpTemplate()
|
||||||
|
cli.SubcommandHelpTemplate = cliutils.GetSubcommandHelpTemplate()
|
||||||
cli.HelpFlag.(*cli.BoolFlag).Usage = gotext.Get("Show help")
|
cli.HelpFlag.(*cli.BoolFlag).Usage = gotext.Get("Show help")
|
||||||
|
|
||||||
err = app.RunContext(ctx, os.Args)
|
err = app.RunContext(ctx, os.Args)
|
||||||
|
|||||||
@@ -1,19 +1,3 @@
|
|||||||
// ALR - Any Linux Repository
|
|
||||||
// Copyright (C) 2025 The ALR Authors
|
|
||||||
//
|
|
||||||
// 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/>.
|
|
||||||
|
|
||||||
// DO NOT EDIT MANUALLY. This file is generated.
|
// DO NOT EDIT MANUALLY. This file is generated.
|
||||||
package alrsh
|
package alrsh
|
||||||
|
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ import (
|
|||||||
|
|
||||||
// createDir создает директорию с правильными правами для production
|
// createDir создает директорию с правильными правами для production
|
||||||
func createDir(itemPath string, mode os.FileMode) error {
|
func createDir(itemPath string, mode os.FileMode) error {
|
||||||
// Используем специальную функцию для создания каталогов с setgid битом только для /tmp/alr
|
// Используем специальную функцию для создания каталогов с setgid битом только для /tmp/alr/ и /var/cache/alr/
|
||||||
// В остальных случаях используем обычное создание директории
|
// Проверяем с слешем в конце, чтобы исключить тестовые директории вроде /tmp/alr-test-XXX
|
||||||
if strings.HasPrefix(itemPath, "/tmp/alr") {
|
if strings.HasPrefix(itemPath, "/tmp/alr/") || strings.HasPrefix(itemPath, "/var/cache/alr/") {
|
||||||
return utils.EnsureTempDirWithRootOwner(itemPath, mode)
|
return utils.EnsureTempDirWithRootOwner(itemPath, mode)
|
||||||
} else {
|
} else {
|
||||||
return os.MkdirAll(itemPath, mode)
|
return os.MkdirAll(itemPath, mode)
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
appbuilder "gitea.plemya-x.ru/Plemya-x/ALR/internal/cliutils/app_builder"
|
appbuilder "gitea.plemya-x.ru/Plemya-x/ALR/internal/cliutils/app_builder"
|
||||||
|
"gitea.plemya-x.ru/Plemya-x/ALR/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RefreshCmd() *cli.Command {
|
func RefreshCmd() *cli.Command {
|
||||||
@@ -29,6 +30,9 @@ func RefreshCmd() *cli.Command {
|
|||||||
Usage: gotext.Get("Pull all repositories that have changed"),
|
Usage: gotext.Get("Pull all repositories that have changed"),
|
||||||
Aliases: []string{"ref"},
|
Aliases: []string{"ref"},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
|
if err := utils.CheckUserPrivileges(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
ctx := c.Context
|
ctx := c.Context
|
||||||
|
|
||||||
|
|||||||
36
repo.go
36
repo.go
@@ -46,6 +46,24 @@ func RepoCmd() *cli.Command {
|
|||||||
SetRepoRefCmd(),
|
SetRepoRefCmd(),
|
||||||
RepoMirrorCmd(),
|
RepoMirrorCmd(),
|
||||||
SetUrlCmd(),
|
SetUrlCmd(),
|
||||||
|
RepoHelpCmd(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func RepoHelpCmd() *cli.Command {
|
||||||
|
return &cli.Command{
|
||||||
|
Name: "help",
|
||||||
|
Aliases: []string{"h"},
|
||||||
|
Usage: gotext.Get("Shows a list of commands or help for one command"),
|
||||||
|
ArgsUsage: "[command]",
|
||||||
|
Action: func(cCtx *cli.Context) error {
|
||||||
|
args := cCtx.Args()
|
||||||
|
if args.Present() {
|
||||||
|
return cli.ShowCommandHelp(cCtx, args.First())
|
||||||
|
}
|
||||||
|
cli.ShowSubcommandHelp(cCtx)
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -331,6 +349,24 @@ func RepoMirrorCmd() *cli.Command {
|
|||||||
AddMirror(),
|
AddMirror(),
|
||||||
RemoveMirror(),
|
RemoveMirror(),
|
||||||
ClearMirrors(),
|
ClearMirrors(),
|
||||||
|
MirrorHelpCmd(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func MirrorHelpCmd() *cli.Command {
|
||||||
|
return &cli.Command{
|
||||||
|
Name: "help",
|
||||||
|
Aliases: []string{"h"},
|
||||||
|
Usage: gotext.Get("Shows a list of commands or help for one command"),
|
||||||
|
ArgsUsage: "[command]",
|
||||||
|
Action: func(cCtx *cli.Context) error {
|
||||||
|
args := cCtx.Args()
|
||||||
|
if args.Present() {
|
||||||
|
return cli.ShowCommandHelp(cCtx, args.First())
|
||||||
|
}
|
||||||
|
cli.ShowSubcommandHelp(cCtx)
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
21
upgrade.go
21
upgrade.go
@@ -26,7 +26,7 @@ import (
|
|||||||
|
|
||||||
"github.com/leonelquinteros/gotext"
|
"github.com/leonelquinteros/gotext"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"go.elara.ws/vercmp"
|
"gitea.plemya-x.ru/xpamych/vercmp"
|
||||||
"golang.org/x/exp/maps"
|
"golang.org/x/exp/maps"
|
||||||
|
|
||||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/build"
|
"gitea.plemya-x.ru/Plemya-x/ALR/internal/build"
|
||||||
@@ -114,7 +114,7 @@ func UpgradeCmd() *cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(updates) > 0 {
|
if len(updates) > 0 {
|
||||||
err = builder.InstallALRPackages(
|
_, err = builder.InstallPkgs(
|
||||||
ctx,
|
ctx,
|
||||||
&build.BuildArgs{
|
&build.BuildArgs{
|
||||||
Opts: &types.BuildOpts{
|
Opts: &types.BuildOpts{
|
||||||
@@ -124,7 +124,7 @@ func UpgradeCmd() *cli.Command {
|
|||||||
Info: deps.Info,
|
Info: deps.Info,
|
||||||
PkgFormat_: build.GetPkgFormat(deps.Manager),
|
PkgFormat_: build.GetPkgFormat(deps.Manager),
|
||||||
},
|
},
|
||||||
mapUptatesInfoToPackages(updates),
|
mapUpdatesToPackageNames(updates),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cliutils.FormatCliExit(gotext.Get("Error checking for updates"), err)
|
return cliutils.FormatCliExit(gotext.Get("Error checking for updates"), err)
|
||||||
@@ -138,12 +138,19 @@ func UpgradeCmd() *cli.Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mapUptatesInfoToPackages(updates []UpdateInfo) []alrsh.Package {
|
func mapUpdatesToPackageNames(updates []UpdateInfo) []string {
|
||||||
var pkgs []alrsh.Package
|
seen := make(map[string]bool)
|
||||||
|
var pkgNames []string
|
||||||
|
|
||||||
for _, info := range updates {
|
for _, info := range updates {
|
||||||
pkgs = append(pkgs, *info.Package)
|
fullName := fmt.Sprintf("%s+%s", info.Package.Name, info.Package.Repository)
|
||||||
|
if !seen[fullName] {
|
||||||
|
seen[fullName] = true
|
||||||
|
pkgNames = append(pkgNames, fullName)
|
||||||
}
|
}
|
||||||
return pkgs
|
}
|
||||||
|
|
||||||
|
return pkgNames
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateInfo struct {
|
type UpdateInfo struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user