diff --git a/UserData b/UserData index 664b27b..c8eb9f6 100755 --- a/UserData +++ b/UserData @@ -6,5 +6,5 @@ targetdir=/opt/${maintainer} mkdir -p ${targetdir} &&\ curl -L https://github.com/${maintainer}/${repo}/archive/${release}.tar.gz |\ tar -xz -C ${targetdir} &&\ -mv ${targetdir}/${repo}-${release} ${targetdir}/${repo} -${targetdir}/${repo}/scripts/run +mv ${targetdir}/${repo}-${release} ${targetdir}/${repo} &&\ +${targetdir}/${repo}/scripts/buildAMI &> /var/log/ami_build.log diff --git a/scripts/run b/scripts/buildAMI similarity index 66% rename from scripts/run rename to scripts/buildAMI index a01155a..b3e6e7f 100755 --- a/scripts/run +++ b/scripts/buildAMI @@ -1,5 +1,10 @@ #!/bin/bash +echo "*************************" +echo "* AWS EC2 AMI Generator *" +echo "*************************" +export dateformat='%Y-%m-%d %H:%M:%S.%N UTC%z' + scriptroot=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) distro=$(lsb_release -i | sed -r 's/^Distributor ID:\W*(.*)$/\L\1/') release=$(lsb_release -c | sed -r 's/^Codename:\W*(.*)$/\L\1/') @@ -7,23 +12,30 @@ release=$(lsb_release -c | sed -r 's/^Codename:\W*(.*)$/\L\1/') # Add global scripts directory globalscripts="${scriptroot}/global" if [ -d "${globalscripts}" ]; then + echo "Found global scripts: ${globalscripts}" PATH="${globalscripts}:${PATH}" fi # Add distro-specific scripts directory distroscripts="${scriptroot}/${distro}/all" if [ -d "${distroscripts}" ]; then + echo "Found distro-specific scripts: ${distroscripts}" PATH="${distroscripts}:${PATH}" fi # Add release-specific scripts directory releasescripts="${scriptroot}/${distro}/${release}" if [ -d "${releasescripts}" ]; then + echo "Found release-specific scripts: ${releasescripts}" PATH="${releasescripts}:${PATH}" fi export PATH +echo -e "\nStarting at $(date +"${dateformat}")" + upgradeSystemPackages installSystemPackages python3 python3-pip puppet cloud-utils installPythonPackages awscli + +echo -e "\nFinished at $(date +"${dateformat}")" diff --git a/scripts/global/installPythonPackages b/scripts/global/installPythonPackages index 2f700a5..792c9c9 100755 --- a/scripts/global/installPythonPackages +++ b/scripts/global/installPythonPackages @@ -1,7 +1,11 @@ #!/bin/bash +echo "==Python Package Installer==" +if [[ "x${dateformat}" != "x" ]]; then + echo -e "Begin at $(date +"${dateformat}")" +fi if [ $# -lt 1 ]; then - echo "Please specify at least one package to install" >&2 + echo -e "\t[FAIL] Please specify at least one package to install" >&2 exit 1 fi @@ -10,9 +14,16 @@ if pip3 --version &>/dev/null; then elif pip --version &>/dev/null; then pip=pip else - echo "No suitable pip found found" >&2 + echo -e "\t[FAIL] No suitable pip found found" >&2 exit 2 fi -$pip install --upgrade "$@" #&>/dev/null -exit $? +echo -e "\tRunning $pip install..." +$pip install --upgrade "$@" &>/dev/null +exval=$? +if [ $exval -eq 0 ]; then + echo -e "\t[DONE]" +else + echo -e "\t[FAIL] Code: ${exval}" + exit $exval +fi diff --git a/scripts/global/installSystemPackages b/scripts/global/installSystemPackages index ab26555..58f0977 100755 --- a/scripts/global/installSystemPackages +++ b/scripts/global/installSystemPackages @@ -1,17 +1,30 @@ #!/bin/bash +echo "==System Package Installer==" +if [[ "x${dateformat}" != "x" ]]; then + echo -e "Begin at $(date +"${dateformat}")" +fi if [ $# -lt 1 ]; then - echo "Please specify at least one package to install" >&2 + echo -e "\t[FAIL] Please specify at least one package to install" >&2 exit 1 fi if apt-get --version &>/dev/null; then + echo -e "\tRunning apt-get install..." apt-get install --assume-yes "$@" &>/dev/null - exit $? + exval=$? elif yum --version &>/dev/null; then + echo -e "\tRunning yum install..." yum --assumeyes install "$@" &>/dev/null - exit $? + exval=$? else - echo "No package mangers found" >&2 + echo -e "\t[FAIL] No package mangers found" >&2 exit 2 fi + +if [ $exval -eq 0 ]; then + echo -e "\t[DONE]" +else + echo -e "\t[FAIL] Code: ${exval}" + exit $exval +fi diff --git a/scripts/global/upgradeSystemPackages b/scripts/global/upgradeSystemPackages index 67d88d7..46d5069 100755 --- a/scripts/global/upgradeSystemPackages +++ b/scripts/global/upgradeSystemPackages @@ -1,16 +1,29 @@ #!/bin/bash +echo "==System Package Updater==" +if [[ "x${dateformat}" != "x" ]]; then + echo -e "Begin at $(date +"${dateformat}")" +fi if apt-get --version &>/dev/null; then + echo -e "Running apt-get update..." apt-get update &>/dev/null exval=$? - if [ $exval -ne 0 ]; then - exit $exval + if [ $exval -eq 0 ]; then + echo -e "Running apt-get upgrade..." + apt-get upgrade --assume-yes &>/dev/null + exval=$? fi - apt-get upgrade --assume-yes &>/dev/null - exit $? fi if yum --version &>/dev/null; then + echo -e "Running yum upgrade..." yum --assumeyes upgrade &>/dev/null - exit $? + exval=$? +fi + +if [ $exval -eq 0 ]; then + echo -e "\t[DONE]" +else + echo -e "\t[FAIL] Code: ${exval}" + exit $exval fi