#!/bin/sh

dir="/var/www/$1/htdocs"

if [ ! "$1" ]
then
    echo "falta el nombre del dominio"
    exit 1
fi

if [ ! -d $dir ]
then
    echo "no existe el dominio"
    exit 1
fi

cd $dir

chmod ogu-w $dir
chmod ogu-w -R administrator components includes language libraries modules plugins templates
chmod ogu-w *.php

# Permisos para joomla =1.0
if [ -d editor ]
then
    chmod ogu-w -R editor
fi
if [ -d mambots ]
then
    chmod ogu-w -R mambots
fi

# Permisos para joomla =1.5
if [ -d xmlrpc ]
then
    chmod ogu-w -R xmlrpc
fi

# Permisos para joomla >=1.6
if [ -d cli ]
then
    chmod ogu-w -R cli
fi

# Permisos para joomla >=3.0
if [ -d bin ]
then
    chmod ogu-w -R bin layouts
fi

chmod ogu+w -R administrator/cache

if [ -d administrator/backups ]
then
    chmod ogu+w -R administrator/backups
fi

# Ajusta permisos para virtuemart 1.5.x
if [ -d components/com_virtuemart/shop_image ]
then
    chmod ogu+w -R components/com_virtuemart/shop_image
fi
if [ -e administrator/components/com_virtuemart/virtuemart.cfg.php ]
then
    chmod ogu+w -R administrator/components/com_virtuemart/virtuemart.cfg.php
fi


# Ajusta permisos para rsform
if [ -d components/com_rsform/uploads ]
then
    chmod ogu+w -R components/com_rsform/uploads
fi


# Ajusta permisos para docman
if [ -e administrator/components/com_docman/docman.config.php ]
then
    chmod ogu+w -R administrator/components/com_docman/docman.config.php
fi


# Ajusta permisos para sef404
if [ -d administrator/components/com_sh404sef/config ]
then
    chmod ogu+w -R administrator/components/com_sh404sef/config
fi
if [ -d components/com_sh404sef/cache ]
then
    chmod ogu+w -R components/com_sh404sef/cache
fi


# Ajusta permisos para akeeba
if [ -d administrator/components/com_akeeba/backup ]
then
    chmod ogu+w -R administrator/components/com_akeeba/backup
fi


# Ajusta permisos para extplorer
if [ -d administrator/components/com_extplorer/config ]
then
    chmod ogu+w -R administrator/components/com_extplorer/config
fi


# Ajusta permisos para breezingforms
if [ -d administrator/components/com_breezingforms/ajax_cache ]
then
    chmod ogu+w -R administrator/components/com_breezingforms/ajax_cache
fi
if [ -d administrator/components/com_breezingforms/payment_cache ]
then
    chmod ogu+w -R administrator/components/com_breezingforms/payment_cache
fi
