Skip to content

Instantly share code, notes, and snippets.

@dotysan
Last active November 14, 2023 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotysan/4c18efa8c6002fa9b7f217a22a21c8ad to your computer and use it in GitHub Desktop.
Save dotysan/4c18efa8c6002fa9b7f217a22a21c8ad to your computer and use it in GitHub Desktop.
Install direnv on a Go-less system using Go in Docker
#! /usr/bin/env bash
#
# Install direnv on a Go-less system using Go in Docker.
#
set -ex
# latest stable release
#DIRENV_VER=v2.32.3
# don't use above as much is fixed in master
#GO_VER=1.21
GO_VER=1-bookworm
main() {
src
cd direnv.git
# much of this tag is b0rk!
#git switch --detach $DIRENV_VER
img
#bld
#tst
ins
cd ..
cln
}
src() {
! test -d direnv.git ||return 0
git clone git@github.com:direnv/direnv.git direnv.git
}
img() {
docker build -t build-direnv - <<-EOF
FROM golang:$GO_VER
# needed for make test
COPY --from=koalaman/shellcheck:latest \
/bin/shellcheck /bin/shellcheck
COPY --from=golangci/golangci-lint:latest \
/usr/bin/golangci-lint /usr/bin/golangci-lint
# more shells needed for make test
RUN apt-get update && apt-get install -y \
elvish \
fish \
tcsh \
zsh
# and Microsoft's PowerShell is a bit trickier
RUN wget --no-verbose \
https://github.com/PowerShell/PowerShell/releases/download/v7.2.16/powershell-lts_7.2.16-1.deb_amd64.deb && \
dpkg --install powershell-lts_7.2.16-1.deb_amd64.deb ; \
apt-get install --fix-broken --yes && \
rm powershell-lts_7.2.16-1.deb_amd64.deb
# give make build proper perms in .:/direnv
RUN useradd --uid $UID --gid "${GROUPS[0]}" \
--create-home --shell /bin/bash $USER
# only needed for make man on v2.32.3 (not master anymore)
#RUN go install github.com/cpuguy83/go-md2man/v2@latest
# also a legacy artifact of tag v2.32.3
#RUN chmod -R 777 /go/pkg/mod
WORKDIR /direnv
EOF
}
bld() {
docker run --rm \
--volume "$PWD:/direnv" \
--user "$UID:${GROUPS[0]}" \
build-direnv \
make
}
tst() {
docker run --rm \
--volume "$PWD:/direnv" \
--user "$UID:${GROUPS[0]}" \
build-direnv \
make test
}
ins() {
docker run --rm \
--volume "$PWD:/direnv" \
--volume "$HOME/.local:/.local" \
--user "$UID:${GROUPS[0]}" \
build-direnv \
make install PREFIX=/.local
}
cln() {
rm --force --recursive direnv.git
docker image rm build-direnv
}
main
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment