From 3c922d7445b4fc51331e7743022928b556001772 Mon Sep 17 00:00:00 2001 From: Tyler Date: Mon, 11 Sep 2017 22:35:41 -0400 Subject: [PATCH] Fix package name --- .gitlab-ci.yml | 6 +- packaging/build-package.sh | 6 +- src/meow.tf/deb-simple/apt.go | 73 ----------------- src/meow.tf/deb-simple/deb/archive/archive.go | 81 +++++++++++++++++++ src/meow.tf/deb-simple/packages.go | 3 +- 5 files changed, 90 insertions(+), 79 deletions(-) create mode 100644 src/meow.tf/deb-simple/deb/archive/archive.go diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 336ab65..4ec4e80 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,7 +30,7 @@ build-i386: - GOOS=linux GOARCH=386 go build -o build/i386/deb-simple artifacts: paths: - - build + - build/i386 cache: key: "pipeline-$CI_PIPELINE_ID" policy: pull @@ -45,7 +45,7 @@ build-amd64: - go build -o build/amd64/deb-simple artifacts: paths: - - build + - build/amd64 cache: key: "pipeline-$CI_PIPELINE_ID" policy: pull @@ -60,7 +60,7 @@ build-armv7: - GOOS=linux GOARCH=arm GOARM=7 go build -o build/armv7/deb-simple artifacts: paths: - - build + - build/armv7 cache: key: "pipeline-$CI_PIPELINE_ID" policy: pull diff --git a/packaging/build-package.sh b/packaging/build-package.sh index ef72b12..a571821 100644 --- a/packaging/build-package.sh +++ b/packaging/build-package.sh @@ -1,5 +1,5 @@ fpm -s dir -t deb -p build/$ARCH/deb-simple_$VERSION.deb \ - -n astra -v $VERSION \ + -n deb-simple -v $VERSION \ --config-files /etc/deb-simple.conf \ --deb-priority optional --force \ --deb-compression bzip2 \ @@ -8,4 +8,6 @@ fpm -s dir -t deb -p build/$ARCH/deb-simple_$VERSION.deb \ --before-install packaging/scripts/preinst.deb \ -a $ARCH build/$ARCH/deb-simple=/usr/bin/deb-simple \ packaging/deb-simple.service=/lib/systemd/system/deb-simple.service \ - sample_conf.ini=/etc/deb-simple.conf \ No newline at end of file + sample_conf.ini=/etc/deb-simple.conf + +curl -X POST "$UPLOAD_URL" -F "file=@build/$ARCH/deb-simple_$VERSION.deb" \ No newline at end of file diff --git a/src/meow.tf/deb-simple/apt.go b/src/meow.tf/deb-simple/apt.go index 3e0236b..b3ec0a9 100644 --- a/src/meow.tf/deb-simple/apt.go +++ b/src/meow.tf/deb-simple/apt.go @@ -3,12 +3,7 @@ package simple import ( "os" "fmt" - "github.com/blakesmith/ar" - "bytes" "io" - "compress/gzip" - "archive/tar" - "log" "path/filepath" "io/ioutil" "strings" @@ -21,74 +16,6 @@ import ( "meow.tf/deb-simple/deb/release" ) -func inspectPackage(filename string) (string, error) { - f, err := os.Open(filename) - if err != nil { - return "", fmt.Errorf("error opening package file %s: %s", filename, err) - } - - arReader := ar.NewReader(f) - defer f.Close() - var controlBuf bytes.Buffer - - for { - header, err := arReader.Next() - - if err == io.EOF { - break - } - - if err != nil { - return "", fmt.Errorf("error in inspectPackage loop: %s", err) - } - - if strings.Trim(header.Name, "/") == "control.tar.gz" { - io.Copy(&controlBuf, arReader) - return inspectPackageControl(controlBuf) - } - } - return "", nil -} - -func inspectPackageControl(filename bytes.Buffer) (string, error) { - gzf, err := gzip.NewReader(bytes.NewReader(filename.Bytes())) - if err != nil { - return "", fmt.Errorf("error creating gzip reader: %s", err) - } - - tarReader := tar.NewReader(gzf) - var controlBuf bytes.Buffer - for { - header, err := tarReader.Next() - - if err == io.EOF { - break - } - - if err != nil { - return "", fmt.Errorf("failed to inspect package: %s", err) - } - - name := header.Name - - switch header.Typeflag { - case tar.TypeDir: - continue - case tar.TypeReg: - if name == "./control" { - io.Copy(&controlBuf, tarReader) - return controlBuf.String(), nil - } - default: - log.Printf( - "Unable to figure out type : %c in file %s\n", - header.Typeflag, name, - ) - } - } - return "", nil -} - func createRelease(config Conf, distro string) error { outfile, err := os.Create(filepath.Join(config.DistPath(distro), "Release")) diff --git a/src/meow.tf/deb-simple/deb/archive/archive.go b/src/meow.tf/deb-simple/deb/archive/archive.go new file mode 100644 index 0000000..198a762 --- /dev/null +++ b/src/meow.tf/deb-simple/deb/archive/archive.go @@ -0,0 +1,81 @@ +package archive + +import ( + "os" + "fmt" + "github.com/blakesmith/ar" + "bytes" + "io" + "strings" + "compress/gzip" + "archive/tar" + "log" +) + +func InspectPackage(filename string) (string, error) { + f, err := os.Open(filename) + if err != nil { + return "", fmt.Errorf("error opening package file %s: %s", filename, err) + } + + arReader := ar.NewReader(f) + defer f.Close() + var controlBuf bytes.Buffer + + for { + header, err := arReader.Next() + + if err == io.EOF { + break + } + + if err != nil { + return "", fmt.Errorf("error in inspectPackage loop: %s", err) + } + + if strings.Trim(header.Name, "/") == "control.tar.gz" { + io.Copy(&controlBuf, arReader) + return InspectPackageControl(controlBuf) + } + } + return "", nil +} + +func InspectPackageControl(filename bytes.Buffer) (string, error) { + gzf, err := gzip.NewReader(bytes.NewReader(filename.Bytes())) + if err != nil { + return "", fmt.Errorf("error creating gzip reader: %s", err) + } + + tarReader := tar.NewReader(gzf) + var controlBuf bytes.Buffer + for { + header, err := tarReader.Next() + + if err == io.EOF { + break + } + + if err != nil { + return "", fmt.Errorf("failed to inspect package: %s", err) + } + + name := header.Name + + switch header.Typeflag { + case tar.TypeDir: + continue + case tar.TypeReg: + if name == "./control" { + io.Copy(&controlBuf, tarReader) + return controlBuf.String(), nil + } + default: + log.Printf( + "Unable to figure out type : %c in file %s\n", + header.Typeflag, name, + ) + } + } + return "", nil +} diff --git a/src/meow.tf/deb-simple/packages.go b/src/meow.tf/deb-simple/packages.go index 9fd37d4..16470c2 100644 --- a/src/meow.tf/deb-simple/packages.go +++ b/src/meow.tf/deb-simple/packages.go @@ -17,6 +17,7 @@ import ( "crypto/sha256" "github.com/blang/semver" "encoding/json" + "meow.tf/deb-simple/deb/archive" ) var ( @@ -163,7 +164,7 @@ func newPackageFile(path, name string) (*PackageFile, error) { var err error - p.ControlData, err = inspectPackage(debPath) + p.ControlData, err = archive.InspectPackage(debPath) if err != nil { return nil, err