#!/bin/bash
# Get salt constants and write to wp-keys.php
#
# by Tim Moody tim@timmoody.com
DEST=/library/wordpress/wp-keys.php
BACKUP=/library/wordpress/wp-keys.php.BAK

echo '<?php' > $DEST
curl https://api.wordpress.org/secret-key/1.1/salt/ >> $DEST
RC=$?

# if the download of keys failed, revert to previous version
if [  $RC -ne 0  ];then
  cp  $BACKUP $DEST
else
  echo '?>' >> $DEST
  chown root:{{ apache_user }} $DEST
  chmod 640 $DEST
  cp -f $DEST $BACKUP
fi
