#!/bin/bash # # mksite-sync-proxy v0.1: update proxy config and reload apache if apropriate # feedback: rhatto at riseup.net | gpl # # This is free software; you can redistribute it and/or modify it under the # terms of the GNU General Public License as published by the Free Software # Foundation; either version 2 of the License, or any later version. # # This software is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with # this program; if not, write to the Free Software Foundation, Inc., 59 Temple # Place - Suite 330, Boston, MA 02111-1307, USA # TMP="/tmp" MKSITE_BASE="/etc/mksite" CONF="$MKSITE_BASE/mksite.conf" MESSAGES="/usr/share/mksite/mksite.messages" LOCKFILE="$TMP/mkproxy.lock" HELPER_FUNCTIONS="/usr/libexec/mksite/mksite-helper" # plugin definitions PLUGIN_NAME="proxy-sync" if [ -f "$HELPER_FUNCTIONS" ]; then source $HELPER_FUNCTIONS mksite_checks else echo Fatal error: function file not found, aborting. echo Erro fatal: arquivo de funcoes nao encontrado, abortando. exit 1 fi # parametros de configuracao LOCAL_RSYNC_CMD="`mksite_eval_param $MKSITE_BASE/plugins/$PLUGIN_NAME $LOCAL_RSYNC_CMD`" REMOT_RSYNC_CMD="`mksite_eval_param $MKSITE_BASE/plugins/$PLUGIN_NAME $REMOTE_RSYNC_CMD`" REMOTE_INSTANCES="`mksite_eval_param $MKSITE_BASE/plugins/$PLUGIN_NAME $REMOTE_INSTANCES`" LOCAL_INSTANCES="`mksite_eval_param $MKSITE_BASE/plugins/$PLUGIN_NAME $LOCAL_INSTANCES`" PROXY_DATA_DIR="`mksite_eval_param $MKSITE_BASE/plugins/$PLUGIN_NAME $DATA_DIR`" # PROXY_DATA_DIR: checksuns de arquivos if [ -z "PROXY_DATA_DIR" ]; then PROXY_DATA_DIR="/var/mksite/proxy" fi if [ ! -d "$PROXY_DATA_DIR" ]; then mkdir -p $PROXY_DATA_DIR/{local,remote} fi # TODO: sincroniza as definicoes de proxy # - rsync remoto: servidor, pasta remota, pasta local, template # - rsync local: pasta da instancia, pasta local, template # TODO: checa modifcoes e caso necessario: # - adiciona o host ao /etc/hosts # - atualiza o apache # - inclui os arquivos no template da jaula correspondente vars="user server remote_folder local_folder template file filename" # local servers: /jaula:/pasta:template if [ ! -z "$LOCAL_INSTANCES" ]; then for local_instance in $LOCAL_INSTANCES; do unset $vars remote_folder="`echo $local_instance | cut -d : -f 1`" local_folder="`echo $local_instance | cut -d : -f 2`" template="`echo $local_instance | cut -d : -f 3`" # checkums guardados em $PROXY_DATA_DIR/local/$template if [ ! -d "$PROXY_DATA_DIR/local/$template" ]; then mkdir -p $PROXY_DATA_DIR/local/$template fi # aplica mudancas, caso elas existam for file in ls $remote_folder; do filename="`basename $file`" if [ ! -a "$local_folder/$filename" ] || ! diff $file $local_folder/$filename; then # faz o rsync $LOCAL_RSYNC_CMD $file/ $local_folder/ # faz o rsync para o template if [ "$USE_SIMPLEPKG" == "yes" ] then $LOCAL_RSYNC_CMD $file/ /etc/simplepkg/$template/`$dirname $file`/ fi # TODO: adiciona entradas no /etc/hosts caso necessario # reinicia o apache break fi done done fi # remote servers: usuario@servidor:/pasta:template if [ ! -z "$REMOTE_INSTANCES" ]; then for local_instance in $REMOTE_INSTANCES; do unset $vars user="`echo $local_instance | cut -d "@" -f 1`" remote_folder="`echo $local_instance | cut -d : -f 1 | cut -d "@" -f 2`" local_folder="`echo $local_instance | cut -d : -f 2`" template="`echo $local_instance | cut -d : -f 3`" # checkums guardados em $PROXY_DATA_DIR/local/$template if [ ! -d "$PROXY_DATA_DIR/remote/$template" ]; then mkdir -p $PROXY_DATA_DIR/remote/$template fi # syncroniza # checa novos arquivos # se nao houver novos arquivos done fi