From c7cbc0d3779f88d6a53dcb727a1756530dac5c8d Mon Sep 17 00:00:00 2001 From: Herpiko Dwi Aguno Date: Mon, 26 Apr 2021 03:39:52 +0000 Subject: [PATCH] Fix #120 Allow to build base.tgz with our own internal repo. --- cmd/builder/init.go | 15 ++++++++++++--- cmd/builder/main.go | 10 ++++++++-- internal/config/config.go | 1 + utils/config.yml | 1 + 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/cmd/builder/init.go b/cmd/builder/init.go index f948a8c..79b3384 100644 --- a/cmd/builder/init.go +++ b/cmd/builder/init.go @@ -10,7 +10,7 @@ import ( "github.com/manifoldco/promptui" ) -func InitBase() (err error) { +func InitBase(useInternalRepo bool) (err error) { logPath := irgshConfig.Builder.Workdir logPath += "/irgsh-builder-init-base-" + uuid.New().String() + ".log" go systemutil.StreamLog(logPath) @@ -62,8 +62,17 @@ func InitBase() (err error) { fmt.Printf("error: %v\n", err) return } + + // Determine the upstream repo + upstreamDistUrl := irgshConfig.Repo.UpstreamDistUrl + upstreamDistCodename := irgshConfig.Repo.UpstreamDistCodename + if useInternalRepo { + upstreamDistUrl = irgshConfig.Repo.DistUrl // Use internal repo + upstreamDistCodename = irgshConfig.Repo.DistCodename + } + cmdStr = "pbuilder create --debootstrapopts --variant=buildd" - if strings.Contains(irgshConfig.Repo.UpstreamDistUrl, "debian") && (strings.Contains(distribution, "Ubuntu") || + if (strings.Contains(upstreamDistUrl, "debian") || strings.Contains(upstreamDistUrl, "blankon")) && (strings.Contains(distribution, "Ubuntu") || strings.Contains(distribution, "Pop")) { _, err = systemutil.CmdExec( "apt-get update && apt-get -y install debian-archive-keyring", @@ -74,7 +83,7 @@ func InitBase() (err error) { fmt.Printf("error: %v\n", err) return } - cmdStr = "pbuilder create --distribution " + irgshConfig.Repo.UpstreamDistCodename + " --mirror " + irgshConfig.Repo.UpstreamDistUrl + " --debootstrapopts \"--keyring=/usr/share/keyrings/debian-archive-keyring.gpg\"" + cmdStr = "pbuilder create --distribution " + upstreamDistCodename + " --mirror " + upstreamDistUrl + " --debootstrapopts \"--keyring=/usr/share/keyrings/debian-archive-keyring.gpg\"" } _, err = systemutil.CmdExec( cmdStr, diff --git a/cmd/builder/main.go b/cmd/builder/main.go index 69ee946..5b87f81 100644 --- a/cmd/builder/main.go +++ b/cmd/builder/main.go @@ -56,8 +56,14 @@ func main() { Name: "init-base", Aliases: []string{"i"}, Usage: "Initialize pbuilder base.tgz. This need to be run under sudo or root", - Action: func(c *cli.Context) error { - err := InitBase() + Flags: []cli.Flag{ + cli.BoolFlag{ + Name: "internalrepo", + Usage: "Use internal repo", + }, + }, + Action: func(ctx *cli.Context) error { + err := InitBase(ctx.Bool("internalrepo")) return err }, }, diff --git a/internal/config/config.go b/internal/config/config.go index 5013db0..440c0db 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -50,6 +50,7 @@ type RepoConfig struct { UpstreamDistUrl string `json:"upstream_dist_url" validate:"required"` // http://kartolo.sby.datautama.net.id/debian UpstreamDistComponents string `json:"upstream_dist_components" validate:"required"` // main non-free>restricted contrib>extras GnupgDir string `json:"gnupg_dir" validate:"required"` // GNUPG dir path + DistUrl string `json:"dist_url" validate:"required"` // http://arsip-dev.blankonlinux.or.id/blankon } // LoadConfig load irgsh config from file diff --git a/utils/config.yml b/utils/config.yml index b242a9a..173d105 100644 --- a/utils/config.yml +++ b/utils/config.yml @@ -25,6 +25,7 @@ repo: upstream_dist_url: 'http://kartolo.sby.datautama.net.id/debian' upstream_dist_components: 'main non-free>restricted contrib>extras' gnupg_dir: '/var/lib/irgsh/gnupg' + dist_url: 'http://arsip-dev.blankonlinux.or.id/blankon' iso: workdir: '/var/lib/irgsh/iso'