@@ -100,6 +100,55 @@ DEBOPS_GALAXY_ACCOUNT="debops"
 # Path to install roles, relative to debops-playbooks repository
 DEBOPS_ROLES_PATH="${DEBOPS_PLAYBOOK_DIR}/roles"
 
+
+# ---- Functions ----
+
+# Find specified file or directory in parent dir (if not specified, finds $DEBOPS_CONFIG)
+# Source: https://unix.stackexchange.com/questions/13464
+find_up () {
+  local name=${1:-$DEBOPS_CONFIG}
+  local slashes="${PWD//[^\/]/}"
+  local directory="${PWD}"
+
+  for (( n=${#slashes}; n>0; --n )) ; do
+    test -e "${directory}/${name}" && echo "$(readlink -f ${directory}/${name})" && return
+    directory="$directory/.."
+  done
+}
+
+# Display error message and exit
+error_msg () {
+  local severity="${2:-Error}"
+  local message="${1}"
+
+  echo >&2 "${SCRIPT_NAME}: ${severity}: ${message}"
+  set +e
+  [[ "${severity}" == "Error" ]] && exit 1
+  set -e
+}
+
+# Check if required commands exist
+require_commands () {
+  for name in ${@} ; do
+    if ! type ${name} > /dev/null 2>&1 ; then
+      error_msg "${name}: command not found"
+    fi
+  done
+}
+
+
+# ---- DebOps environment setup ----
+
+# Find DebOps configuration file
+debops_config="$(find_up)"
+
+# Find root of the DebOps project dir
+[ -n "${debops_config}" ] && debops_root="$(dirname ${debops_config})"
+
+# Source DebOps configuration file
+[ -n "${debops_config}" ] && [ -r ${debops_config} ] && source ${debops_config}
+
+
 # ---- Main script ----
 
 # Check if required commands are available