Skip to content

Commit 9c6cbef

Browse files
committed
feat: Add --noconfirm for auto build
1 parent 82bdc74 commit 9c6cbef

8 files changed

Lines changed: 43 additions & 26 deletions

File tree

‎CLAUDE.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Build requires root privileges. Output goes to `alteriso/out/`, work directory i
5151
### Injectable Mechanism
5252

5353
AlterISO leverages archiso's `_run_once()` function which sources `profiledef.sh`. Generated `profiledef.sh` includes:
54+
5455
- Pre/post hooks: `pre_<function>()`, `post_<function>()`
5556
- Override hooks: `override_<function>()`
5657
- Example: `post__make_packages()`, `pre__make_customize_airootfs()`
@@ -69,6 +70,7 @@ modules/<name>/
6970
### Profile Configuration
7071

7172
`profiledef.json` fields:
73+
7274
- `arch` (required): Target architecture (currently "x86_64")
7375
- `modules` (required): List of modules to load in order
7476
- `os_name`, `kernel_name`, `username`, `cow_spacesize`: Optional config

‎alteriso/src/internal/archiso/injects/loader.sh‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ __alteriso_injected_list() {
3232
fi
3333
done < <(compgen -v)
3434

35-
local _a _a_org
36-
while read -r _a; do
37-
_a_org=$(echo "${_a}" | sed -E 's/^(pre|post|override)_(.+)$/\2/')
38-
if printf '%s\n' "${_funcs[@]}" | grep -qx -- "$_a_org"; then
39-
_msg_info "Injected as array: $_a"
40-
fi
41-
done < <(printf '%s\n' "${_arrays[@]}" | grep -E -- '^(pre|post|override)_(.+)$' | sort -u)
35+
local _a _a_org
36+
while read -r _a; do
37+
_a_org=$(echo "${_a}" | sed -E 's/^(pre|post|override)_(.+)$/\2/')
38+
if printf '%s\n' "${_funcs[@]}" | grep -qx -- "$_a_org"; then
39+
_msg_info "Injected as array: $_a"
40+
fi
41+
done < <(printf '%s\n' "${_arrays[@]}" | grep -E -- '^(pre|post|override)_(.+)$' | sort -u)
4242
}
4343

