#!/bin/bash

set -e

export BRANCH=${BRANCH:-<%= @dns_branch %>}
export TMPDIR=${TMPDIR:-<%= @dns_tmpdir %>}
export REPO=${REPO:-<%= @dns_repo %>}
export TARGETPATH=${TARGETPATH:-<%= @target_path %>}

(
  flock -n 9 || exit 1
  echo "Clean up..."
  rm -rf "${TMPDIR}"

  echo "Cloning..."
  git clone "${REPO}" "${TMPDIR}"
  cd "${TMPDIR}"
  git checkout "${BRANCH}"

  REVISION=`git log -1 HEAD | fgrep commit | awk '{print $NF}'`
  PREV_REVISION=`cat /tmp/ns-revision.txt 2>/dev/null || echo -n none`
  echo -n "${REVISION}" > /tmp/ns-revision.txt

  echo "Revision: \$Id: ${REVISION} \$"
  echo "Previous revision: ${PREV_REVISION}"

  if [[ "${REVISION}" == "${PREV_REVISION}" ]]; then
    echo "No updates found."
    exit 0
  fi

  echo "Linking..."
  rm -rf "${TARGETPATH}/zones"

  mv "${TMPDIR}/zones" "${TARGETPATH}/"

  echo "Reloading DNS configuration..."
  rndc reload
) 9>/var/lock/ns-update.lock

#!/bin/bash

set -e

export BRANCH=${BRANCH:-<%= @dns_branch %>}
export TMPDIR=${TMPDIR:-<%= @dns_tmpdir %>}
export REPO=${REPO:-<%= @dns_repo %>}
export TARGETPATH=${TARGETPATH:-<%= @target_path %>}

(
  flock -n 9 || exit 1
  echo "Clean up..."
  rm -rf "${TMPDIR}"

  echo "Cloning..."
  git clone "${REPO}" "${TMPDIR}"
  cd "${TMPDIR}"
  git checkout "${BRANCH}"

  REVISION=`git log -1 HEAD | fgrep commit | awk '{print $NF}'`
  PREV_REVISION=`cat /tmp/ns-revision.txt 2>/dev/null || echo -n none`
  echo -n "${REVISION}" > /tmp/ns-revision.txt

  echo "Revision: \$Id: ${REVISION} \$"
  echo "Previous revision: ${PREV_REVISION}"

  if [[ "${REVISION}" == "${PREV_REVISION}" ]]; then
    echo "No updates found."
    exit 0
  fi

  echo "Linking..."
  rm -rf "${TARGETPATH}/zones"

  mv "${TMPDIR}/zones" "${TARGETPATH}/"

  echo "Reloading DNS configuration..."
  /usr/sbin/rndc reload
) 9>/var/lock/ns-update.lock

Fix for rndc launch: use full path
Fix for rndc launch: use full path

Change-Id: Ie2d483711a43267ff97cb7463ed96795280e1986
Signed-off-by: Igor Shishkin <754e6e0fd0f692545d04d1591d9a3de62bb04f84@mirantis.com>
