doronbehar / pistol

General purpose file previewer designed for Ranger, Lf to make scope.sh redundant

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Install Fails

brandonkal opened this issue · comments

Unable to install using go get. It appears there is a dependency issue.

~/.config/lf  brew install libmagic
==> Downloading https://homebrew.bintray.com/bottles/libmagic-5.37.high_sierra.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/14/14eb5417f36b7ae1813a290c6004c880bd2c50498bc470a48dd9fb8cb489aa4e?__gda__=exp=1574840839~hmac=ea3c38b75d874c38c4341e6
######################################################################## 100.0%
==> Pouring libmagic-5.37.high_sierra.bottle.tar.gz
🍺  /usr/local/Cellar/libmagic/5.37: 315 files, 6.7MB
~/.config/lf  go get -u github.com/doronbehar/pistol/cmd/pistol
package github.com/pierrec/lz4/v3: cannot find package "github.com/pierrec/lz4/v3" in any of:
	/usr/local/Cellar/go/1.13.4/libexec/src/github.com/pierrec/lz4/v3 (from $GOROOT)
	/Users/brandon/go/src/github.com/pierrec/lz4/v3 (from $GOPATH)

Thanks for reporting this. Could you locate the header files of libmagic as installed by brew? It should be something like /usr/local/Cellar/libmagic/5.37/include. After locating the include path, could you try running the following:

CGO_CFLAGS="-I/usr/local/Cellar/libmagic/5.37/include" go get -u github.com/doronbehar/pistol/cmd/pistol

The same issue here running Ubuntu 18.04.

Ran sudo apt install libmagic-dev then go get -u github.com/doronbehar/pistol/cmd/pistol, same error.

I was able to locate only the .so files.

asmar:/usr/lib/x86_64-linux-gnu$ ll libmagic.*
.rw-r--r-- 261k root root 29 říj 17:50 libmagic.a
lrwxrwxrwx   17 root root 29 říj 17:50 libmagic.so -> libmagic.so.1.0.0
lrwxrwxrwx   17 root root 29 říj 17:50 libmagic.so.1 -> libmagic.so.1.0.0
.rw-r--r-- 137k root root 29 říj 17:50 libmagic.so.1.0.0

@asmarcz Could you use apt-file or dpkg to search for the package that will provide magic.h? It seems libmagic-dev should provide /usr/include/magic.h, see this...

@doronbehar I'm sorry, I didn't know of such possibility.

I located the file

asmar:~$ dpkg -S magic.h
linux-headers-4.15.0-70-generic: /usr/src/linux-headers-4.15.0-70-generic/include/config/fb/neomagic.h
linux-libc-dev:amd64: /usr/include/linux/magic.h
linux-headers-4.15.0-70: /usr/src/linux-headers-4.15.0-70/include/linux/vermagic.h
linux-headers-4.15.0-72-generic: /usr/src/linux-headers-4.15.0-72-generic/include/config/fb/neomagic.h
linux-headers-4.15.0-72: /usr/src/linux-headers-4.15.0-72/include/uapi/linux/magic.h
linux-headers-4.15.0-72: /usr/src/linux-headers-4.15.0-72/include/video/neomagic.h
linux-headers-4.15.0-70: /usr/src/linux-headers-4.15.0-70/include/video/neomagic.h
linux-headers-4.15.0-36: /usr/src/linux-headers-4.15.0-36/include/linux/vermagic.h
linux-headers-4.15.0-36-generic: /usr/src/linux-headers-4.15.0-36-generic/include/config/fb/neomagic.h
linux-headers-4.15.0-69: /usr/src/linux-headers-4.15.0-69/include/linux/vermagic.h
linux-headers-4.15.0-69-generic: /usr/src/linux-headers-4.15.0-69-generic/include/config/fb/neomagic.h
linux-headers-4.15.0-70: /usr/src/linux-headers-4.15.0-70/include/uapi/linux/magic.h
linux-headers-4.15.0-72: /usr/src/linux-headers-4.15.0-72/include/linux/vermagic.h
linux-headers-4.15.0-36: /usr/src/linux-headers-4.15.0-36/include/video/neomagic.h
linux-headers-4.15.0-36: /usr/src/linux-headers-4.15.0-36/include/uapi/linux/magic.h
linux-headers-4.15.0-69: /usr/src/linux-headers-4.15.0-69/include/uapi/linux/magic.h
libmagic-dev:amd64: /usr/include/magic.h
linux-headers-4.15.0-69: /usr/src/linux-headers-4.15.0-69/include/video/neomagic.h

