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
reset
gocui: build
# use the ncurses gui (only kinda works still)
ncurses: build
reset
./go-deb --gui gocui >/tmp/witgui.log.stderr 2>&1
./go-deb --gui gocui
nocui: reset build
./go-deb --gui nocui

View File

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

14
main.go
View File

@ -44,8 +44,14 @@ func main() {
// todo: add the go.work file logic here
homeDir, _ := os.UserHomeDir()
filepath := filepath.Join(homeDir, "go/src", argv.Repo)
os.Chdir(filepath)
var debpath string
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
cBox.addRepo(argv.Repo)
@ -60,6 +66,9 @@ func main() {
// verify the values for the package
if cBox.status == nil {
if argv.Repo == "." {
// this means try the local directory for a custom 'control' file
} else {
log.Info("argv.Repo =", argv.Repo)
log.Info("repo not found. Try:")
log.Info("")
@ -67,6 +76,7 @@ func main() {
log.Info("")
os.Exit(-1)
}
}
// set the working directory to argv.Repo
log.Info("cd", cBox.status.Path())

View File

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

View File

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