add an example to build a custom .deb

This commit is contained in:
Jeff Carr 2024-11-16 09:49:49 -06:00
parent d45037dee9
commit 526605ff87
8 changed files with 72 additions and 30 deletions

View File

@ -36,9 +36,10 @@ reset:
# clear your terminal # clear your terminal
reset reset
gocui: build # use the ncurses gui (only kinda works still)
ncurses: build
reset reset
./go-deb --gui gocui >/tmp/witgui.log.stderr 2>&1 ./go-deb --gui gocui
nocui: reset build nocui: reset build
./go-deb --gui nocui ./go-deb --gui nocui

View File

@ -42,7 +42,12 @@ func (c *controlBox) buildPackage() (bool, error) {
fulldebname := filepath.Join(homeDir, "incoming", debname) fulldebname := filepath.Join(homeDir, "incoming", debname)
if shell.Exists(fulldebname) { if shell.Exists(fulldebname) {
log.Info("debian package already built: " + fulldebname) log.Info("debian package already built: " + fulldebname)
return true, errors.New("debian package already built: " + fulldebname) if argv.Auto {
return true, errors.New("debian package already built: " + fulldebname)
} else {
return false, errors.New("debian package already built: " + fulldebname)
}
} }
var fullfilename string var fullfilename string
@ -132,13 +137,17 @@ func (c *controlBox) buildPackage() (bool, error) {
log.Warn("mkdir failed") log.Warn("mkdir failed")
return false, errors.New("mkdir files/usr/bin") return false, errors.New("mkdir files/usr/bin")
} }
if r := shell.Run([]string{"cp", fullfilename, "files/usr/bin"}); r.Error != nil { if os.Getenv("GO_DEB_CUSTOM") == "true" {
log.Warn("cp failed") // skip cp & strip on custom 'control' files
return false, r.Error } else {
} if r := shell.Run([]string{"cp", fullfilename, "files/usr/bin"}); r.Error != nil {
if r := shell.Run([]string{"strip", "files/usr/bin/" + filename}); r.Error != nil { log.Warn("cp failed")
log.Warn("strip failed") return false, r.Error
return false, r.Error }
if r := shell.Run([]string{"strip", "files/usr/bin/" + filename}); r.Error != nil {
log.Warn("strip failed")
return false, r.Error
}
} }
// put the README in there (if missing, generate it?) // put the README in there (if missing, generate it?)
@ -168,19 +177,10 @@ func (c *controlBox) buildPackage() (bool, error) {
shell.Run([]string{"cp", "postinst", "files/DEBIAN/"}) shell.Run([]string{"cp", "postinst", "files/DEBIAN/"})
} }
if c.status == nil {
log.Warn("c.status == nil")
panic(-1)
}
// experiment for the toolkit package // experiment for the toolkit package
// if the git repo has a "./build" script run it before packaging // if the git repo has a "./build" script run it before packaging
// this way the user can put custom files in the .deb package // this way the user can put custom files in the .deb package
if c.status.Exists("build") { if shell.Exists("build") {
if argv.Release {
os.Unsetenv("GO111MODULE")
} else {
os.Setenv("GO111MODULE", "off")
}
shell.Run([]string{"./build"}) shell.Run([]string{"./build"})
} }

View File

@ -0,0 +1,6 @@
.PHONY: build
all: build
build:
go-deb --repo .

10
examples/protoc-gen-go/build Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash -x
# this is the new protobuf generator
#
# go-clone google.golang.org/protobuf
# cd ~/go/src/google.golang.org/protobuf/cmd/protoc-gen-go
# go install
mkdir -p files/usr/bin
cp ~/go/bin/protoc-gen-go files/usr/bin

View File

@ -0,0 +1,12 @@
Source: google.golang.org.protobuf
Build-Depends: golang
Package: protoc-gen-go-new
Maintainer: Jeff Carr <jcarr@wit.com>
Packager: Jeff Carr <jcarr@wit.com>
Architecture: amd64
Depends:
URL: https://go.wit.com/
Recommends:
Version: 0.1
Description: protoc-gen-go from google.golang.org/protobuf
You need this one until the debian sid packages are updated

30
main.go
View File

@ -35,7 +35,7 @@ func main() {
os.Exit(0) os.Exit(0)
} }
myGui = gui.New() myGui = gui.New()
if !argv.Auto { if !argv.Auto {
myGui.InitEmbed(resources) myGui.InitEmbed(resources)
} }
myGui.Default() myGui.Default()
@ -44,8 +44,14 @@ func main() {
// todo: add the go.work file logic here // todo: add the go.work file logic here
homeDir, _ := os.UserHomeDir() homeDir, _ := os.UserHomeDir()
filepath := filepath.Join(homeDir, "go/src", argv.Repo) var debpath string
os.Chdir(filepath) if argv.Repo == "." {
os.Setenv("GO_DEB_CUSTOM", "true")
debpath, _ = os.Getwd()
} else {
debpath = filepath.Join(homeDir, "go/src", argv.Repo)
}
os.Chdir(debpath)
// scan the repo // scan the repo
cBox.addRepo(argv.Repo) cBox.addRepo(argv.Repo)
@ -60,19 +66,23 @@ func main() {
// verify the values for the package // verify the values for the package
if cBox.status == nil { if cBox.status == nil {
log.Info("argv.Repo =", argv.Repo) if argv.Repo == "." {
log.Info("repo not found. Try:") // this means try the local directory for a custom 'control' file
log.Info("") } else {
log.Info(" go-clone", argv.Repo) log.Info("argv.Repo =", argv.Repo)
log.Info("") log.Info("repo not found. Try:")
os.Exit(-1) log.Info("")
log.Info(" go-clone", argv.Repo)
log.Info("")
os.Exit(-1)
}
} }
// set the working directory to argv.Repo // set the working directory to argv.Repo
log.Info("cd", cBox.status.Path()) log.Info("cd", cBox.status.Path())
os.Chdir(cBox.status.Path()) os.Chdir(cBox.status.Path())
if argv.Auto { if argv.Auto {
shell.TestTerminalColor() shell.TestTerminalColor()
// basicWindow.Show() // broken gui package. convert to protobuf // basicWindow.Show() // broken gui package. convert to protobuf
if ok, err := cBox.buildPackage(); ok { if ok, err := cBox.buildPackage(); ok {

View File

@ -65,6 +65,8 @@ func (c *controlBox) readControlFile() error {
c.Depends.SetText(value) c.Depends.SetText(value)
case "Recommends": case "Recommends":
c.Recommends.SetText(value) c.Recommends.SetText(value)
case "Version":
c.Version.SetText(value)
case "Package": case "Package":
c.Package.SetText(value) c.Package.SetText(value)
// if c.Package.String() != value { // if c.Package.String() != value {

View File

@ -36,6 +36,7 @@ func makebasicWindow() *gadgets.BasicWindow {
basicWindow.Disable() basicWindow.Disable()
if ok, err := cBox.buildPackage(); ok { if ok, err := cBox.buildPackage(); ok {
log.Info("build worked") log.Info("build worked")
os.Exit(0)
} else { } else {
log.Warn("build failed", err) log.Warn("build failed", err)
} }