github.com/weaveworks/common@v0.0.0-20230728070032-dd9e68f319d5/tools/build/golang/build.sh (about)

     1  #!/bin/sh
     2  
     3  set -eu
     4  
     5  if [ -n "${SRC_NAME:-}" ]; then
     6      SRC_PATH=${SRC_PATH:-$GOPATH/src/$SRC_NAME}
     7  elif [ -z "${SRC_PATH:-}" ]; then
     8      echo "Must set either \$SRC_NAME or \$SRC_PATH."
     9      exit 1
    10  fi
    11  
    12  # If we run make directly, any files created on the bind mount
    13  # will have awkward ownership.  So we switch to a user with the
    14  # same user and group IDs as source directory.  We have to set a
    15  # few things up so that sudo works without complaining later on.
    16  uid=$(stat --format="%u" "$SRC_PATH")
    17  gid=$(stat --format="%g" "$SRC_PATH")
    18  echo "weave:x:$uid:$gid::$SRC_PATH:/bin/sh" >>/etc/passwd
    19  echo "weave:*:::::::" >>/etc/shadow
    20  echo "weave	ALL=(ALL)	NOPASSWD: ALL" >>/etc/sudoers
    21  
    22  su weave -c "PATH=$PATH make -C $SRC_PATH BUILD_IN_CONTAINER=false $*"