#!/usr/bin/env bash
groupadd --system lxd
adduser --system lxd lxd

## Add user to lxd group to allow non-privileged user access to LXD
#usermod -a -G lxd <user>

sudo apt update
sudo apt install acl dnsmasq-base git golang liblxc1 lxcfs lxc-dev python-pylxd libacl1-dev make pkg-config rsync squashfs-tools tar xz-utils

#=============================================================================
# golang deps
#golang-any-shared-dev use: 
apt install -y golang-any # or similar

# golang-yaml.v2-dev transitional for 
apt install -y golang-gopkg-yaml.v2-dev

#golang-websocket-dev transitional for 
apt install -y golang-github-gorilla-websocket-dev

# golang-go.crypto-dev transitional package for: 
apt install -y golang-golang-x-crypto-dev

apt install -y \
	golang-petname-dev \
	golang-context-dev \
	golang-github-gorilla-mux-dev \
	golang-github-gosexy-gettext-dev \
	golang-github-mattn-go-colorable-dev \
	golang-github-mattn-go-sqlite3-dev \
	golang-github-olekukonko-tablewriter-dev \
	golang-github-pborman-uuid-dev \
	golang-gocapability-dev \
	golang-gopkg-tomb.v2-dev \
	golang-gopkg-flosch-pongo2.v3-dev \
	golang-github-inconshreveable-log15.v2-dev

#=============================================================================
# Missing - build from git as it's in NEW
# golang-gopkg-lxc-go-lxc.v2-dev

# build deps:
apt install -y \
	dh-golang \
       	golang-go\
	lxc-dev\
	pkg-config

# https://pkg-go.alioth.debian.org/workflow-changes.html
#dget -u http://archive.ubuntu.com/ubuntu/pool/main/g/golang-gopkg-lxc-go-lxc.v2/golang-gopkg-lxc-go-lxc.v2_0.0~git20160405.0.85d46fc-0ubuntu2.dsc

git clone https://anonscm.debian.org/cgit/pkg-go/packages/golang-gopkg-lxc-go-lxc.v2.git
cd ./golang-gopkg-lxc-go-lxc.v2
apt install -y cowbuilder dh-golang

DIST=$(lsb_release --short --codename)
ARCH=$(dpkg --print-architecture)
#DIST=ascii ARCH=amd64 git-pbuilder create
DIST=${DIST} ARCH=${ARCH} git-pbuilder update

gbp buildpackage --git-pbuilder --git-arch=${ARCH} --git-dist=${DIST}

# Should probably use a containerized reprepro FIXME
cp golang-gopkg-lxc-go-lxc.v2-dev_*_all.deb /srv/pbuilder/deps/

#=============================================================================
# LXD
# Build-Depends: 
apt install -y \
	debhelper \
	dh-apparmor \
	dh-golang \
	golang-go \
	help2man \
	libacl1-dev \
	libsqlite3-dev \
	lxc-dev \
	pkg-config \
	python3-lxc

# dsc creates 
#	lxd, 
#	lxd-tools, 
#	lxd-client, 
#	lxc2, in debian just lxc 1:2.0.7-2
#	golang-github-lxc-lxd-dev

#dget -u http://archive.ubuntu.com/ubuntu/pool/main/l/lxd/lxd_2.21-0ubuntu3.dsc
#dget -u http://archive.ubuntu.com/ubuntu/pool/main/l/lxd/lxd_2.21-0ubuntu3~16.04.1.dsc
#dget -u http://archive.ubuntu.com/ubuntu/pool/main/l/lxd/lxd_2.21-0ubuntu3~17.10.1.dsc

git clone http://github.com/lxc/lxd-pkg-ubuntu
