packages/lang/golang/golang-build.sh
Jeffery To 3dd55b504c
golang: Move module cache into DL_DIR
This also adds a config option GOLANG_MOD_CACHE_WORLD_READABLE; if
enabled, chmod is run after a Go package build to make all
files/directories in the module cache world-readable.

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
2020-10-06 16:27:52 +08:00

48 lines
822 B
Bash

#!/bin/sh
log() {
# shellcheck disable=SC2039
local IFS=" "
printf '%s\n' "$*"
}
log_error() {
# shellcheck disable=SC2039
local IFS=" "
printf 'Error: %s\n' "$*" >&2
}
cache_cleanup() {
if ! [ -d "$GO_MOD_CACHE_DIR" ]; then
return 0
fi
# in case go is called without -modcacherw
find "$GO_MOD_CACHE_DIR" -type d -not -perm -u+w -exec chmod u+w '{}' +
if [ -n "$CONFIG_GOLANG_MOD_CACHE_WORLD_READABLE" ]; then
find "$GO_MOD_CACHE_DIR" -type d -not -perm -go+rx -exec chmod go+rx '{}' +
find "$GO_MOD_CACHE_DIR" -not -type d -not -perm -go+r -exec chmod go+r '{}' +
fi
return 0
}
if [ "$#" -lt 1 ]; then
log_error "Missing command"
exit 1
fi
command="$1"
shift 1
case "$command" in
cache_cleanup)
cache_cleanup
;;
*)
log_error "Invalid command \"$command\""
exit 1
;;
esac