Skip to content

Instantly share code, notes, and snippets.

@larstobi
Created October 13, 2011 08:11
Show Gist options
  • Save larstobi/1283705 to your computer and use it in GitHub Desktop.
Save larstobi/1283705 to your computer and use it in GitHub Desktop.
Functions for use by https://gist.github.com/1283703
function package_installed {
name=$1
if `rpm -q $name 1>/dev/null`; then
return 0
else
return 1
fi
}
function install_package {
if `yum install --quiet -y $1 1>/dev/null`; then
return 0
else
return 1
fi
}
function ensure_package_installed {
if ! package_installed $1 ; then
echo "Installing ${1}"
install_package $1
fi
}
function ensure_packages_installed {
for package in $1; do
ensure_package_installed $package
done
}
function user_present {
if `grep -q "^$1:" /etc/passwd`; then
return 0
else
return 1
fi
}
function ensure_user_present {
if ! user_present $1; then
echo "Adding user $1"
DIR=/var/empty/$1
useradd -d $DIR $1
chown root:root $DIR
chmod 711 $DIR
fi
}
function ensure_directory {
if ! [ -d $1 ]; then
mkdir /etc/puppet
fi
}
function ensure_file {
path=$1
source=$2
if ! [ -f $path ]; then
cp $source $path && \
return 0
elif ! diff -q $source $path; then
return 0
fi
}
function ensure_yum_repo {
reponame=$1
yumrepos="/etc/yum.repos.d"
if ! [ -f $yumrepos/$reponame ]; then
cp $reponame $yumrepos/
return 0
elif ! diff -q $reponame $yumrepos/$reponame; then
return 0
fi
}
function ensure_vhost_present {
vhost=$1
vhosts="/etc/httpd/conf.d"
if ! [ -f $vhosts/$vhost ]; then
cp $vhost $vhosts/
return 0
elif ! diff -q $vhost $vhosts/$vhost; then
return 0
fi
}
function exec_puppet_apply {
manifest=$1
puppet apply $manifest
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment