diff --git a/Makefile b/Makefile index 7b81329..ac0e730 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ TIMESTAMP_MINUTE := $(shell date -u +%Y%m%d%H%M) # build OS ?= linux ARCH ?= amd64 -DIST ?= bookworm +DIST ?= trixie # go 1.22 is available in trixie GOLDFLAGS ?= "-s" # by default create a leaner binary GOARCH ?= amd64 @@ -36,8 +36,9 @@ DESTDIR ?= prefix ?= /usr/local exec_prefix ?= $(prefix) bindir ?= $(exec_prefix)/bin -sharedir ?= $(exec_prefix)/share +sharedir ?= $(prefix)/share mandir ?= $(sharedir)/man/man1 +docsdir ?= $(sharedir)/doc/chkok # use Make's builtin variable to call 'install' INSTALL ?= install @@ -54,18 +55,20 @@ PKG_DIST_DIR ?= $(abspath $(makefile_dir)/..) PKG_TGZ_NAME = chkok-$(CHKOK_VERSION)-$(OS)-$(ARCH).tar.gz PKG_TGZ_PATH = $(PKG_DIST_DIR)/$(PKG_TGZ_NAME) PKG_CHECKSUM_NAME = chkok-$(CHKOK_VERSION)-SHA256SUMS -# PBUILDER_COMPONENTS ?= "main universe" -# PBUILDER_RC ?= $(makefile_dir)build/package/pbuilderrc -# PBUILDER_HOOKS_DIR ?= $(makefile_dir)build/package/pbuilder-hooks + +PBUILDER_COMPONENTS ?= "main universe" +PBUILDER_RC ?= $(makefile_dir)build/package/pbuilderrc +PBUILDER_HOOKS_DIR ?= $(makefile_dir)build/package/pbuilder-hooks + RPM_DEV_TREE ?= $(HOME)/rpmbuild # find Debian package version from the changelog file. latest version # should be at the top, first matching 'chkok (0.1.0-1) ...' and sed clears chars not in version -# CHKOK_DEB_VERSION := $(shell grep --only-matching --max-count 1 --perl-regexp "^\s*chkok\s+\(.+\)\s*" build/package/debian/changelog | sed 's/[^0-9.-]//g') -# CHKOK_DEB_UPSTREAM_VERSION := $(shell echo $(CHKOK_DEB_VERSION) | grep --only-matching --perl-regexp '^[0-9.]+') -# CHKOK_DEB_UPSTREAM_TARBAL_PATH := $(abspath $(makefile_dir)/..) -# CHKOK_DEB_UPSTREAM_TARBAL := $(CHKOK_DEB_UPSTREAM_TARBAL_PATH)/chkok_$(CHKOK_DEB_UPSTREAM_VERSION).orig.tar.gz -# DEB_BUILD_GIT_BRANCH := pkg-deb-$(CHKOK_DEB_VERSION)-$(TIMESTAMP_MINUTE) +CHKOK_DEB_VERSION := $(shell grep --only-matching --max-count 1 --perl-regexp "^\s*chkok\s+\(.+\)\s*" build/package/debian/changelog | sed 's/[^0-9.-]//g') +CHKOK_DEB_UPSTREAM_VERSION := $(shell echo $(CHKOK_DEB_VERSION) | grep --only-matching --perl-regexp '^[0-9.]+') +CHKOK_DEB_UPSTREAM_TARBAL_PATH := $(abspath $(makefile_dir)/..) +CHKOK_DEB_UPSTREAM_TARBAL := $(CHKOK_DEB_UPSTREAM_TARBAL_PATH)/chkok_$(CHKOK_DEB_UPSTREAM_VERSION).orig.tar.gz +DEB_BUILD_GIT_BRANCH := pkg-deb-$(CHKOK_DEB_VERSION)-$(TIMESTAMP_MINUTE) # find rpm version from the spec file. latest version # should be in the top tags, first matching 'Version: 0.1.0' and sed clears chars not in version @@ -74,8 +77,10 @@ RPM_DEV_SRC_TGZ = $(RPM_DEV_TREE)/SOURCES/chkok-$(CHKOK_RPM_VERSION).tar.gz RPM_DEV_SPEC = $(RPM_DEV_TREE)/SPECS/chkok-$(CHKOK_RPM_VERSION).spec # command aliases -# cowbuilder = env DISTRIBUTION=$(DIST) ARCH=$(ARCH) BASEPATH=/var/cache/pbuilder/base-$(DIST)-$(ARCH).cow cowbuilder +cowbuilder = env DISTRIBUTION=$(DIST) ARCH=$(ARCH) BASEPATH=/var/cache/pbuilder/base-$(DIST)-$(ARCH).cow cowbuilder +# testing +TEST_SKIP_STATICCHECKS ?= chkok: GOOS=$(OS) GOARCH=$(GOARCH) go build -ldflags $(GOLDFLAGS) cmd/chkok.go @@ -86,7 +91,7 @@ build: chkok test: go test -v -race ./... - ./scripts/staticchecks + if test -z $(TEST_SKIP_STATICCHECKS); then ./scripts/staticchecks; fi install: build @@ -94,10 +99,15 @@ install: build $(INSTALL_PROGRAM) chkok $(DESTDIR)$(bindir) mkdir -p $(DESTDIR)$(mandir) cp docs/man/chkok.1 $(DESTDIR)$(mandir) + mkdir -p $(DESTDIR)$(docsdir) + cp examples/config.yaml $(DESTDIR)$(docsdir)/example-config.yaml + cp README.rst $(DESTDIR)$(docsdir)/README.rst uninstall: rm -f $(DESTDIR)$(bindir)/chkok rm -f $(DESTDIR)$(mandir)/chkok.1 + rm -f $(DESTDIR)$(docsdir)/* + rmdir $(DESTDIR)$(docsdir) clean: rm -f chkok @@ -107,29 +117,28 @@ clean: distclean: clean # override prefix so .deb package installs binaries to /usr/bin instead of /usr/local/bin -# pkg-deb: export prefix = /usr +# run target with 'make pkg-deb prefix=/usr' # requires a cowbuilder environment. see pkg-deb-setup -# pkg-deb: -# git checkout -b $(DEB_BUILD_GIT_BRANCH) -# rm -f $(CHKOK_DEB_UPSTREAM_TARBAL); tar --exclude-backups --exclude-vcs -zcf $(CHKOK_DEB_UPSTREAM_TARBAL) . -# cp -r build/package/debian debian; git add debian; git commit -m 'add debian dir for packaging v$(CHKOK_DEB_VERSION)' -# gbp buildpackage --git-ignore-new --git-verbose --git-pbuilder \ -# --git-no-create-orig --git-tarball-dir=$(CHKOK_DEB_UPSTREAM_TARBAL_PATH) \ -# --git-hooks \ -# --git-dist=$(DIST) --git-arch=$(ARCH) \ -# --git-ignore-new --git-ignore-branch \ -# --git-pbuilder-options='--configfile=$(PBUILDER_RC) --hookdir=$(PBUILDER_HOOKS_DIR) --buildresult=$(PKG_DIST_DIR)' \ -# -b -us -uc -sa -# git checkout $(GIT_CURRENT_BRANCH) -# git branch -D $(DEB_BUILD_GIT_BRANCH) +pkg-deb: + git checkout -b $(DEB_BUILD_GIT_BRANCH) + rm -f $(CHKOK_DEB_UPSTREAM_TARBAL); tar --exclude-backups --exclude-vcs -zcf $(CHKOK_DEB_UPSTREAM_TARBAL) . + cp -r build/package/debian debian; git add debian; git commit -m 'add debian dir for packaging v$(CHKOK_DEB_VERSION)' + gbp buildpackage --git-ignore-new --git-ignore-branch --git-verbose --git-pbuilder \ + --git-no-create-orig --git-tarball-dir=$(CHKOK_DEB_UPSTREAM_TARBAL_PATH) \ + --git-hooks \ + --git-dist=$(DIST) --git-arch=$(ARCH) \ + --git-pbuilder-options='--configfile=$(PBUILDER_RC) --hookdir=$(PBUILDER_HOOKS_DIR) --buildresult=$(PKG_DIST_DIR)' \ + -b -us -uc -sa + git checkout $(GIT_CURRENT_BRANCH) + git branch -D $(DEB_BUILD_GIT_BRANCH) # required: # sudo apt-get install build-essential debhelper pbuilder fakeroot cowbuilder git-buildpackage devscripts ubuntu-dev-tools -# pkg-deb-setup: -# echo "creating a git-pbuilder environment with apt repositories to install new go versions ..." -# DIST=$(DIST) ARCH=$(ARCH) git-pbuilder create --components=$(PBUILDER_COMPONENTS) \ -# --extrapackages="cowdancer curl wget" --configfile=$(PBUILDER_RC) \ -# --hookdir=$(PBUILDER_HOOKS_DIR) +pkg-deb-setup: + echo "creating a git-pbuilder environment with apt repositories to install new go versions ..." + DIST=$(DIST) ARCH=$(ARCH) git-pbuilder create --components=$(PBUILDER_COMPONENTS) \ + --extrapackages="cowdancer curl wget" --configfile=$(PBUILDER_RC) \ + --hookdir=$(PBUILDER_HOOKS_DIR) pkg-tgz: build tar --create --gzip --exclude-vcs --exclude=docs/man/*.rst --file $(PKG_TGZ_PATH) chkok \ @@ -170,7 +179,7 @@ sync-version: @ sed -i 's/^:Version:.*/:Version: $(CHKOK_VERSION)/;t' docs/man/chkok.rst && $(MAKE) docs @ # update first occurrence of version in RPM spec @ sed -i 's/^Version:.*/Version: $(CHKOK_VERSION)/;t' build/package/chkok.spec - @ # (grep --max 1 --only --perl-regexp '^chkok.+\(.+\).+' build/package/debian/changelog | grep -q -F $(CHKOK_VERSION)) || \ + @ (grep --max 1 --only --perl-regexp '^chkok.+\(.+\).+' build/package/debian/changelog | grep -q -F $(CHKOK_VERSION)) || \ echo -e "\e[33m*** NOTE:\e[m version $(CHKOK_VERSION) maybe missing from Debian changelog" @ (grep --line-regexp '%changelog' -A 50 build/package/chkok.spec | grep -q -F $(CHKOK_VERSION)) || \ echo -e "\e[33m*** NOTE:\e[m version $(CHKOK_VERSION) maybe missing from RPM changelog" diff --git a/build/package/chkok.spec b/build/package/chkok.spec index f151609..7ad1ea7 100644 --- a/build/package/chkok.spec +++ b/build/package/chkok.spec @@ -1,5 +1,5 @@ Name: chkok -Version: 0.3.0 +Version: 0.3.1 Release: 1%{?dist} Summary: checks attributes of files and sockets @@ -31,7 +31,6 @@ Provides different running modes, useful for reporting to local and remote monit %install rm -rf $RPM_BUILD_ROOT %make_install -cp -a examples/config.yaml example-config.yaml %clean @@ -40,12 +39,17 @@ rm -rf $RPM_BUILD_ROOT %files %license LICENSE -%doc README.rst example-config.yaml +%doc README.rst %{_bindir}/%{name} %{_mandir}/man1/%{name}* +%{_docdir}/chkok/example-config.yaml %changelog +* Sun Jun 16 2024 Farzad Ghanei 0.3.1-1 +- Add support for Debian packaging +- Improve packaging + * Sat May 11 2024 Farzad Ghanei 0.3.0-1 - Add support for required headers for http runner - Add maxHeaderBytes configuration for http runner diff --git a/build/package/debian/changelog b/build/package/debian/changelog new file mode 100644 index 0000000..e347261 --- /dev/null +++ b/build/package/debian/changelog @@ -0,0 +1,10 @@ +chkok (0.3.1-1) UNRELEASED; urgency=low + + [ Farzad Ghanei ] + * Closes #10 adds deb packaging + * Add support for required headers for http runner + * Add maxHeaderBytes configuration for http runner + + [ Farzad Ghanei ] + + -- Farzad Ghanei <644113+farzadghanei@users.noreply.github.com> Sun, 16 Jun 2024 16:08:03 +0100 diff --git a/build/package/debian/chkok.manpages b/build/package/debian/chkok.manpages new file mode 100644 index 0000000..97ce177 --- /dev/null +++ b/build/package/debian/chkok.manpages @@ -0,0 +1 @@ +docs/man/chkok.1 diff --git a/build/package/debian/control b/build/package/debian/control new file mode 100644 index 0000000..4e386f6 --- /dev/null +++ b/build/package/debian/control @@ -0,0 +1,14 @@ +Source: chkok +Section: misc +Priority: optional +Maintainer: Farzad Ghanei <644113+farzadghanei@users.noreply.github.com> +Homepage: https://github.com/farzadghanei/chkok +Standards-Version: 4.6.2 +Build-Depends: debhelper-compat (= 13), golang-go (>=1.22), git, ca-certificates + +Package: chkok +Architecture: amd64 +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: checks attributes of files and sockets + "chkok" checks if attributes of files and sockets match the provided + conditions. diff --git a/build/package/debian/copyright b/build/package/debian/copyright new file mode 100644 index 0000000..2e71f86 --- /dev/null +++ b/build/package/debian/copyright @@ -0,0 +1,44 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: chkok +Upstream-Contact: Farzad Ghanei +Source: https://github.com/farzadghanei/chkok + +Files: * +Copyright: 2024 Farzad Ghanei <644113+farzadghanei@users.noreply.github.com> +License: MIT + +Files: go-yaml/yaml* +Copyright: Copyright (c) 2006-2011 Kirill Simonov +License: MIT + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies + of the Software, and to permit persons to whom the Software is furnished to do + so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. + + + +License: MIT + Permission is hereby granted, free of charge, to any person obtaining a copy of this software + and associated documentation files (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/build/package/debian/docs b/build/package/debian/docs new file mode 100644 index 0000000..a1320b1 --- /dev/null +++ b/build/package/debian/docs @@ -0,0 +1 @@ +README.rst diff --git a/build/package/debian/rules b/build/package/debian/rules new file mode 100755 index 0000000..1be8e28 --- /dev/null +++ b/build/package/debian/rules @@ -0,0 +1,16 @@ +#!/usr/bin/make -f + +%: + dh $@ + + +override_dh_install: + dh_install + + +override_dh_auto_test: + # skip staticchecks on package build + $(MAKE) test TEST_SKIP_STATICCHECKS=1 + +override_dh_usrlocal: + @echo "skip dh_usrlocal" \ No newline at end of file diff --git a/build/package/debian/source/format b/build/package/debian/source/format new file mode 100644 index 0000000..46ebe02 --- /dev/null +++ b/build/package/debian/source/format @@ -0,0 +1 @@ +3.0 (quilt) \ No newline at end of file diff --git a/build/package/pbuilderrc b/build/package/pbuilderrc new file mode 100644 index 0000000..432e398 --- /dev/null +++ b/build/package/pbuilderrc @@ -0,0 +1,20 @@ +# configurations for pbuilder/cowbuilder +# can be set via ~/.pbuilderrc + +# by defualt don't sign the deb package +AUTO_DEBSIGN=${AUTO_DEBSIGN:-no} + +# configure where to place the built packages +BUILDRESULT=${PKG_DIST_DIR:-../} + +# apt repository components +COMPONENTS=${COMPONENTS:-"main universe"} + +# enable networking in pbuilder env so go can download package dependencies +USENETWORK=yes + +# set $HOME var to $BUILDDIR so commands that need $HOME env var would work +BUILD_HOME=$BUILDDIR + +# set debbuild opts so dpkg-buildpackage skips signing packages +DEBBUILDOPTS=${DEBBUILDOPTS:-"-us -uc -I -i"} diff --git a/cmd/chkok.go b/cmd/chkok.go index 0b50295..6060989 100644 --- a/cmd/chkok.go +++ b/cmd/chkok.go @@ -11,7 +11,7 @@ import ( ) // Version of the app -const Version string = "0.3.0" +const Version string = "0.3.1" // ModeHTTP run checks in http server mode const ModeHTTP string = "http" diff --git a/docs/man/chkok.1 b/docs/man/chkok.1 index 34ce13f..dcc30b3 100644 --- a/docs/man/chkok.1 +++ b/docs/man/chkok.1 @@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. -.TH "CHKOK" 1 "2024-05-11" "0.3.0" "General Command Manuals" +.TH "CHKOK" 1 "2024-05-16" "0.3.1" "General Command Manuals" .SH NAME chkok \- Check if file attributes are OK .SH SYNOPSIS diff --git a/docs/man/chkok.rst b/docs/man/chkok.rst index a453733..dc76cbe 100644 --- a/docs/man/chkok.rst +++ b/docs/man/chkok.rst @@ -7,9 +7,9 @@ Check if file attributes are OK ------------------------------- :Author: Farzad Ghanei -:Date: 2024-05-11 +:Date: 2024-05-16 :Copyright: Copyright (c) 2024 Farzad Ghanei. chkok is an open source project released under the terms of the MIT license. -:Version: 0.3.0 +:Version: 0.3.1 :Manual section: 1 :Manual group: General Command Manuals