From 351da8c0eb51b89283c5caadd47511a9a3e67757 Mon Sep 17 00:00:00 2001 From: Christopher Obbard Date: Thu, 10 Aug 2023 10:47:11 +0100 Subject: [PATCH] actions: debootstrap: Determine default script based on suite/parent-suite If the debootstrap script property is unspecified, set the script to be the suite property, falling back to the parent suite if the script doesn't exist and finally falling back to unstable if the parent suite doesn't have a custom script. Signed-off-by: Christopher Obbard --- actions/debootstrap_action.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/actions/debootstrap_action.go b/actions/debootstrap_action.go index 775393f5..4b9d3b72 100644 --- a/actions/debootstrap_action.go +++ b/actions/debootstrap_action.go @@ -51,11 +51,14 @@ Example: not use debian codenames for their suite names (e.g. "stable"). - script -- the full path of the script to use to build the target rootfs. (e.g. `/usr/share/debootstrap/scripts/kali`) - If unspecified, the property will be set to use the `unstable` script. + If unspecified, the property will be automatically determined in the following order, + with the path "/usr/share/debootstrap/scripts/" prepended: + `suite` property, `parent-suite` property then `unstable`. */ package actions import ( + "errors" "fmt" "io" "log" @@ -193,6 +196,10 @@ func shouldExcludeUsrIsMerged(suite string) bool { } } +func getDebootstrapScriptPath(script string) string { + return path.Join("/usr/share/debootstrap/scripts/", script) +} + func (d *DebootstrapAction) Run(context *debos.DebosContext) error { cmdline := []string{"debootstrap"} @@ -252,7 +259,24 @@ func (d *DebootstrapAction) Run(context *debos.DebosContext) error { return fmt.Errorf("cannot find debootstrap script %s", d.Script) } } else { - d.Script = "/usr/share/debootstrap/scripts/unstable" + /* Auto determine debootstrap script to use from d.Suite, falling back to + d.ParentSuite if it doesn't exist. Finally, fallback to unstable if a + script for the parent suite does not exist. */ + for _, s := range []string{d.Suite, d.ParentSuite, "unstable"} { + d.Script = getDebootstrapScriptPath(s) + if _, err := os.Stat(d.Script); err == nil { + break + } else { + log.Printf("cannot find debootstrap script %s\n", d.Script) + + /* Unstable should always be available so error out if not */ + if s == "unstable" { + return errors.New("cannot find debootstrap script for unstable") + } + } + } + + log.Printf("using debootstrap script %s\n", d.Script) } cmdline = append(cmdline, d.Script)