03d22f2
#!/bin/bash
03d22f2
03d22f2
DISTGIT_PATH=$(pwd)
03d22f2
03d22f2
FEDORA_VERSION=rawhide
b040fbf
DOCKER_FEDORA_VERSION=master
557675f
DISTGIT_BRANCH=rawhide
735de04
REPO_SELINUX_POLICY=${REPO_SELINUX_POLICY:-https://github.com/fedora-selinux/selinux-policy}
b719841
REPO_SELINUX_POLICY_BRANCH=${REPO_SELINUX_POLICY_BRANCH:-$FEDORA_VERSION}
735de04
REPO_CONTAINER_SELINUX=${REPO_CONTAINER_SELINUX:-https://github.com/containers/container-selinux}
b9e53a5
REPO_MACRO_EXPANDER=${REPO_MACRO_EXPANDER:-https://github.com/fedora-selinux/macro-expander.git}
b719841
b719841
# When -l is specified, we use locally created tarballs and don't download them from github
b719841
DOWNLOAD_DEFAULT_GITHUB_TARBALLS=1
b719841
if [ "$1" == "-l" ]; then
b719841
    DOWNLOAD_DEFAULT_GITHUB_TARBALLS=0
b719841
fi
03d22f2
03d22f2
git checkout $DISTGIT_BRANCH -q
03d22f2
d9d5631
POLICYSOURCES=`mktemp -d --tmpdir policysources.XXXXXX`
03d22f2
pushd $POLICYSOURCES > /dev/null
03d22f2
e042be0
git clone --depth=1 -q $REPO_SELINUX_POLICY selinux-policy \
e042be0
    -b $REPO_SELINUX_POLICY_BRANCH
e042be0
git clone --depth=1 -q $REPO_CONTAINER_SELINUX container-selinux
e042be0
git clone --depth=1 -q $REPO_MACRO_EXPANDER macro-expander
03d22f2
03d22f2
pushd selinux-policy > /dev/null
856e200
# prepare policy patches against upstream commits matching the last upstream merge
51dc83b
BASE_HEAD_ID=$(git rev-parse HEAD)
51dc83b
BASE_SHORT_HEAD_ID=$(c=${BASE_HEAD_ID}; echo ${c:0:7})
b719841
git archive --prefix=selinux-policy-$BASE_HEAD_ID/ --format tgz HEAD > $DISTGIT_PATH/selinux-policy-$BASE_SHORT_HEAD_ID.tar.gz
47948f5
popd > /dev/null
47948f5
ab3db24
pushd container-selinux > /dev/null
ab3db24
# Actual container-selinux files are in master branch
d932255
#git checkout -b ${DOCKER_FEDORA_VERSION} -t origin/${DOCKER_FEDORA_VERSION} -q
ab3db24
tar -czf container-selinux.tgz container.if container.te container.fc
03d22f2
popd > /dev/null
03d22f2
03d22f2
pushd $DISTGIT_PATH > /dev/null
b719841
if [ $DOWNLOAD_DEFAULT_GITHUB_TARBALLS == 1 ]; then
5e55c3a
    wget -O selinux-policy-${BASE_SHORT_HEAD_ID}.tar.gz https://github.com/fedora-selinux/selinux-policy/archive/${BASE_HEAD_ID}.tar.gz &> /dev/null
b719841
fi
ab3db24
cp $POLICYSOURCES/container-selinux/container-selinux.tgz .
b9e53a5
cp $POLICYSOURCES/macro-expander/macro-expander.sh ./macro-expander
8e8fb9c
chmod +x ./macro-expander
03d22f2
popd > /dev/null
03d22f2
03d22f2
popd > /dev/null
03d22f2
rm -rf $POLICYSOURCES
03d22f2
5487666
# Update commit id in selinux-policy.spec file
5487666
sed -i "s/%global commit [^ ]*$/%global commit $BASE_HEAD_ID/" selinux-policy.spec
b719841
b719841
# Update sources
5487666
sha512sum --tag selinux-policy-${BASE_SHORT_HEAD_ID}.tar.gz container-selinux.tgz macro-expander > sources
b719841
5487666
echo -e "\nSELinux policy tarball and container-selinux.tgz with container policy files have been created."
5487666
echo "Commit id of selinux-policy in spec file was changed to ${BASE_HEAD_ID}"