2017-10-13 09:57:37 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2018-03-28 16:10:57 +02:00
|
|
|
# Timing creation
|
|
|
|
TIME_START=$(date +%s)
|
|
|
|
|
2017-10-13 09:57:37 +02:00
|
|
|
# Latest version of misp
|
|
|
|
VER=$(curl -s https://api.github.com/repos/MISP/MISP/tags |jq -r '.[0] | .name')
|
|
|
|
# Latest commit hash of misp
|
|
|
|
LATEST_COMMIT=$(curl -s https://api.github.com/repos/MISP/MISP/commits |jq -r '.[0] | .sha')
|
|
|
|
# Update time-stamp and make sure file exists
|
|
|
|
touch /tmp/misp-latest.sha
|
|
|
|
# SHAsums to be computed
|
|
|
|
SHA_SUMS="1 256 384 512"
|
|
|
|
|
|
|
|
# Configure your user and remote server
|
|
|
|
REL_USER="misp-release"
|
|
|
|
REL_SERVER="cpab"
|
|
|
|
|
2018-02-14 12:04:44 +01:00
|
|
|
# Enable logging for packer
|
|
|
|
PACKER_LOG=1
|
|
|
|
|
|
|
|
# Make sure we have a current work directory
|
|
|
|
PWD=`pwd`
|
|
|
|
|
2018-03-28 16:10:57 +02:00
|
|
|
# Fetching latest MISP LICENSE
|
2018-04-16 11:57:41 +02:00
|
|
|
/usr/bin/wget -q -O /tmp/LICENSE-misp https://raw.githubusercontent.com/MISP/MISP/2.4/LICENSE
|
2018-03-28 16:10:57 +02:00
|
|
|
|
2017-10-13 09:57:37 +02:00
|
|
|
# Place holder, this fn() should be used to anything signing related
|
|
|
|
function signify()
|
|
|
|
{
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
echo "This function needs an arguments"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check if latest build is still up to date, if not, roll and deploy new
|
|
|
|
if [ "${LATEST_COMMIT}" != "$(cat /tmp/misp-latest.sha)" ]; then
|
|
|
|
|
|
|
|
echo "Current MISP version is: ${VER}@${LATEST_COMMIT}"
|
|
|
|
|
|
|
|
# Search and replace for vm_name and make sure we can easily identify the generated VMs
|
|
|
|
cat misp.json| sed "s|\"vm_name\": \"MISP_demo\",|\"vm_name\": \"MISP_${VER}@${LATEST_COMMIT}\",|" > misp-deploy.json
|
|
|
|
|
|
|
|
# Build vmware VM set
|
2018-02-14 12:04:44 +01:00
|
|
|
PACKER_LOG_PATH="${PWD}/packerlog-vmware.txt"
|
|
|
|
/usr/local/bin/packer build --on-error=ask -only=vmware-iso misp-deploy.json
|
2017-10-13 09:57:37 +02:00
|
|
|
|
|
|
|
# Build virtualbox VM set
|
2018-02-14 12:04:44 +01:00
|
|
|
PACKER_LOG_PATH="${PWD}/packerlogi-vbox.txt"
|
|
|
|
/usr/local/bin/packer build --on-error=ask -only=virtualbox-iso misp-deploy.json
|
2017-10-13 09:57:37 +02:00
|
|
|
|
|
|
|
# ZIPup all the vmware stuff
|
|
|
|
zip -r MISP_${VER}@${LATEST_COMMIT}-vmware.zip packer_vmware-iso_vmware-iso_sha1.checksum packer_vmware-iso_vmware-iso_sha512.checksum output-vmware-iso
|
|
|
|
|
|
|
|
# Create a hashfile for the zip
|
|
|
|
for SUMsize in `echo ${SHA_SUMS}`; do
|
|
|
|
shasum -a ${SUMsize} *.zip > MISP_${VER}@${LATEST_COMMIT}-vmware.zip.sha${SUMsize}
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
# Current file list of everything to gpg sign and transfer
|
|
|
|
FILE_LIST="MISP_${VER}@${LATEST_COMMIT}-vmware.zip output-virtualbox-iso/MISP_${VER}@${LATEST_COMMIT}.ova packer_virtualbox-iso_virtualbox-iso_sha1.checksum packer_virtualbox-iso_virtualbox-iso_sha256.checksum packer_virtualbox-iso_virtualbox-iso_sha384.checksum packer_virtualbox-iso_virtualbox-iso_sha512.checksum MISP_${VER}@${LATEST_COMMIT}-vmware.zip.sha1 MISP_${VER}@${LATEST_COMMIT}-vmware.zip.sha256 MISP_${VER}@${LATEST_COMMIT}-vmware.zip.sha384 MISP_${VER}@${LATEST_COMMIT}-vmware.zip.sha512"
|
|
|
|
|
|
|
|
# Create the latest MISP export directory
|
|
|
|
ssh ${REL_USER}@${REL_SERVER} mkdir -p export/MISP_${VER}@${LATEST_COMMIT}
|
|
|
|
|
|
|
|
# Sign and transfer files
|
|
|
|
for FILE in ${FILE_LIST}; do
|
|
|
|
gpg --armor --output ${FILE}.asc --detach-sig ${FILE}
|
2018-03-28 16:10:57 +02:00
|
|
|
rsync -azvq --progress ${FILE} ${REL_USER}@${REL_SERVER}:export/MISP_${VER}@${LATEST_COMMIT}
|
|
|
|
rsync -azvq --progress ${FILE}.asc ${REL_USER}@${REL_SERVER}:export/MISP_${VER}@${LATEST_COMMIT}
|
2017-10-13 09:57:37 +02:00
|
|
|
ssh ${REL_USER}@${REL_SERVER} rm export/latest
|
|
|
|
ssh ${REL_USER}@${REL_SERVER} ln -s MISP_${VER}@${LATEST_COMMIT} export/latest
|
2017-12-06 15:28:00 +01:00
|
|
|
ssh ${REL_USER}@${REL_SERVER} chmod -R +r export
|
2017-10-13 09:57:37 +02:00
|
|
|
done
|
|
|
|
|
2018-01-19 12:39:07 +01:00
|
|
|
ssh ${REL_USER}@${REL_SERVER} cd export ; tree -T "MISP VM Images" -H https://www.circl.lu/misp-images/ -o index.html
|
|
|
|
|
2017-10-13 09:57:37 +02:00
|
|
|
# Remove files for next run
|
|
|
|
rm -r output-virtualbox-iso
|
|
|
|
rm -r output-vmware-iso
|
|
|
|
rm *.checksum *.zip *.sha*
|
|
|
|
rm misp-deploy.json
|
|
|
|
rm packer_virtualbox-iso_virtualbox-iso_sha1.checksum.asc
|
|
|
|
rm packer_virtualbox-iso_virtualbox-iso_sha256.checksum.asc
|
|
|
|
rm packer_virtualbox-iso_virtualbox-iso_sha384.checksum.asc
|
|
|
|
rm packer_virtualbox-iso_virtualbox-iso_sha512.checksum.asc
|
2017-12-06 15:28:00 +01:00
|
|
|
rm MISP_${VER}@${LATEST_COMMIT}-vmware.zip.asc
|
2018-04-16 11:57:41 +02:00
|
|
|
rm /tmp/LICENSE-misp
|
2017-10-13 09:57:37 +02:00
|
|
|
echo ${LATEST_COMMIT} > /tmp/misp-latest.sha
|
2018-03-28 16:10:57 +02:00
|
|
|
TIME_END=$(date +%s)
|
|
|
|
TIME_DELTA=$(expr ${TIME_END} - ${TIME_START})
|
|
|
|
|
|
|
|
echo "The generation took ${TIME_DELTA} seconds"
|
2017-10-13 09:57:37 +02:00
|
|
|
else
|
|
|
|
echo "Current MISP version ${VER}@${LATEST_COMMIT} is up to date."
|
|
|
|
fi
|