4444
__alteriso_cleanup() {
@@ -197,16 +197,17 @@ __alteriso_show_config() {
197197
_kernel_name=$(__alteriso_profiledef_kernelname)
198198
_arch=$(__alteriso_profiledef_arch)
199199
200-
echo "[alteriso] INFO: Architecture: $_arch"
201-
echo "[alteriso] INFO: Username: $_username"
202-
echo "[alteriso] INFO: Kernel Name: $_kernel_name"
203-
echo "[alteriso] INFO: Profile Directory: $__alteriso_profile_dir"
200+
echo "[alteriso] INFO: Architecture: $_arch" >&2
201+
echo "[alteriso] INFO: Username: $_username" >&2
202+
echo "[alteriso] INFO: Kernel Name: $_kernel_name" >&2
203+
echo "[alteriso] INFO: Profile Directory: $__alteriso_profile_dir" >&2
204204
205-
echo -n "[alteriso] Are you sure to continue? (y/N): "
205+
echo -n "[alteriso] Are you sure to continue? (y/N): " >&2
206206
read -r answer
207-
if [[ "$answer" != "y" && "$answer" != "Y" ]]; then
207+
208+
if [[ "${answer,,}" = "y" ]]; then
208209
echo "[alteriso] Aborted."
209-
exit 0
210+
exit 1
210211
fi
211212
}
212213
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
#!/usr/bin/env bash
22
# shellcheck disable=all
33

4+
# Initial loader
45
{{ .LoaderContent }}
56

67
__alteriso_loadfile "$__alteriso_profile_dir/injecter.sh"
78

8-
{{ range $index, $module := .EmbedScripts }}
9+
# Function defines
10+
{{- range $index, $module := .EmbedScripts }}
911
{{ inject_script $module }}
1012
{{ end }}
11-
12-
{{- range $func, $codes := .Injects -}}
13+
# Inject Array
14+
{{ range $func, $codes := .Injects -}}
1315
{{- $func }}{{ "+=(" }}
1416
{{- range $index, $code := $codes -}}
1517
{{- $code }}
1618
{{- end -}}
1719
{{ ")" }}
1820
{{ end -}}
19-
21+
# Variable defines
2022
{{ .ProfileDefContent }}
21-
23+
# Validate alteriso profiles
2224
__alteriso_validate
2325
__alteriso_validate_profile
24-
2526
{{ if .RequireInjectable -}}
2627
__alteriso_require_injectable
2728
{{- end }}
@@ -32,4 +33,6 @@ if [[ "$__alteriso_compatible_mode" = "y" ]]; then
3233
return 0
3334
fi
3435
__alteriso_injected_list
36+
{{- if not .NoConfirm }}
3537
__alteriso_show_config
38+
{{- end }}

‎alteriso/src/internal/archiso/profile_def.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,14 @@ func (p *Profile) ProfileDefSh() ([]byte, error) {
7474
EmbedScripts []string
7575
Injects map[string][]string
7676
RequireInjectable bool
77+
NoConfirm bool
7778
}{
7879
LoaderContent: string(loaderContent),
7980
ProfileDefContent: string(profileDef),
8081
EmbedScripts: embedScripts,
8182
Injects: injects,
8283
RequireInjectable: p.Config.RequireInjectable,
84+
NoConfirm: p.NoConfirm,
8385
}
8486

8587
profileDefContent, err := profileDefTemplate()

‎alteriso/src/internal/archiso/profile_new.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ type profileOption func(*Profile) error
1616
// }
1717
// }
1818

19+
func WithNoConfirm(f bool) profileOption {
20+
return func(p *Profile) error {
21+
p.NoConfirm = f
22+
return nil
23+
}
24+
}
25+
1926
func WithModulesPath(dir string) profileOption {
2027
return func(p *Profile) error {
2128
p.ModulesPath = dir

‎alteriso/src/internal/archiso/profile_struct.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type Profile struct {
66
Path string
77
BootloadersPath string
88
ModulesPath string
9+
NoConfirm bool
910
}
1011

1112
type ProfileDef struct {

‎alteriso/src/internal/cmd/profile/generate.go‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package profile
33
import (
44
"log/slog"
55
"os"
6-
"path"
76

87
"github.com/FascodeNet/alterlinux/src/internal/archiso"
98
"github.com/FascodeNet/alterlinux/src/internal/errors"
@@ -38,27 +37,27 @@ func generateCmd() *cobra.Command {
3837

3938
bootloadersPath := cmd.Parent().PersistentFlags().Lookup("bootloaders").Value.String()
4039
modulesPath := cmd.Parent().PersistentFlags().Lookup("modules").Value.String()
40+
noConfirm := cmd.Parent().PersistentFlags().Lookup("noconfirm").Changed
4141

4242
profile, err := archiso.NewProfile(configDir,
4343
archiso.WithModulesPath(modulesPath),
4444
archiso.WithbootloadersPath(bootloadersPath),
45+
archiso.WithNoConfirm(noConfirm),
4546
// archiso.WithPacmanCacheDir(pacmanCacheDir),
4647
)
4748
if err != nil {
4849
return err
4950
}
5051

51-
// dstDir := path.Join(outDir, configName)
52-
dstDir := path.Join(outDir)
53-
if futils.Exists(dstDir) {
52+
if futils.Exists(outDir) {
5453
return errors.New("output directory already exists")
5554
}
5655

57-
if err := profile.GenArchisoProfile(dstDir); err != nil {
56+
if err := profile.GenArchisoProfile(outDir); err != nil {
5857
return errors.Wrap(err)
5958
}
6059

61-
slog.Info("Generated archiso profile", "dir", dstDir)
60+
slog.Info("Generated archiso profile", "dir", outDir)
6261

6362
return nil
6463
},

‎alteriso/src/internal/cmd/profile/root.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var profileReg = cobrautils.Registory{}
1010
func Cmd() *cobra.Command {
1111
bootloadersPath := "/usr/share/alteriso/bootloaders"
1212
modulesPath := "/usr/share/alteriso/modules/"
13+
noconfirm := false
1314

1415
cmd := &cobra.Command{
1516
Use: "profile",
@@ -18,6 +19,7 @@ func Cmd() *cobra.Command {
1819

1920
cmd.PersistentFlags().StringVarP(&modulesPath, "modules", "", modulesPath, "Path to modules config dir")
2021
cmd.PersistentFlags().StringVarP(&bootloadersPath, "bootloaders", "", bootloadersPath, "Path to bootloaders config dir")
22+
cmd.PersistentFlags().BoolVarP(&noconfirm, "noconfirm", "", noconfirm, "No check the settings before building")
2123

2224
profileReg.Bind(cmd)
2325
return cmd

0 commit comments

Comments
 (0)