Sha256: 8bf989b5340002d8b292e6e5a75294e6deaaaa3dfd9693feb01feb3ea6c0a2b7

Contents?: true

Size: 1.04 KB

Versions: 7

Compression:

Stored size: 1.04 KB

Contents

# This file is used to define functions under the sunzi.* namespace.

# Set $sunzi_pkg to "apt-get" or "yum", or abort.
#
if which apt-get >/dev/null 2>&1; then
  export sunzi_pkg=apt-get
elif which yum >/dev/null 2>&1; then
  export sunzi_pkg=yum
fi

if [ "$sunzi_pkg" = '' ]; then
  echo 'sunzi only supports apt-get or yum!' >&2
  exit 1
fi

# Mute STDOUT and STDERR
#
function sunzi.mute() {
  echo "Running \"$@\""
  `$@ >/dev/null 2>&1`
  return $?
}

# Installer
#
function sunzi.installed() {
  if [ "$sunzi_pkg" = 'apt-get' ]; then
    dpkg -s $@ >/dev/null 2>&1
  elif [ "$sunzi_pkg" = 'yum' ]; then
    rpm -qa | grep $@ >/dev/null
  fi
  return $?
}

# When there's "set -e" in install.sh, sunzi.install should be used with if statement,
# otherwise the script may exit unexpectedly when the package is already installed.
#
function sunzi.install() {
  if sunzi.installed "$@"; then
    echo "$@ already installed"
    return 1
  else
    echo "No packages found matching $@. Installing..."
    sunzi.mute "$sunzi_pkg -y install $@"
    return 0
  fi
}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sunzi-2.1.0 templates/create/recipes/sunzi.sh
sunzi-2.0.0 templates/create/recipes/sunzi.sh
sunzi-1.5.2 lib/templates/create/recipes/sunzi.sh
sunzi-1.5.1 lib/templates/create/recipes/sunzi.sh
sunzi-1.5.0 lib/templates/create/recipes/sunzi.sh
sunzi-1.4.0 lib/templates/create/recipes/sunzi.sh
sunzi-1.3.0 lib/templates/create/recipes/sunzi.sh