#!/bin/bash
set -x
set -e
set -o pipefail
set -u

#to destroy
# lxc-stop --name $container
# lxc-destroy --name $container

date
git describe --always

container=gnatstuff
inner=iuser
locker=/afs/sipb.mit.edu/project/gcc-6plus/src


#this container location is for mkc
lxc-create -t download -n $container --dir /scratch/kenta/kenta2/$container -- -d ubuntu -r trusty -a amd64
rm -f ~/gccada.log
lxc-start -n $container -o ~/mylxc.log -d
incontainer="lxc-attach -n $container --"
inlocal="$incontainer sudo -u $inner"
#setting UIDs to match the host does not work
$incontainer useradd -m $inner
#needed for networking to start
sleep 5
tar cf - -C $locker sources.list | $incontainer tar xf - -C /etc/apt
$incontainer apt-get update -q

$incontainer dpkg -l
$incontainer apt-get install -q --no-install-recommends -y debian-keyring devscripts fakeroot gdb
$incontainer apt-get install -q --no-install-recommends -y aptitude
#build-essential does not seem essential?
$incontainer apt-get build-dep -q -y --no-install-recommends gcc-4.8
$incontainer aptitude build-dep -q -y -R gnat-4.8

udir=/home/$inner/i

$inlocal mkdir $udir

# gnat-4.8 does not install gnatgcc
tar cf - user.sh | $inlocal tar xf - -C $udir
nice time $inlocal bash $udir/user.sh
date
true $0 All done
