#!/bin/sh


source $GEXT_AFREPO/AFR-SETUP.sh


has_afrepo_conf=`egrep "^Include conf/httpd-afrepo.conf" "$GEXTAMP_INSTALLED/conf/httpd.conf"`

if [ "x$has_afrepo_conf" = "x" ] ; then
  # Not currently in file => append it

  echo ""
  echo "** Appending 'httpd-afrepo.conf' to main Apache config file"
  echo "Include conf/httpd-afrepo.conf" >> "$GEXTAMP_INSTALLED/conf/httpd.conf"
fi

echo ""
echo "** Regnerating httpd-afrepo.conf"
cat "etc/httpd-afrepo.conf.in" \
  | sed "s%@4store-http-prefix@%$protocol://$f4store_hostname:$f4store_port%g" > "$GEXTAMP_INSTALLED/conf/httpd-afrepo.conf"


public_facing_url="$protocol://$public_facing_hostname"

if [ "x$public_facing_port" != "x" ] ; then
  public_facing_url="$public_facing_url:$public_facing_port"
fi

if [ "x$public_facing_url_prefix" != "x" ] ; then
  public_facing_url="$public_facing_url$public_facing_url_prefix"
fi

public_facing_url="$public_facing_url/"



public_facing_f4store_url="$protocol://$public_facing_f4store_hostname"

if [ "x$public_facing_f4store_port" != "x" ] ; then
  public_facing_f4store_url="$public_facing_f4store_url:$public_facing_f4store_port"
fi

if [ "x$public_facing_f4store_url_prefix" != "x" ] ; then
  public_facing_f4store_url="$public_facing_f4store_url$public_facing_f4store_url_prefix"
fi

public_facing_f4store_url="$public_facing_f4store_url/"


echo ""
echo "** Regenerating AFRepo.class.php"
cat "AFRepo.GSDLEXT.class.php.in" \
  | sed "s%@afrepo-http-prefix@%$protocol://$hostname:$port%g" \
  | sed "s%@4store-http-prefix@%$protocol://$f4store_hostname:$f4store_port%g" \
  | sed "s%@public-facing-afrepo-http-prefix@%$public_facing_url%g" \
  | sed "s%@public-facing-4store-http-prefix@%$public_facing_f4store_url%g" \
  > "$GEXTAMP_INSTALLED/htdocs/afrepo/AFRepo.class.php"



echo ""
echo "** Copying static HTML content (images, CSS etc) to htdocs/afrepo"
#/bin/cp -r html/* "$GEXTAMP_INSTALLED/htdocs/afrepo/."

rsync -pav --exclude .svn html/* "$GEXTAMP_INSTALLED/htdocs/afrepo/."