#!/bin/bash

# Run the install again!
hooks/install

wp_install_path="/var/www/"

if [ -f "$wp_install_path/wp-config.php" ]; then
	chown -R www-data.www-data $wp_install_path

	hooks/config-changed

	juju-log "Upgrading WordPress core..."
	wp core update --path=$wp_install_path

	# Patch to fix old installations that didn't cookie properly
	if [ -f "$wp_install_path/wp-info.php" ] && [ -f .wp-secret ]; then
		secret_key=`cat .wp-secret`
		sed -i -e "s/define('SECRET_KEY',.*/define('SECRET_KEY', '$secret_key')\;/" $wp_install_path/wp-info.php
	fi
fi

hooks/restart
