diff --git a/Makefile b/Makefile deleted file mode 100644 index 9517f2e..0000000 --- a/Makefile +++ /dev/null @@ -1,37 +0,0 @@ -# builds .rpm and .deb packages -# requires dockerd to be running -# builds the packages for amd64 - -VERSION=$(shell go run main.go -V) -ARCHIVE="gotop_$(VERSION)_linux_amd64" - -.PHONY: all -all: dist/gotop.rpm dist/gotop.deb - -dist/gotop: - @GOOS=linux GOARCH=amd64 go build -o $@ - -dist: - @mkdir $@ - -dist/gotop.rpm: dist dist/gotop - @docker run --rm \ - -v "$(PWD)/build:/tmp/build" \ - -v "$(PWD)/dist:/tmp/dist" \ - -e "VERSION=$(VERSION)" \ - goreleaser/nfpm pkg \ - --config /tmp/build/nfpm.yml \ - --target /tmp/dist/$(ARCHIVE).rpm - -dist/gotop.deb: dist dist/gotop - @docker run --rm \ - -v "$(PWD)/build:/tmp/build" \ - -v "$(PWD)/dist:/tmp/dist" \ - -e "VERSION=$(VERSION)" \ - goreleaser/nfpm pkg \ - --config /tmp/build/nfpm.yml \ - --target /tmp/dist/$(ARCHIVE).deb - -.PHONY: clean -clean: - @-rm -rf dist diff --git a/go.mod b/go.mod index 56c0e5d..bbe879c 100644 --- a/go.mod +++ b/go.mod @@ -2,18 +2,20 @@ module github.com/xxxserxxx/gotop require ( github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect + github.com/cjbassi/drawille-go v0.1.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/distatus/battery v0.9.0 + github.com/distatus/battery v0.10.0 github.com/docopt/docopt.go v0.0.0-20180111231733-ee0de3bc6815 - github.com/gizak/termui/v3 v3.0.0 + github.com/gizak/termui/v3 v3.1.0 github.com/go-ole/go-ole v1.2.4 // indirect - github.com/mattn/go-runewidth v0.0.4 + github.com/mattn/go-runewidth v0.0.8 github.com/mitchellh/go-wordwrap v1.0.0 // indirect - github.com/shirou/gopsutil v2.18.11+incompatible + github.com/nsf/termbox-go v0.0.0-20200204031403-4d2b513ad8be // indirect + github.com/shirou/gopsutil v2.20.1+incompatible github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect github.com/stretchr/testify v1.4.0 + golang.org/x/arch v0.0.0-20181203225421-5a4828bb7045 // indirect golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 // indirect - howett.net/plist v0.0.0-20181124034731-591f970eefbb // indirect ) go 1.13 diff --git a/go.sum b/go.sum index 6106028..b49447c 100644 --- a/go.sum +++ b/go.sum @@ -2,16 +2,21 @@ github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUW github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= github.com/cjbassi/drawille-go v0.0.0-20190126131713-27dc511fe6fd h1:XtfPmj9tQRilnrEmI1HjQhxXWRhEM+m8CACtaMJE/kM= github.com/cjbassi/drawille-go v0.0.0-20190126131713-27dc511fe6fd/go.mod h1:vjcQJUZJYD3MeVGhtZXSMnCHfUNZxsyYzJt90eCYxK4= +github.com/cjbassi/drawille-go v0.1.0/go.mod h1:vjcQJUZJYD3MeVGhtZXSMnCHfUNZxsyYzJt90eCYxK4= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/distatus/battery v0.9.0 h1:8NS5o00/j3Oh2xgocA6pQROTp5guoR+s8CZlWzHC4QM= github.com/distatus/battery v0.9.0/go.mod h1:gGO7GxHTi1zlRT+cAj8uGG0/8HFiqAeH0TJvoipnuPs= +github.com/distatus/battery v0.10.0 h1:YbizvmV33mqqC1fPCAEaQGV3bBhfYOfM+2XmL+mvt5o= +github.com/distatus/battery v0.10.0/go.mod h1:STnSvFLX//eEpkaN7qWRxCWxrWOcssTDgnG4yqq9BRE= github.com/docopt/docopt.go v0.0.0-20180111231733-ee0de3bc6815 h1:HMAfwOa33y82IaQEKQDfUCiwNlxtM1iw7HLM9ru0RNc= github.com/docopt/docopt.go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:l7JNRynTRuqe45tpIyItHNqZWTxywYjp87MWTOnU5cg= github.com/gizak/termui/v3 v3.0.0 h1:NYTUG6ig/sJK05O5FyhWemwlVPO8ilNpvS/PgRtrKAE= github.com/gizak/termui/v3 v3.0.0/go.mod h1:uinu2dMdtMI+FTIdEFUJQT5y+KShnhQRshvPblXq3lY= +github.com/gizak/termui/v3 v3.1.0 h1:ZZmVDgwHl7gR7elfKf1xc4IudXZ5qqfDh4wExk4Iajc= +github.com/gizak/termui/v3 v3.1.0/go.mod h1:bXQEBkJpzxUAKf0+xq9MSWAvWZlE7c+aidmyFlkYTrY= github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI= github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= @@ -24,16 +29,22 @@ github.com/mattn/go-runewidth v0.0.2 h1:UnlwIPBGaTZfPQ6T1IGzPI0EkYAQmT9fAEJ/poFC github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/mattn/go-runewidth v0.0.8 h1:3tS41NlGYSmhhe/8fhGRzc+z3AYCw1Fe1WAyLuujKs0= +github.com/mattn/go-runewidth v0.0.8/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM= github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4= github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d h1:x3S6kxmy49zXVVyhcnrFqxvNVCBPb2KZ9hV2RBdS840= github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ= +github.com/nsf/termbox-go v0.0.0-20200204031403-4d2b513ad8be h1:yzmWtPyxEUIKdZg4RcPq64MfS8NA6A5fNOJgYhpR9EQ= +github.com/nsf/termbox-go v0.0.0-20200204031403-4d2b513ad8be/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/shirou/gopsutil v2.18.11+incompatible h1:PMFTKnFTr/YTRW5rbLK4vWALV3a+IGXse5nvhSjztmg= github.com/shirou/gopsutil v2.18.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= +github.com/shirou/gopsutil v2.20.1+incompatible h1:oIq9Cq4i84Hk8uQAUOG3eNdI/29hBawGrD5YRl6JRDY= +github.com/shirou/gopsutil v2.20.1+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 h1:udFKJ0aHUL60LboW/A+DfgoHVedieIzIXE8uylPue0U= github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc= github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= @@ -42,6 +53,7 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= golang.org/x/arch v0.0.0-20181203225421-5a4828bb7045 h1:Pn8fQdvx+z1avAi7fdM2kRYWQNxGlavNDSyzrQg2SsU= golang.org/x/arch v0.0.0-20181203225421-5a4828bb7045/go.mod h1:cYlCBUl1MsqxdiKgmc4uh7TxZfWSFLOGSRR090WDxt8= +golang.org/x/sys v0.0.0-20190912141932-bc967efca4b8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 h1:sfkvUWPNGwSV+8/fNqctR5lS2AqCSqYwXdrjCxp/dXo= golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= diff --git a/logging/logging_arm64.go b/logging/logging_arm64.go index 48ace31..03848bb 100644 --- a/logging/logging_arm64.go +++ b/logging/logging_arm64.go @@ -1,3 +1,5 @@ +// +build arm64 + package logging import ( diff --git a/logging/logging_other.go b/logging/logging_other.go index 6a48b69..f5705d6 100644 --- a/logging/logging_other.go +++ b/logging/logging_other.go @@ -1,3 +1,4 @@ +// +build linux openbsd freebsd // +build !arm64 package logging diff --git a/logging/logging_windows.go b/logging/logging_windows.go new file mode 100644 index 0000000..65a2e55 --- /dev/null +++ b/logging/logging_windows.go @@ -0,0 +1,18 @@ +// +build windows + +package logging + +import ( + "os" + "syscall" +) + +var ( + kernel32 = syscall.MustLoadDLL("kernel32.dll") + procSetStdHandle = kernel32.MustFindProc("SetStdHandle") +) + +func stderrToLogfile(logfile *os.File) { + // https://groups.google.com/d/msg/golang-nuts/fG8hEAs7ZXs/tahEOuCEPn0J. + syscall.Syscall(procSetStdHandle.Addr(), 2, uintptr(logfile.Fd()), 2, 0) +} diff --git a/make.sh b/make.sh new file mode 100755 index 0000000..fc920f3 --- /dev/null +++ b/make.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +export VERSION=$(go run ./cmd/gotop -V) + +rm -f build.log + +function candz() { + export GOOS=$1 + export GOARCH=$2 + OUT=build/gotop_${VERSION}_${GOOS}_${GOARCH} + if [[ -n $3 ]]; then + export GOARM=$3 + OUT=${OUT}_v${GOARM} + fi + OUT=${OUT}.zip + if [[ -e $OUT ]]; then + echo SKIP $OUT + return + fi + D=build/gotop + if [[ $GOOS == "windows" ]]; then + D=${D}.exe + fi + go build -o $D ./cmd/gotop >> build.log 2>&1 + unset GOOS GOARCH GOARM CGO_ENABLED + if [[ $? -ne 0 ]]; then + printenv | grep GO >> build.log + echo "############### FAILED ###############" >> build.log + echo >> build.log + echo >> build.log + echo FAILED $OUT + return + fi + cd build + zip $(basename $OUT) $(basename $D) >> ../build.log 2>&1 + cd .. + rm -f $D + if [[ $? -ne 0 ]]; then + echo "############### FAILED ###############" >> build.log + echo >> build.log + echo >> build.log + echo FAILED $OUT + return + fi + echo BUILT $OUT +} + +candz linux arm64 +for x in 5 6 7; do + candz linux arm $x +done +for x in 386 amd64; do + candz linux $x + + sed -i "s/arch: .*/arch: \"${x}\"/" build/nfpm.yml + for y in rpm deb; do + OUT=build/gotop_${VERSION}_linux_${x}.${y} + if [[ -e $OUT ]]; then + echo SKIP $OUT + else + echo Building $OUT + nfpm pkg -t ${OUT} -f build/nfpm.yml + fi + done + + candz windows $x + candz freebsd $x + + export CGO_ENABLED=1 + candz darwin $x + candz openbsd $x + unset CGO_ENABLED +done + +rm -f build/gotop diff --git a/widgets/temp_darwin.go b/widgets/temp_darwin.go index 2f5cde3..d0e512b 100644 --- a/widgets/temp_darwin.go +++ b/widgets/temp_darwin.go @@ -1,3 +1,5 @@ +// +build darwin + package widgets // #cgo LDFLAGS: -framework IOKit diff --git a/widgets/temp_freebsd.go b/widgets/temp_freebsd.go index fcc6cda..8d9eda6 100644 --- a/widgets/temp_freebsd.go +++ b/widgets/temp_freebsd.go @@ -1,3 +1,5 @@ +// +build freebsd + package widgets import ( diff --git a/widgets/temp_linux.go b/widgets/temp_linux.go index 674599e..1460007 100644 --- a/widgets/temp_linux.go +++ b/widgets/temp_linux.go @@ -1,3 +1,5 @@ +// +build linux + package widgets import ( diff --git a/widgets/temp_openbsd.go b/widgets/temp_openbsd.go index 8d0dc63..0d4a24a 100644 --- a/widgets/temp_openbsd.go +++ b/widgets/temp_openbsd.go @@ -1,3 +1,5 @@ +// +build openbsd + package widgets // loosely based on https://github.com/openbsd/src/blob/master/sbin/sysctl/sysctl.c#L2517 diff --git a/widgets/temp_windows.go b/widgets/temp_windows.go index 8160900..422e395 100644 --- a/widgets/temp_windows.go +++ b/widgets/temp_windows.go @@ -1,3 +1,5 @@ +// +build windows + package widgets import (