Then I tried to run the command again with substituted path but it gave the same error.

asmar:~$ CGO_CFLAGS="-I/usr/include/magic.h" go get -u github.com/doronbehar/pistol/cmd/pistol
package github.com/pierrec/lz4/v3: cannot find package "github.com/pierrec/lz4/v3" in any of:
	/usr/local/go/src/github.com/pierrec/lz4/v3 (from $GOROOT)
	/home/asmar/go/src/github.com/pierrec/lz4/v3 (from $GOPATH)

Boy, I haven't noticed this has nothing to do with libmagic... both your and @brandonkal 's installation should be fine without the need to modify CGO_CFLAGS during build. lz4 is a dependency of archiver - meaning that something is wrong with the way it imports it.

I've updated the repo with a small dependencies updates. Please try again now and if the same error persists, I'll talk with the archiver guys.

Still doesn't work. Same error. Tried asmar:~$ sudo rm -r go/src/ before running still not working.

Funny... could you try cloning the repo and cd to cmd/pistol inside the repo and run go build or go install?

Doesn't seem to contain error.

asmar:~/projects/pistol/cmd/pistol$ go build
go: downloading github.com/adrg/xdg v0.0.0-20190319220657-88e5137d2444
go: downloading github.com/galdor/go-cmdline v1.1.0
go: downloading github.com/sirupsen/logrus v1.4.2
go: downloading github.com/rakyll/magicmime v0.1.0
go: downloading github.com/dustin/go-humanize v1.0.0
go: downloading github.com/alecthomas/chroma v0.6.3
go: downloading github.com/mholt/archiver v0.0.0-20190623220050-33320f6f7306
go: extracting github.com/sirupsen/logrus v1.4.2
go: downloading golang.org/x/sys v0.0.0-20190527104216-9cd6430ef91e
go: extracting github.com/adrg/xdg v0.0.0-20190319220657-88e5137d2444
go: extracting github.com/dustin/go-humanize v1.0.0
go: extracting github.com/galdor/go-cmdline v1.1.0
go: extracting github.com/mholt/archiver v0.0.0-20190623220050-33320f6f7306
go: downloading github.com/ulikunitz/xz v0.5.6
go: downloading github.com/nwaples/rardecode v1.0.0
go: downloading github.com/golang/snappy v0.0.1
go: downloading github.com/klauspost/pgzip v1.2.1
go: extracting github.com/golang/snappy v0.0.1
go: downloading github.com/andybalholm/brotli v0.0.0-20190621154722-5f990b63d2d6
go: extracting github.com/alecthomas/chroma v0.6.3
go: downloading github.com/dlclark/regexp2 v1.1.6
go: downloading github.com/klauspost/compress v1.7.1
go: downloading github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8
go: downloading github.com/pierrec/lz4 v2.0.5+incompatible
go: extracting github.com/klauspost/pgzip v1.2.1
go: downloading github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964
go: extracting github.com/nwaples/rardecode v1.0.0
go: downloading github.com/dsnet/compress v0.0.1
go: extracting github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964
go: extracting github.com/andybalholm/brotli v0.0.0-20190621154722-5f990b63d2d6
go: downloading github.com/golang/gddo v0.0.0-20190419222130-af0f2af80721
go: extracting github.com/ulikunitz/xz v0.5.6
go: extracting github.com/dlclark/regexp2 v1.1.6
go: extracting golang.org/x/sys v0.0.0-20190527104216-9cd6430ef91e
go: extracting github.com/golang/gddo v0.0.0-20190419222130-af0f2af80721
go: extracting github.com/pierrec/lz4 v2.0.5+incompatible
go: extracting github.com/dsnet/compress v0.0.1
go: extracting github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8
go: extracting github.com/rakyll/magicmime v0.1.0
go: extracting github.com/klauspost/compress v1.7.1
go: downloading github.com/klauspost/cpuid v1.2.0
go: extracting github.com/klauspost/cpuid v1.2.0
go: finding github.com/adrg/xdg v0.0.0-20190319220657-88e5137d2444
go: finding github.com/galdor/go-cmdline v1.1.0
go: finding github.com/rakyll/magicmime v0.1.0
go: finding github.com/sirupsen/logrus v1.4.2
go: finding github.com/alecthomas/chroma v0.6.3
go: finding github.com/dustin/go-humanize v1.0.0
go: finding github.com/mholt/archiver v0.0.0-20190623220050-33320f6f7306
go: finding golang.org/x/sys v0.0.0-20190527104216-9cd6430ef91e
go: finding github.com/dlclark/regexp2 v1.1.6
go: finding github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964
go: finding github.com/dsnet/compress v0.0.1
go: finding github.com/golang/snappy v0.0.1
go: finding github.com/klauspost/pgzip v1.2.1
go: finding github.com/klauspost/compress v1.7.1
go: finding github.com/andybalholm/brotli v0.0.0-20190621154722-5f990b63d2d6
go: finding github.com/nwaples/rardecode v1.0.0
go: finding github.com/pierrec/lz4 v2.0.5+incompatible
go: finding github.com/ulikunitz/xz v0.5.6
go: finding github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8
go: finding github.com/golang/gddo v0.0.0-20190419222130-af0f2af80721
go: finding github.com/klauspost/cpuid v1.2.0

