#!/bin/sh

set -ex

# for these tests, run snap and snapd from outside of the core snap
mkdir -p /etc/systemd/system/snapd.service.d/
cat <<EOF | tee /etc/systemd/system/snapd.service.d/no-reexec.conf
[Service]
Environment=SNAP_REEXEC=0
EOF

# required for the debian adt host
if [ "$http_proxy" != "" ]; then
    cat <<EOF | tee /etc/systemd/system/snapd.service.d/proxy.conf
[Service]
Environment=http_proxy=$http_proxy
Environment=https_proxy=$http_proxy
EOF

    # ensure environment is updated
    echo "http_proxy=$http_proxy" >> /etc/environment
    echo "https_proxy=$http_proxy" >> /etc/environment
fi
systemctl daemon-reload

# ensure we can do a connect to localhost
echo ubuntu:ubuntu|chpasswd
sed -i 's/\(PermitRootLogin\|PasswordAuthentication\)\>.*/\1 yes/' /etc/ssh/sshd_config
systemctl reload sshd.service

# and now run spread against localhost
export GOPATH=/tmp/go
go get -u github.com/snapcore/spread/cmd/spread
/tmp/go/bin/spread -v autopkgtest:
