#!/bin/sh
set -ex

# Run $1 as a normal user. This isn't currently quoted properly, but it does
# run the command in a login shell, which I think is as close as I can get and
# all I need right now. It also preserves the current working directory so that
# dep8 test resources can still be located. There was some discussion of this
# approach at: http://irclogs.ubuntu.com/2014/06/06/%23ubuntu-devel.html#t09:35

# Author: Robie Basak <robie.basak@canonical.com>

adduser --system --shell /bin/sh --disabled-password --gecos '' jujutest
adduser jujutest lxd || true

# Allow jujutest to sudo back to root (this is what juju expects)
echo 'jujutest ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/jujutest

su jujutest -l -c "cd '$PWD'; $@"
