|
| 1 | +package profile |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "log/slog" |
| 6 | + "os" |
| 7 | + "path" |
| 8 | + |
| 9 | + "github.com/FascodeNet/alterlinux/src/internal/archiso" |
| 10 | + "github.com/FascodeNet/alterlinux/src/internal/errors" |
| 11 | + "github.com/Hayao0819/nahi/exutils" |
| 12 | + "github.com/spf13/cobra" |
| 13 | +) |
| 14 | + |
| 15 | +func buildCmd() *cobra.Command { |
| 16 | + outDir := "./out" |
| 17 | + cmd := cobra.Command{ |
| 18 | + Use: "build", |
| 19 | + Short: "Build the ISO from generated profile", |
| 20 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 21 | + configDir := args[0] |
| 22 | + configName := path.Base(configDir) |
| 23 | + |
| 24 | + bootloadersPath := cmd.Parent().PersistentFlags().Lookup("bootloaders").Value.String() |
| 25 | + modulesPath := cmd.Parent().PersistentFlags().Lookup("modules").Value.String() |
| 26 | + |
| 27 | + profile, err := archiso.NewProfile(configDir, bootloadersPath, modulesPath) |
| 28 | + if err != nil { |
| 29 | + return err |
| 30 | + } |
| 31 | + |
| 32 | + profileDir, err := os.MkdirTemp("", fmt.Sprintf("alteriso-%s-*", configName)) |
| 33 | + if err != nil { |
| 34 | + return errors.Wrap(err) |
| 35 | + } |
| 36 | + defer os.RemoveAll(profileDir) |
| 37 | + |
| 38 | + if err := profile.GenArchisoProfile(profileDir); err != nil { |
| 39 | + return errors.Wrap(err) |
| 40 | + } |
| 41 | + |
| 42 | + slog.Info("Generated archiso profile", "dir", profileDir) |
| 43 | + |
| 44 | + mkarchiso, err := archiso.MkarchisoPath() |
| 45 | + if err != nil { |
| 46 | + return errors.Wrap(err) |
| 47 | + } |
| 48 | + |
| 49 | + if err := exutils.CommandWithStdio(mkarchiso, "-v", "-w", "work", "-o", outDir, profileDir).Run(); err != nil { |
| 50 | + return errors.Wrap(err) |
| 51 | + } |
| 52 | + |
| 53 | + return nil |
| 54 | + |
| 55 | + }, |
| 56 | + } |
| 57 | + |
| 58 | + cmd.Flags().StringVarP(&outDir, "out", "o", outDir, "Output directory") |
| 59 | + |
| 60 | + return &cmd |
| 61 | + |
| 62 | +} |
| 63 | + |
| 64 | +func init() { |
| 65 | + profileReg.Add(buildCmd()) |
| 66 | +} |
0 commit comments