Skip to content

Instantly share code, notes, and snippets.

@dotysan
Last active November 14, 2023 19:01
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/c02714e7f81224a17ef01c51d6801c08 to your computer and use it in GitHub Desktop.
Save dotysan/c02714e7f81224a17ef01c51d6801c08 to your computer and use it in GitHub Desktop.
Install GitHub CLI on a Go-less system using Go in Docker
#! /usr/bin/env bash
#
# Install GitHub CLI on a Go-less system using Go in Docker.
#
set -ex
# latest stable release
GHCLI_VER=v2.38.0
GO_VER=1-bookworm
main() {
src
cd gh-cli.git
git switch --detach $GHCLI_VER
img
#bld
#tst
ins
cd ..
cln
}
src() {
! test -d gh-cli.git ||return 0
git clone git@github.com:cli/cli.git gh-cli.git
}
img() {
docker build -t build-ghcli - <<-EOF
FROM golang:$GO_VER
# give make build proper perms in .:/gh-cli
RUN useradd --uid $UID --gid "${GROUPS[0]}" \
--create-home --shell /bin/bash $USER
WORKDIR /gh-cli
EOF
}
bld() {
docker run --rm \
--volume "$PWD:/gh-cli" \
--user "$UID:${GROUPS[0]}" \
build-ghcli \
make
}
tst() {
docker run --rm \
--volume "$PWD:/gh-cli" \
--user "$UID:${GROUPS[0]}" \
build-ghcli \
make test
}
ins() {
docker run --rm \
--volume "$PWD:/gh-cli" \
--volume "$HOME/.local:/.local" \
--user "$UID:${GROUPS[0]}" \
build-ghcli \
make install prefix=/.local
}
cln() {
rm --force --recursive gh-cli.git
docker image rm build-ghcli
}
main
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment