Skip to content

Commit

Permalink
Merge pull request #48 from cesarjorgemartinez/task/update_2024_04_1
Browse files Browse the repository at this point in the history
task/update_2024_04_1
  • Loading branch information
cesarjorgemartinez authored May 6, 2024
2 parents 5e4ffd1 + 3fa365b commit 5bcc4a7
Show file tree
Hide file tree
Showing 59 changed files with 2,923 additions and 1,593 deletions.
28 changes: 8 additions & 20 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,12 @@ hs_err_pid*
# Specific folders
images/
isos/
qemuinstaller/
# for each Operating System build then replicate it
CentOS7Minimal/logs/
CentOS7Minimal/output-virtualbox-iso/
CentOS7Minimal/packer.d/
CentOS7Minimal/.packerconfig
CentOS7Minimal/packer_cache/
CentOS7Minimal/packer-software/
CentOS8Minimal/logs/
CentOS8Minimal/output-virtualbox-iso/
CentOS8Minimal/packer.d/
CentOS8Minimal/.packerconfig
CentOS8Minimal/packer_cache/
CentOS8Minimal/packer-software/
Ubuntu20Minimal/logs/
Ubuntu20Minimal/output-virtualbox-iso/
Ubuntu20Minimal/packer.d/
Ubuntu20Minimal/.packerconfig
Ubuntu20Minimal/packer_cache/
Ubuntu20Minimal/packer-software/
# for each Operating System build ignore these files and directories over the first level
*/packer.zip
*/packer.exe
*/logs/
*/output-virtualbox-iso/
*/packer.d/
*/.packerconfig
*/packer_cache/

299 changes: 0 additions & 299 deletions Build-CentOS-7-Minimal-image.html

This file was deleted.

299 changes: 0 additions & 299 deletions Build-CentOS-8-Minimal-image.html

This file was deleted.

310 changes: 0 additions & 310 deletions Build-Ubuntu-20-Minimal-image.html

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ PARENT_HOME_BASEDIR="$(dirname $(readlink -f "${HOME_BASEDIR}"))"
PROGNAME="$(basename $0)"
cd ${HOME_BASEDIR}
set -e
source ${HOME_BASEDIR}/conf/virtual-machine.conf
source ${HOME_BASEDIR}/conf/vm.conf

function help ()
{
Expand Down Expand Up @@ -86,7 +86,7 @@ echo "**************************************************************************
echo

echo "INFO: Show environment variables"
env | egrep '^PACKER_|^SO_|^VBOXPATH=|^QEMUPATH=|^PATH=' | sort
env | egrep '^PACKER_|^SO_|^PATH=' | sort

if [ "${PACKER_MACHINEREADABLEOUTPUT,,}" == "true" ]
then
Expand All @@ -103,10 +103,10 @@ mkdir -p ${HOME_BASEDIR}/logs
export PACKER_LOG_PATH="logs/packerlog.txt"

echo "INFO: Obtain SO_ISOCHECKSUMIMAGE from ${SO_ISOURLSHA256SUM}"
export SO_ISOCHECKSUMIMAGE="$(grep -s "${SO_ISOIMAGENAME}" ${PARENT_HOME_BASEDIR}/isos/${SO_ISOSHA256SUMNAME} | awk '{print $1}')"
export SO_ISOCHECKSUMIMAGE="$(grep -s "${SO_ISOIMAGENAME}" ${SO_ARTIFACT_DIR}/isos/${SO_ISOSHA256SUMNAME} | awk '{print $1}')"

echo "INFO: Validate JSON with Packer"
packer-software/packer.exe ${MACHINEREADABLEPARAMETER} validate json/virtual-machine.json
./packer.exe ${MACHINEREADABLEPARAMETER} validate json/vm.json

if [ "${PACKER_DEBUG,,}" == "true" ]
then
Expand All @@ -115,47 +115,33 @@ then
fi

echo "INFO: Run the build with Packer"
packer-software/packer.exe build ${PACKERDEBUG} ${MACHINEREADABLEPARAMETER} -force \
./packer.exe build ${PACKERDEBUG} ${MACHINEREADABLEPARAMETER} -force \
-var so_adminuser=${SO_ADMINUSER} \
-var so_adminpass=${SO_ADMINPASS} \
-var so_defaultclouduser=${SO_DEFAULTCLOUDUSER} \
json/virtual-machine.json
json/vm.json

echo "INFO: Remove references of -disk001 in generated packer files in <${HOME_BASEDIR}/output-virtualbox-iso>"
if [ -f ${HOME_BASEDIR}/output-virtualbox-iso/${SO_DISTRIBUTION}${SO_SHORTVERSION}-${SO_NAMEVERSION}-${SO_IMAGETYPE}-${SO_BUILDDATE}-disk001.vmdk ]
if [ -f ${HOME_BASEDIR}/output-virtualbox-iso/${SO_VMFULLNAME}-disk001.vmdk ]
then
mv ${HOME_BASEDIR}/output-virtualbox-iso/${SO_DISTRIBUTION}${SO_SHORTVERSION}-${SO_NAMEVERSION}-${SO_IMAGETYPE}-${SO_BUILDDATE}-disk001.vmdk \
${HOME_BASEDIR}/output-virtualbox-iso/${SO_DISTRIBUTION}${SO_SHORTVERSION}-${SO_NAMEVERSION}-${SO_IMAGETYPE}-${SO_BUILDDATE}.vmdk
mv ${HOME_BASEDIR}/output-virtualbox-iso/${SO_VMFULLNAME}-disk001.vmdk ${HOME_BASEDIR}/output-virtualbox-iso/${SO_VMFULLNAME}.vmdk
fi
if [ -f ${HOME_BASEDIR}/output-virtualbox-iso/${SO_DISTRIBUTION}${SO_SHORTVERSION}-${SO_NAMEVERSION}-${SO_IMAGETYPE}-${SO_BUILDDATE}.ovf ]
if [ -f ${HOME_BASEDIR}/output-virtualbox-iso/${SO_VMFULLNAME}.ovf ]
then
sed -i -e 's/-disk001//g' ${HOME_BASEDIR}/output-virtualbox-iso/${SO_DISTRIBUTION}${SO_SHORTVERSION}-${SO_NAMEVERSION}-${SO_IMAGETYPE}-${SO_BUILDDATE}.ovf
sed -i -e 's/-disk001//g' ${HOME_BASEDIR}/output-virtualbox-iso/${SO_VMFULLNAME}.ovf ${HOME_BASEDIR}/output-virtualbox-iso/${SO_VMFULLNAME}.mf
fi

echo "INFO: Remove all images named as <${PARENT_HOME_BASEDIR}/images/${SO_DISTRIBUTION}${SO_MAJORVERSION}.*${SO_IMAGETYPE}*>"
mkdir -p ${PARENT_HOME_BASEDIR}/images
rm -rf ${PARENT_HOME_BASEDIR}/images/${SO_DISTRIBUTION}${SO_MAJORVERSION}.*${SO_IMAGETYPE}*
echo "INFO: Move vmdk and ovf files from <${HOME_BASEDIR}/output-virtualbox-iso> to <${PARENT_HOME_BASEDIR}/images>"
find ${HOME_BASEDIR}/output-virtualbox-iso -maxdepth 1 -type f | xargs -r -I '{}' mv {} ${PARENT_HOME_BASEDIR}/images
echo "INFO: Remove all images named as <${SO_ARTIFACT_DIR}/images/${SO_DISTRIBUTION}${SO_MAJORVERSION}*${SO_IMAGETYPE}*>"
mkdir -p ${SO_ARTIFACT_DIR}/images
rm -rf "${SO_ARTIFACT_DIR}/images/${SO_DISTRIBUTION}${SO_MAJORVERSION}*${SO_IMAGETYPE}*"
echo "INFO: Move vmdk and ovf files from <${HOME_BASEDIR}/output-virtualbox-iso> to <${SO_ARTIFACT_DIR}/images>"
find ${HOME_BASEDIR}/output-virtualbox-iso -maxdepth 1 -type f | xargs -r -I '{}' mv {} ${SO_ARTIFACT_DIR}/images

cd ${PARENT_HOME_BASEDIR}/images

echo "INFO: Get vmdk file inside <${PARENT_HOME_BASEDIR}/images>"
SEARCHFILE=".*${SO_DISTRIBUTION}${SO_SHORTVERSION}-${SO_NAMEVERSION}-${SO_IMAGETYPE}-[0-9]*.vmdk"
VMDK_FILENAME="$(find * -type f -regex "${SEARCHFILE}" 2>/dev/null || true)"

if [ "${VMDK_FILENAME}" == "" ]
if [ -f ${SO_ARTIFACT_DIR}/images/${SO_VMFULLNAME}.vmdk ]
then
echo "ERROR: Can not find any vmdk file"
exit 1
echo "INFO: Convert vmdk format <${SO_ARTIFACT_DIR}/images/${SO_VMFULLNAME}.vmdk> to qcow2 format <${SO_ARTIFACT_DIR}/images/${SO_VMFULLNAME}.qcow2>"
qemu-img.exe convert -c -f vmdk -O qcow2 $(cygpath -w ${SO_ARTIFACT_DIR}/images/${SO_VMFULLNAME}.vmdk) $(cygpath -w ${SO_ARTIFACT_DIR}/images/${SO_VMFULLNAME}.qcow2)
else
echo "ERROR: Disk file <${SO_ARTIFACT_DIR}/images/${SO_VMFULLNAME}.vmdk> not found"
fi
ONLYNAME_IMAGE="$(basename -s .vmdk ${VMDK_FILENAME})"

echo "INFO: VMDK file to convert <${VMDK_FILENAME}>"
echo "INFO: Image name to convert <${ONLYNAME_IMAGE}>"

echo "INFO: Convert vmdk file to qcow2"
qemu-img.exe convert -c -f vmdk ${ONLYNAME_IMAGE}.vmdk -O qcow2 ${ONLYNAME_IMAGE}.qcow2

cd ${HOME_BASEDIR}

45 changes: 0 additions & 45 deletions CentOS7Minimal/bin/download-and-install-packer.sh

This file was deleted.

37 changes: 0 additions & 37 deletions CentOS7Minimal/bin/download-iso.sh

This file was deleted.

31 changes: 31 additions & 0 deletions CentOS7Minimal/bin/getiso.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

set -o pipefail

RESULT=0
trap catch_errors ERR
function catch_errors() {
RESULT=$?
}

SCRIPT_BASEDIR="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
HOME_BASEDIR="$(dirname $(readlink -f "${SCRIPT_BASEDIR}"))"
PARENT_HOME_BASEDIR="$(dirname $(readlink -f "${HOME_BASEDIR}"))"
cd ${HOME_BASEDIR}
set -e
source ${HOME_BASEDIR}/conf/vm.conf

echo "INFO: show environment variables"
env | egrep '^PACKER_|^SO_|^PATH=' | sort

mkdir -p ${SO_ARTIFACT_DIR}/isos
cd ${SO_ARTIFACT_DIR}/isos

echo "INFO: Get <${SO_ISOURLIMAGE}> into <${SO_ARTIFACT_DIR}/isos> if already is not downloaded"
curl -C - -L -O "${SO_ISOURLIMAGE}"

echo "INFO: Get <${SO_ISOURLSHA256SUM}> into <${SO_ARTIFACT_DIR}/isos> if already is not downloaded"
curl -C - -L -o ${SO_ISOSHA256SUMNAME} "${SO_ISOURLSHA256SUM}"

cd ${HOME_BASEDIR}

34 changes: 34 additions & 0 deletions CentOS7Minimal/bin/getpacker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

set -o pipefail

RESULT=0
trap catch_errors ERR
function catch_errors() {
RESULT=$?
}

SCRIPT_BASEDIR="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
HOME_BASEDIR="$(dirname $(readlink -f "${SCRIPT_BASEDIR}"))"
cd ${HOME_BASEDIR}
set -e
source ${HOME_BASEDIR}/conf/vm.conf

echo "INFO: show environment variables"
env | egrep '^PACKER_|^SO_|^PATH=' | sort

echo "INFO: Get packer software <${PACKER_VERSION}> into <${HOME_BASEDIR}/packer.zip>"
if [ "${PACKER_VERSION}" == "nightly" ]
then
curl -L -o ${HOME_BASEDIR}/packer.zip $(curl -L -s 'https://api.github.com/repos/hashicorp/packer/releases/tags/nightly' | jq -r '.assets[] | select(.browser_download_url | endswith("windows_amd64.zip")) | .browser_download_url')
else
curl -L -o ${HOME_BASEDIR}/packer.zip https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_windows_amd64.zip
fi

echo "INFO: Unzip packer ${PACKER_VERSION}"
unzip -L -o packer.zip 'packer*'
chmod 755 *.exe
echo "INFO: Show packer version from the executable: $(${HOME_BASEDIR}/packer --version)"

cd ${HOME_BASEDIR}

Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ HOME_BASEDIR="$(dirname $(readlink -f "${SCRIPT_BASEDIR}"))"
PARENT_HOME_BASEDIR="$(dirname $(readlink -f "${HOME_BASEDIR}"))"
cd ${HOME_BASEDIR}
set -e
source ${HOME_BASEDIR}/conf/virtual-machine.conf
source ${HOME_BASEDIR}/conf/vm.conf

echo "INFO: Show environment variables"
env | egrep '^PACKER_|^SO_|^VBOXPATH=|^QEMUPATH=|^PATH=' | sort
env | egrep '^PACKER_|^SO_|^PATH=' | sort

mkdir -p ${PARENT_HOME_BASEDIR}/images
cd ${PARENT_HOME_BASEDIR}/images
mkdir -p ${SO_ARTIFACT_DIR}/images
cd ${SO_ARTIFACT_DIR}/images

echo "INFO: Get qcow2 file inside <${PARENT_HOME_BASEDIR}/images>"
echo "INFO: Get qcow2 file inside <${SO_ARTIFACT_DIR}/images>"
SEARCHFILE=".*${SO_DISTRIBUTION}${SO_SHORTVERSION}-${SO_NAMEVERSION}-${SO_IMAGETYPE}-[0-9]*.qcow2"
QCOW2_FILENAME="$(find * -type f -regex "${SEARCHFILE}" 2>/dev/null || true)"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ export PACKER_SSH_HANDSHAKE_ATTEMPTS=10
export PACKER_CONFIG="$(cygpath -m ${HOME_BASEDIR}/.packerconfig)"
# The location of the packer.d config directory
export PACKER_CONFIG_DIR="$(cygpath -m ${HOME_BASEDIR})"
export VBOXPATH="/cygdrive/c/Program Files/Oracle/VirtualBox"
export QEMUPATH="/cygdrive/c/Program Files/qemu"
export PATH="${VBOXPATH}:${QEMUPATH}:${PATH}"
# Store ISO and virtual machine files inside the Git repository in <gitrootdirectory>/(images|isos)
# export SO_ARTIFACT_DIR=${PARENT_HOME_BASEDIR}
# Store ISO and virtual machine files outside the Git repository in $HOME/(images|isos)
export SO_ARTIFACT_DIR=$HOME
export SO_ARTIFACT_DIR_WIN=$(cygpath -m ${SO_ARTIFACT_DIR})
export SO_GUESTOSTYPE="RedHat_64"
# Disk size of virtual machine in MB
export SO_GUESTDISKSIZE=40960
Expand All @@ -27,10 +29,10 @@ export SO_SHORTVERSION="${SO_MAJORVERSION}.${SO_MINORVERSION}"
# The iso file type to download and use can be Minimal or DVD (can exists others but here only use these types)
export SO_ISOTYPE="Minimal"
export SO_ISOIMAGENAME="${SO_DISTRIBUTION}-${SO_MAJORVERSION}-x86_64-${SO_ISOTYPE}-${SO_NAMEVERSION}.iso"
export SO_ISOURLIMAGE="http://ftp.uma.es/mirror/${SO_DISTRIBUTION}/${SO_MAJORVERSION}.${SO_MINORVERSION}.${SO_NAMEVERSION}/isos/x86_64/${SO_ISOIMAGENAME}"
export SO_ISOURLIMAGE="http://ftp.rediris.es/mirror/${SO_DISTRIBUTION}/${SO_MAJORVERSION}.${SO_MINORVERSION}.${SO_NAMEVERSION}/isos/x86_64/${SO_ISOIMAGENAME}"
export SO_ISOSHA256SUMNAME="${SO_ISOIMAGENAME%.iso}.sum"
export SO_ISOCHECKSUMTYPE="sha256"
export SO_ISOURLSHA256SUM="http://ftp.uma.es/mirror/${SO_DISTRIBUTION}/${SO_MAJORVERSION}.${SO_MINORVERSION}.${SO_NAMEVERSION}/isos/x86_64/sha256sum.txt"
export SO_ISOURLSHA256SUM="http://ftp.rediris.es/mirror/${SO_DISTRIBUTION}/${SO_MAJORVERSION}.${SO_MINORVERSION}.${SO_NAMEVERSION}/isos/x86_64/sha256sum.txt"
export SO_BUILDDATE="$(date +%Y%m%d)"
export SO_VMFULLNAME="${SO_DISTRIBUTION}${SO_SHORTVERSION}-${SO_NAMEVERSION}-${SO_IMAGETYPE}-${SO_BUILDDATE}"
# The time to wait after booting the initial virtual machine before typing the boot_command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Conflicts=shutdown.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/control-cloud-init.sh
ExecStart=/usr/local/bin/controlcloud-init.sh
RemainAfterExit=yes
TimeoutSec=0

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Requires=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/guest-vmtools.sh
ExecStart=/usr/local/bin/guestvmtools.sh
RemainAfterExit=yes
TimeoutSec=0

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ if [ "$(echo "${MACHINETYPE}" | grep '^virtualbox$')" != "" ]
then
echo "INFO: Detected VM of type VirtualBox. Reinstalling the Guest Additions"
sudo touch /opt/reinstallGuestAdditions.action
sudo /usr/local/bin/guest-vmtools.sh
sudo /usr/local/bin/guestvmtools.sh
fi

echo "INFO: You need to reboot your O.S. to apply the changes correctly"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if [ "$(echo "${MACHINETYPE}" | grep '^virtualbox$')" != "" ]
then
echo "INFO: Detected VM of type VirtualBox. Reinstalling the Guest Additions"
sudo touch /opt/reinstallGuestAdditions.action
sudo /usr/local/bin/guest-vmtools.sh
sudo /usr/local/bin/guestvmtools.sh
fi

echo "INFO: You need to reboot your O.S. to apply the changes correctly"
Expand Down
Loading

0 comments on commit 5bcc4a7

Please sign in to comment.