Skip to content

Commit

Permalink
actions: debootstrap: Determine default script based on suite/parent-…
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
obbardc committed Jan 10, 2024
1 parent cb59e3c commit 351da8c
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions actions/debootstrap_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 351da8c

Please sign in to comment.