#!/bin/bash
set -ex

# add openstack juno repo
sudo apt-get update && apt-get install -y software-properties-common
sudo add-apt-repository -y cloud-archive:juno

# add galeracluster repo
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 D669017EBC19DDBA
sudo add-apt-repository 'deb http://releases.galeracluster.com/ubuntu trusty main'

sudo apt-get update

sudo apt-get install reprepro -y

#download packages
#set packages = $getVar('packages', [])

#for pkg in $packages
sudo apt-get -d install $pkg -y
#end for

#make repo
mkdir -p trusty-juno-ppa/conf
cat <<EOF > trusty-juno-ppa/conf/distributions
Codename: trusty
Components: main
Architectures: amd64
EOF

mkdir deb
find /var/cache/apt/ -name *.deb | xargs -i cp {} deb

reprepro -b trusty-juno-ppa includedeb trusty deb/*.deb

tar -zcvf /trusty-juno-ppa.tar.gz ./trusty-juno-ppa