#!/usr/bin/env bash

# Configure shell.
set -u

# User-friendly print wrapper.
log() {
  printf '[%s] [%s] %s\n' "${0##*/}" "$( date '+%Y-%m-%dT%H:%M:%S' )" "${@}"
}

while [[ true ]]; do
  log 'Launching password sync app'
  secret2file -secret="${PROTECTED_SERVICE_SECRET_NAME}" -file="/etc/nginx/auth/${PROTECTED_SERVICE_NAME}"
  # TODO: Add chmod

  log "Sleeping for ${SYNC_DELAY} till the next update"
  sleep ${SYNC_DELAY}
done