1 more thing please @asmarcz, I'd like to know the output of go version on your machine.

I installed Go just yesterday (or the day before) when I tried to use pistol with lf.

asmar:~$ go version
go version go1.13.5 linux/amd64

And could you try deleting the $GOPATH/ or probably ~/go in your case and then run: go install github.com/doronbehar/pistol/cmd/pistol

asmar:~$ sudo rm -r go
[sudo] password for asmar: 
asmar:~$ go install github.com/doronbehar/pistol/cmd/pistol
can't load package: package github.com/doronbehar/pistol/cmd/pistol: cannot find package "github.com/doronbehar/pistol/cmd/pistol" in any of:
	/usr/local/go/src/github.com/doronbehar/pistol/cmd/pistol (from $GOROOT)
	/home/asmar/go/src/github.com/doronbehar/pistol/cmd/pistol (from $GOPATH)

Oh right, I've managed to reproduce with a modified $GOPATH on my machine. The issue is familiar with archiver - mholt/archiver#195 and there's an currently open upstream Go issue: golang/go#31529

As a workaround (I tested), Use the following command instead:

env GO111MODULE=on go get -u github.com/doronbehar/pistol/cmd/pistol

Once verified the workaround works for you as well, I'll update the readme..

Thank you, pistol can be run now:

asmar:~/go/bin$ ./pistol --help
Usage: ./pistol OPTIONS [<file> ...]

OPTIONS

-c, --config <config>  configuration file to use (defaults to /home/asmar/.config/pistol.conf)
-h, --help             print help and exit
-v, --verbosity        increase verbosity

ARGUMENTS

file                   the file to preview

As a side note. For me with default Go settings the paths were

$GOPATH/bin/pistol
~/go/bin/pistol

as opposed to the README

$GOPATH/.bin/pistol
~/.go/bin/pistol

Thanks for reporting this. Could you locate the header files of libmagic as installed by brew? It should be something like /usr/local/Cellar/libmagic/5.37/include. After locating the include path, could you try running the following:

CGO_CFLAGS="-I/usr/local/Cellar/libmagic/5.37/include" go get -u github.com/doronbehar/pistol/cmd/pistol

For those, having this issue on Mac M1 silicon:
CGO_CFLAGS="-I/opt/homebrew/Cellar/libmagic/5.44/include" go install github.com/doronbehar/pistol/cmd/pistol@latest worked for me. brew installs sutff in /opt/homebrew/Cellar just so you don't get bored on your 3k$ computer.

I tried this on my m1 mac and didn't work for me..please anyone can help to fix this?

CGO_CFLAGS="-I/opt/homebrew/Cellar/libmagic/5.44/include/magic.h" go install github.com/doronbehar/pistol/cmd/pistol@latest
# github.com/doronbehar/magicmime
go/pkg/mod/github.com/doronbehar/magicmime@v0.1.1-0.20211127135329-3de4ff29dc49/magicmime.go:28:11: fatal error: 'magic.h' file not found
 #include <magic.h>
          ^~~~~~~~~
1 error generated.

Ubuntu 23.10 user here, can't compile due to magic.h missing

$ go install github.com/doronbehar/pistol/cmd/pistol@latest
# github.com/doronbehar/magicmime
go/pkg/mod/github.com/doronbehar/magicmime@v0.1.1-0.20211127135329-3de4ff29dc49/magicmime.go:28:11: fatal error: magic.h: No such file or directory
   28 | // #include <magic.h>
      |           ^~~~~~~~~
compilation terminated.