#!/bin/bash set -e # variables SKEL="./skel" CONF_DIR="php/conf.d" FILEPHP="lliurex.ini" CONF_PHP="$CONF_DIR/$FILEPHP" PATH_PHP="/etc/php5/conf.d/lliurex.ini" ######## # main # ######## # test LIB_FILE="/usr/share/lliurex/llxcfg-httpd/llxcfg-httpd.sh" [ -e "$LIB_FILE" ] || exit 1 . ${LIB_FILE} [ "${LLX_WWW_PATH}" ] || exit 1 LIB_FILE="/usr/share/lliurex/lliurex-srv-common/lliurex-netfuncs.sh" [ -e "$LIB_FILE" ] || exit 1 . ${LIB_FILE} # configure Apache2 APACHEPATH="/etc/apache2" llxcfg-config list "$DEFAULT_CONF" | while read DEFAULT_FILE ; do llxcfg-config read "$DEFAULT_CONF/$DEFAULT_FILE" | skel-install -t "$APACHEPATH/$DEFAULT_FILE" done # read sites llxcfg-config listfiles "$SITE_LIST" |while read SITE_FILE ; do # every file in "SITE_LIST" is an standard alias file (one alias per line) # but the first is the site name VHOST_NAME="$(head -1 "$SITE_FILE")" VHOST_ALIAS="$(sed -e "1d" "$SITE_FILE" |tr "\n" " ")" if [ "$VHOST_NAME" ] ; then # test for config in "real world" VHOST_FILE="${LLX_AVAILABLE_PATH}/${VHOST_NAME}" # Removed the if because now will regenerate all the confiles all the times #if [ ! -f "$VHOST_FILE" ] ; then # generate config ... llxcfg-systemvars add VHOST_NAME="$VHOST_NAME" [ "$VHOST_ALIAS" ] && llxcfg-systemvars add VHOST_ALIAS="$VHOST_ALIAS" TEMPFILE="$(tempfile)" # read specific template or default (llxcfg-config read "$SITE_CONF/$VHOST_NAME" || llxcfg-config read "$SITE_CONF/default") > "$TEMPFILE" # process template and install in skel llxcfg-template "$TEMPFILE" |skel-install "$VHOST_FILE" #fi # test for link if [ ! -L "$APACHE_ENABLED_SITES/$VHOST_NAME" ] ; then mkdir -p "${SKEL}/${APACHE_ENABLED_SITES}" ln -sf "${VHOST_FILE}" "${SKEL}/${APACHE_ENABLED_SITES}/${VHOST_NAME}" fi fi llxcfg-systemvars del VHOST_NAME VHOST_ALIAS done #SSL SITES CERTSDIR="/etc/lliurex-secrets/certs/lliurex-ssl-sites/" llxcfg-config listfiles "$SITE_LIST_SSL" |while read SITE_FILE ; do # every file in "SITE_LIST" is an standard alias file (one alias per line) # but the first is the site name VHOST_NAME="$(head -1 "$SITE_FILE")" VHOST_ALIAS="$(sed -e "1d" "$SITE_FILE" |tr "\n" " ")" if [ "$VHOST_NAME" ] ; then # test for config in "real world" VHOST_FILE="${LLX_AVAILABLE_PATH}/${VHOST_NAME}" # The same that above #if [ ! -f "$VHOST_FILE" ] ; then # generate config ... llxcfg-systemvars add VHOST_NAME="$VHOST_NAME" [ "$VHOST_ALIAS" ] && llxcfg-systemvars add VHOST_ALIAS="$VHOST_ALIAS" TEMPFILE="$(tempfile)" # read specific template or default (llxcfg-config read "$SITE_CONF_SSL/$VHOST_NAME" || llxcfg-config read "$SITE_CONF_SSL/default") > "$TEMPFILE" # process template and install in skel llxcfg-template "$TEMPFILE" |skel-install "$VHOST_FILE" ## Creating Cert Lliurex-Pki CRTNAME="$VHOST_NAME" ###[ -e "$CERTSDIR/$CRTNAME" ] || lliurex-pki -n "$CRTNAME" -u www-data -g www-data -d "$CERTSDIR" > /dev/null 2>&1 #fi # test for link if [ ! -L "$APACHE_ENABLED_SITES/$VHOST_NAME" ] ; then mkdir -p "${SKEL}/${APACHE_ENABLED_SITES}" ln -fs "${VHOST_FILE}" "${SKEL}/${APACHE_ENABLED_SITES}/${VHOST_NAME}" fi fi llxcfg-systemvars del VHOST_NAME VHOST_ALIAS done # remove unwanted links # valid hostnames HTTP_SITES=" $(http_list_sites) $(http_list_sites_ssl)" # real links #find "${APACHE_ENABLED_SITES}" -type l -exec readlink -f {} \; # real lliurex sites find "${LLX_AVAILABLE_PATH}" -xtype f -printf "%f\n" |while read VHOST ; do if ! echo "$HTTP_SITES" |grep -q " $VHOST " ; then # remove link if exists echo "${APACHE_ENABLED_SITES}/${VHOST}" >> remove.list fi done # TODO: remove 'orphan' links # real links #find "${APACHE_ENABLED_SITES}" -type l -exec readlink -f {} \; # valid hostnames #PHP-CPKG llxcfg-config read ${CONF_PHP} | skel-install -t ${PATH_PHP} exit 0