From 20a193f04c8da00de19993dd67a503d21ef87ac9 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Sun, 13 Jul 2025 14:29:12 +0200 Subject: [PATCH] [mod] add Golang ecosystem to the SearXNG toolchain Signed-off-by: Markus Heiser --- .gitignore | 1 + Makefile | 5 +- manage | 23 ++++- utils/lib_go.sh | 211 ------------------------------------------- utils/lib_govm.sh | 226 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 250 insertions(+), 216 deletions(-) delete mode 100755 utils/lib_go.sh create mode 100755 utils/lib_govm.sh diff --git a/.gitignore b/.gitignore index 1305d0ac8..ea6147b1c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ geckodriver.log .coverage coverage/ +.govm/ .nvm/ cache/ build/ diff --git a/Makefile b/Makefile index a4b19c25d..4c633e1fc 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ install uninstall: $(Q)./manage pyenv.$@ PHONY += clean -clean: py.clean docs.clean node.clean nvm.clean test.clean +clean: py.clean docs.clean node.clean nvm.clean go.clean test.clean $(Q)./manage build_msg CLEAN "common files" $(Q)find . -name '*.orig' -exec rm -f {} + $(Q)find . -name '*.rej' -exec rm -f {} + @@ -57,7 +57,7 @@ test.shell: $(MTOOLS) \ utils/lib.sh \ utils/lib_sxng*.sh \ - utils/lib_go.sh \ + utils/lib_govm.sh \ utils/lib_nvm.sh \ utils/lib_redis.sh \ utils/lib_valkey.sh \ @@ -82,6 +82,7 @@ MANAGE += test.yamllint test.pylint test.black test.pybabel test.unit test.cover MANAGE += themes.all themes.simple themes.fix themes.lint themes.test MANAGE += static.build.commit static.build.drop static.build.restore MANAGE += nvm.install nvm.clean nvm.status nvm.nodejs +MANAGE += go.env.dev go.clean PHONY += $(MANAGE) diff --git a/manage b/manage index cf3abbca6..7d2305e65 100755 --- a/manage +++ b/manage @@ -32,8 +32,8 @@ source "$(dirname "${BASH_SOURCE[0]}")/utils/lib_sxng_themes.sh" # shellcheck source=utils/lib_sxng_test.sh source "$(dirname "${BASH_SOURCE[0]}")/utils/lib_sxng_test.sh" -# shellcheck source=utils/lib_go.sh -source "$(dirname "${BASH_SOURCE[0]}")/utils/lib_go.sh" +# shellcheck source=utils/lib_govm.sh +source "$(dirname "${BASH_SOURCE[0]}")/utils/lib_govm.sh" # shellcheck source=utils/lib_valkey.sh source "$(dirname "${BASH_SOURCE[0]}")/utils/lib_valkey.sh" @@ -41,7 +41,8 @@ source "$(dirname "${BASH_SOURCE[0]}")/utils/lib_valkey.sh" # shellcheck source=utils/lib_sxng_vite.sh source "$(dirname "${BASH_SOURCE[0]}")/utils/lib_sxng_vite.sh" -PATH="${REPO_ROOT}/node_modules/.bin:${PATH}" +# add ./local dev tools from python (virtualenv), golang and nodejs +PATH="${PY_ENV}/bin:${REPO_ROOT}/node_modules/.bin:${GOROOT}/bin:${GOPATH}/bin:${PATH}" # config @@ -100,11 +101,27 @@ EOF static.help vite.help cat < [filename|sha256|size] - # - # kind: [archive|source|installer] - # os: [darwin|freebsd|linux|windows] - # arch: [amd64|arm64|386|armv6l|ppc64le|s390x] - - python - "$@" < [] - - local version fname sha size user userpr - local buf=() - - version="${1:-${GO_VERSION}}" - user="${2:-${USERNAME}}" - userpr=" ${_Yellow}|${user}|${_creset} " - - rst_title "Install Go in ${user}'s HOME" section - - mapfile -t buf < <( - go.ver_info "${version}" archive "$(go.os)" "$(go.arch)" filename sha256 size - ) - - if [ ${#buf[@]} -eq 0 ]; then - die 42 "can't find info of golang version: ${version}" - fi - fname="${buf[0]}" - sha="${buf[1]}" - size="$(numfmt --to=iec "${buf[2]}")" - - info_msg "Download go binary ${fname} (${size}B)" - cache_download "${GO_DL_URL}/${fname}" "${fname}" - - pushd "${CACHE}" &> /dev/null - echo "${sha} ${fname}" > "${fname}.sha256" - if ! sha256sum -c "${fname}.sha256" >/dev/null; then - die 42 "downloaded file ${fname} checksum does not match" - else - info_msg "${fname} checksum OK" - fi - popd &> /dev/null - - info_msg "install golang" - tee_stderr 0.1 < \$HOME/.go_env -echo "export PATH=\$HOME/local/go/bin:\\\$GOPATH/bin:\\\$PATH" >> \$HOME/.go_env -EOF - info_msg "test golang installation" - sudo -i -u "${user}" < [] - - local package user userpr - - package="${1}" - user="${2:-${USERNAME}}" - userpr=" ${_Yellow}|${user}|${_creset} " - - if [ -z "${package}" ]; then - die 42 "${FUNCNAME[0]}() - missing argument: " - fi - tee_stderr 0.1 <] - - local user - user="${1:-${USERNAME}}" - sudo -i -u "${user}" bash --init-file "~${user}/.go_env" -} - -go.version(){ - local user - user="${1:-${USERNAME}}" - sudo -i -u "${user}" < + + local version dest fname sha size tmp + version="${1:-$GOVERSION}" + dest="${2:-$GOROOT}" + + info_msg "Install Go in ${dest}" + + # HINT: the python requirements needed by go.vm.version are taken from the + # developer environment. If it is not yet installed, install it now .. + pyenv.install + + # fetch go version .. + local buf=() + mapfile -t buf < <( + go.vm.version "${version}" archive "$(go.os)" "$(go.arch)" filename sha256 size + ) + if [ ${#buf[@]} -eq 0 ]; then + die 42 "can't find info of golang version: ${version}" + fi + fname="${buf[0]}" + sha="${buf[1]}" + size="$(numfmt --to=iec "${buf[2]}")" + + info_msg "Download go binary ${fname} (${size}B)" + cache_download "${_GO_DL_URL}/${fname}" "${fname}" + + pushd "${CACHE}" &>/dev/null + echo "${sha} ${fname}" >"${fname}.sha256" + if ! sha256sum -c "${fname}.sha256" >/dev/null; then + die 42 "downloaded file ${fname} checksum does not match" + else + info_msg "${fname} checksum OK" + fi + popd &>/dev/null + + info_msg "install golang" + + tmp="$(mktemp -d)" + tar -C "${tmp}" -xzf "${CACHE}/${fname}" + rm -rf "${dest}" + mkdir -p "$(dirname "${dest}")" + mv "${tmp}/go" "${dest}" + + mkdir -p "$(dirname "$GOENV")" + export GOENV + + "${GOVM_EXE}" telemetry off + "${GOVM_EXE}" env -w \ + GOBIN="$GOBIN" \ + GOTOOLCHAIN="$GOTOOLCHAIN" \ + GOCACHE="$GOCACHE" \ + GOPATH="$GOPATH" \ + GOMODCACHE="$GOMODCACHE" + + mkdir -p "${GOMODCACHE}" +} + +go.vm.list() { + + # Go versions manager; list Go versions (stable) + + python < [filename|sha256|size] + # + # kind: [archive|source|installer] + # os: [darwin|freebsd|linux|windows] + # arch: [amd64|arm64|386|armv6l|ppc64le|s390x] + + python - "$@" <