#!/bin/bash
set -x
set -e
rm -rf bin
git checkout origin/v4-7-test
~/samba/config.abartlet

git checkout CVE-2018-14629-v4-7
git rebase origin/v4-7-test
make -j
git format-patch origin/v4-7-test..HEAD --stdout > CVE-2018-14629-v4-7.patch

git checkout CVE-2018-16841-v4-7
git rebase origin/v4-7-test
make -j
git format-patch origin/v4-7-test..HEAD --stdout > CVE-2018-16841-v4-7.patch

git checkout CVE-2018-16851-v4-7
git rebase origin/v4-7-test
make -j
git format-patch origin/v4-7-test..HEAD --stdout > CVE-2018-16851-v4-7.patch

git checkout mit-kdc-experimental-v4-7
git rebase origin/v4-7-test
make -j
git format-patch origin/v4-7-test..HEAD --stdout > mit-kdc-experimental-v4-7.patch

git checkout 2018-11-v4-7-CVEs
git reset --hard origin/v4-7-test
git rebase CVE-2018-14629-v4-7 && git rebase  CVE-2018-16841-v4-7 && git rebase CVE-2018-16851-v4-7 && git rebase mit-kdc-experimental-v4-7
make -j
git format-patch origin/v4-7-test..2018-11-v4-7-CVEs --stdout > 2018-11-v4-7-CVEs.patch


rm -rf bin
git checkout origin/v4-8-test
~/samba/config.abartlet

git checkout CVE-2018-14629-v4-8
git rebase origin/v4-8-test
make -j
git format-patch origin/v4-8-test..HEAD --stdout > CVE-2018-14629-v4-8.patch

git checkout CVE-2018-16841-v4-8
git rebase origin/v4-8-test
make -j
git format-patch origin/v4-8-test..HEAD --stdout > CVE-2018-16841-v4-8.patch

git checkout CVE-2018-16851-v4-8
git rebase origin/v4-8-test
make -j
git format-patch origin/v4-8-test..HEAD --stdout > CVE-2018-16851-v4-8.patch

git checkout mit-kdc-experimental-v4-8
git rebase origin/v4-8-test
make -j
git format-patch origin/v4-8-test..HEAD --stdout > mit-kdc-experimental-v4-8.patch


git checkout 2018-11-v4-8-CVEs
git reset --hard origin/v4-8-test
git rebase CVE-2018-14629-v4-8 && git rebase  CVE-2018-16841-v4-8 && git rebase CVE-2018-16851-v4-8 && git rebase mit-kdc-experimental-v4-8
make -j
git format-patch origin/v4-8-test..2018-11-v4-8-CVEs --stdout > 2018-11-v4-8-CVEs.patch


rm -rf bin
git checkout origin/v4-9-test
~/samba/config.abartlet

git checkout CVE-2018-14629-v4-9
git rebase origin/v4-9-test
make -j
git format-patch origin/v4-9-test..HEAD --stdout > CVE-2018-14629-v4-9.patch

git checkout CVE-2018-16841-v4-9
git rebase origin/v4-9-test
make -j
git format-patch origin/v4-9-test..HEAD --stdout > CVE-2018-16841-v4-9.patch

git checkout CVE-2018-16851-v4-9
git rebase origin/v4-9-test
make -j
git format-patch origin/v4-9-test..HEAD --stdout > CVE-2018-16851-v4-9.patch

git checkout CVE-2018-16852-v4-9
git rebase origin/v4-9-test
make -j
git format-patch origin/v4-9-test..HEAD --stdout > CVE-2018-16852-v4-9.patch

git checkout mit-kdc-experimental-v4-9
git rebase origin/v4-9-test
make -j
git format-patch origin/v4-9-test..HEAD --stdout > mit-kdc-experimental-v4-9.patch


git checkout 2018-11-v4-9-CVEs
git reset --hard origin/v4-9-test
git rebase CVE-2018-14629-v4-9 && git rebase  CVE-2018-16841-v4-9 && git rebase CVE-2018-16851-v4-9 && git rebase CVE-2018-16852-v4-9 && git rebase mit-kdc-experimental-v4-9
make -j
git format-patch origin/v4-9-test..2018-11-v4-9-CVEs --stdout > 2018-11-v4-9-CVEs.patch


rm -rf bin
git checkout origin/master
~/samba/config.abartlet

git checkout CVE-2018-14629-master
git rebase origin/master
make -j
git format-patch origin/master..HEAD --stdout > CVE-2018-14629-master.patch

git checkout CVE-2018-16841-master
git rebase origin/master
make -j
git format-patch origin/master..HEAD --stdout > CVE-2018-16841-master.patch

git checkout CVE-2018-16851-master
git rebase origin/master
make -j
git format-patch origin/master..HEAD --stdout > CVE-2018-16851-master.patch

git checkout CVE-2018-16852-master
git rebase origin/master
make -j
git format-patch origin/master..HEAD --stdout > CVE-2018-16852-master.patch

git checkout mit-kdc-experimental
git rebase origin/master
make -j
git format-patch origin/master..HEAD --stdout > mit-kdc-experimental-master.patch


git checkout 2018-11-master-CVEs
git reset --hard origin/master
git rebase CVE-2018-14629-master && git rebase  CVE-2018-16841-master && git rebase CVE-2018-16851-master && git rebase CVE-2018-16852-master && git rebase mit-kdc-experimental
~/samba/config.abartlet && make -j
git format-patch origin/master..2018-11-master-CVEs --stdout > 2018-11-master-CVEs.patch
