Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagebash
themeRDark
titleSet if not already defined
collapsetrue
: ${var=value}

This one is obscure....<TODO> explain!

Code Block
languagebash
themeRDark
titleSet if not defined OR set to the empty string
collapsetrue
: ${var:=value}

...

Code Block
languagebash
themeRDark
titleInstall packages via sudo only if it is not already installed
collapsetrue
install_package ()
{
  PACKAGE_NAME=$1
  # Does not work if the package has been installed and later removed
  # dpkg -s ${PACKAGE_NAME} > /dev/null
  dpkg-query -W -f='${Status}' ${PACKAGE_NAME} | grep -q -P '^install ok installed$'
  if [ $? -ne 0 ]; then
    sudo apt-get -q -y install ${PACKAGE_NAME} > /dev/null
  else
    pretty_print "  $(padded_message ${PACKAGE_NAME} "found")"
    return 0
  fi
  if [ $? -ne 0 ]; then
    pretty_error "  $(padded_message ${PACKAGE_NAME} "failed")"
    return 1
  fi
  pretty_warning "  $(padded_message ${PACKAGE_NAME} "installed")"
  return 0
}

# usage
install_package ansible

...