Use builtins instead of env vars for atmel_tools

The atmel_tools.sh script requires root privileges to run, and
previously it was checking for this at the beginning of the script by
looking at the ${USER} and ${UID} environment variables and making sure
they were "root" and "0" respectively.  This works great when you run
the script from an environment with those values set, such as running
it manually from the command line.

Unfortunately those values aren't always set such as if this is run
through minijail0 by debugd.  Even when the script is, in fact, run as
root, there's no values in those variables and the script exits before
doing anything.

This change modifies that check to use values pulled from the builtins
"id" and "whoami" in an attempt to guarantee that the values are always
populated.  In my testing this approach seems to work regardless of how
the script is run.

BUG=b:37777693
TEST=I used the script to query the Atmel reference values on my Samus
both from the command line and through a modified version of debugd.
Both were able to correctly identify themselves as being run as root
whereas before the version run through debugd failed.  When run as a
user that is not root, they both fail as expected still.

Change-Id: I78d24c257546b9576899959e2082d97dabb36299
Signed-off-by: Charlie Mooney <charliemooney@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/493829
Reviewed-by: Jingkui Wang <jkwang@google.com>
(cherry picked from commit dbca0fb3580fcea784b9cf9312ec113941b5a394)
Reviewed-on: https://chromium-review.googlesource.com/516471
1 file changed
tree: a4f0f2fa3d2b50d037f489bccedaa6553701f98d
  1. policies/
  2. scripts/
  3. LICENSE
  4. OWNERS
  5. README