Skip to content

Commit

Permalink
Add logging into the scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
brwyatt committed Mar 8, 2015
1 parent 59695a9 commit 7503d45
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 15 deletions.
4 changes: 2 additions & 2 deletions UserData
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions scripts/run → scripts/buildAMI
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
#!/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/')

# 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}")"
19 changes: 15 additions & 4 deletions scripts/global/installPythonPackages
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
21 changes: 17 additions & 4 deletions scripts/global/installSystemPackages
Original file line number Diff line number Diff line change
@@ -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
23 changes: 18 additions & 5 deletions scripts/global/upgradeSystemPackages
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7503d45

Please sign in to comment.