Adding Chapter 1 : Packer will build for you

This commit is contained in:
2021-03-18 16:11:35 +01:00
commit 02e13dfb00
97 changed files with 4630 additions and 0 deletions

View File

@ -0,0 +1,30 @@
#!/bin/bash
if [[ $# -ne 3 ]]
then
echo Missing arguments
exit 2
fi
WORKDIR=${1}
DOMAIN=${2}
VERSION=${3}
function findImages()
{
find ${1} -iname "${2}*.img"
}
sleep 5
for imageName in $(findImages ${WORKDIR} ${DOMAIN})
do
latestName=$(echo $imageName | sed "s/.img/_latest.img/g")
newName=$(echo $imageName | sed "s/.img/_${VERSION}.img/g")
virt-sparsify -x --compress --tmp ./ --format qcow2 ${imageName} ${newName}
if [[ $? -eq 0 ]]
then
ln -s ${newName} ${latestName}
rm -rf ${imageName}
fi
done

View File

@ -0,0 +1,65 @@
#!/bin/bash
WORKDIR=${1}
sys_img=$(find ${WORKDIR} -name "*.img")
provisionDirectory=${2}
if [[ ! -d ${provisionDirectory} ]]
then
mkdir -p ${provisionDirectory}
fi
tmpMntPnt=$(mktemp -d)
tmpWorkDir=$(mktemp -d)
#
# $1 : qcow image
# $2 : mount point
#
function mountQcowImage()
{
guestmount -a $1 -i --ro ${2}
return ${?}
}
function getEoleDbConfig()
{
workdir=${1}
mntPnt=${2}
provisionDir=${3}
cd ${workdir}
cp ${mntPnt}/etc/eole/eole-db.d/* .
mkdir -p ${provisionDir}/etc/eole/eole-db.d
cp * ${provisionDir}/etc/eole/eole-db.d
cd -
}
function processConfiguration()
{
workdir=${1}
mntPnt=${2}
provisionDir=${3}
files=$(awk '/file:/ {gsub(/,|"|\047/,""); print $3}' ${mntPnt}/etc/eole/eole-db.d/*)
for file in ${files}
do
dirname=$(dirname ${file})
dest="${provisionDir}/${dirname}"
mkdir -p ${dest}
cp ${mntPnt}${file} ${dest}
done
}
mountQcowImage ${sys_img} ${tmpMntPnt}
getEoleDbConfig ${tmpWorkDir} ${tmpMntPnt} ${provisionDirectory}
processConfiguration ${tmpWorkDir} ${tmpMntPnt} ${provisionDirectory}
umount ${tmpMntPnt}
rm -rf ${tmpMntPnt}
#rm -rf ${tmpWorkDir}