infinite-omicron / pentesting-vm

Penetration Testing Virtual Machine
GNU General Public License v3.0
2 stars 2 forks source link

go installation path #26

Closed outzhu closed 1 year ago

outzhu commented 2 years ago

go seems to have issues with go install due to its undefined GOPATH not being included in $PATH, once fixed I will close https://github.com/infinite-omicron/pentesting-vm/issues/20.

go is in the /usr/bin/

go env outputs

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/vagrant/.cache/go-build"
GOENV="/home/vagrant/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/vagrant/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/vagrant/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.15"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build433537816=/tmp/go-build -gno-record-gcc-switches"

It has GOPATH="/home/vagrant/go" but I can't echo $GOPATH.

I can call with go env GOPATH but I don't know how to export GOBIN with $GOPATH/bin

outzhu commented 2 years ago

I can't figured out Packer env variables. So I did this to fix GOPATH. Building to see if it works.

provisioner "shell" {
    inline = ["echo GOPATH=$HOME/go > ~/.bashrc","echo PATH=$PATH:$GOPATH/bin > ~/.bashrc","source ~/.bashrc"]
  }
oxr463 commented 2 years ago

That's a good approach! Then it'll be persistent for both Docker and Vagrant.

outzhu commented 2 years ago

It didn't work. There's no ~/.bashrc. I guess Packer doesn't create files?

oxr463 commented 2 years ago

It didn't work. There's no ~/.bashrc. I guess Packer doesn't create files?

No, it doesn't. I'm guessing this is because we're on Alpine, which doesn't use bash as the default shell.

This might give you some clues: https://stackoverflow.com/q/39621880/8507637

outzhu commented 2 years ago

But it worked in the vagrant box? and I had to use source ~/.profile to make it work in the box as well.

oxr463 commented 2 years ago

The Vagrant image isn't official (from Alpine)... It comes from a third pary (See: https://github.com/lavabit/robox/tree/master/scripts/alpine314). The docker image is an official image created by the Alpine developers.

Check this out:

docker run -it alpine:latest /bin/sh
cat /etc/profile.d/README 
This directory should contain shell scripts configuring system-wide
environment on users' shells.

Files with the .sh extension found in this directory are evaluated by
Bourne-compatible shells (like ash, bash or zsh) when started as a
login shell.

Maybe you can create a new file here, e.g., /etc/profile.d/go.sh

outzhu commented 2 years ago

I put this in the dependencies.sh and it doesn't show up in the Vagrant box, didn't work. Keeping at it.

export GOPATH=$HOME/go >/etc/profile.d/go.sh
export PATH=$PATH:$GOPATH/bin > /etc/profile.d/go.sh
outzhu commented 2 years ago

Docker doesn't seem to like $HOME for it's env GOPATH. I have to figure out how to fix that.

from git action log pentesting-docker.docker.alpine: go: GOPATH entry is relative; must be absolute path: "$HOME/go".

oxr463 commented 2 years ago

Bug: https://github.com/hashicorp/packer/issues/11855

oxr463 commented 2 years ago

Have we tried this? https://stackoverflow.com/a/59485924/8507637

outzhu commented 2 years ago

this wouldn't work. Packer doesn't save variables, it would still be the same issue when in the box/container. Alpine isn't the issue.

outzhu commented 1 year ago

I made a solution to call go packages. I will still look for alternatives but until then the solution is uploading a go.sh in /etc/profile.d/.