# cat /srv/scripts/mirror_centos6.sh #!/bin/bash SOURCE1="rsync://centos.ufms.br/CentOS/6" SOURCE2="rsync://centos.ufms.br/CentOS/6.7" TARGET="/var/www/html/centos" CREATE="createrepo_centos6.sh" LOGS="/var/log/mirror" LOGOFILE="/var/log/mirror/centos_6.log" MAILNOTIFY="gean@rascunhos.wiki.br" DEBUGFILE="/var/log/mirror/centos_6.debug" MAILSUBJECT="ERRO Repositorio CentOS 6" LOCKFILE="/var/log/mirror/centos_6.lock" # funcao para registrar os logs function log() { echo `date +%d.%m.%Y%t%H:%M:%S` " LOG:" $1 | tee -a ${LOGFILE} } # Cria o diretorio mirror se ele nao existir if [ ! -d ${LOGS} ] ; then log "Diretorio de logs criado." mkdir -p ${LOGS} fi # funcao para registrar os erros function error() { echo `date +%d.%m.%Y%t%H:%M:%S` " ERROR:" $1 | tee -a ${LOGFILE} if [ -n "${MAILNOTIFY}" ] ; then echo `date +%d.%m.%Y%t%H:%M:%S` " ERROR:" $1 | mail -s "${MAILSUBJECT}" ${MAILNOTIFY} fi } # funcao para registrar o status function status() { case "$1" in 0) log "Synchronization completed." ;; 1) error "RSYNC: Syntax or usage error." ;; 2) error "RSYNC: Protocol incompatibility." ;; 3) error "RSYNC: Errors selecting input/output files, dirs." ;; 4) error "RSYNC: Requested action not supported: an attempt was made to manipulate 64-bit files on a platform that cannot support them; or an option was specified that is supported by the client and not by the server." ;; 5) error "RSYNC: Error starting client-server protocol." ;; 6) error "RSYNC: Daemon unable to append to log-file." ;; 10) error "RSYNC: Error in socket I/O." ;; 11) error "RSYNC: Error in file I/O." ;; 12) error "RSYNC: Error in rsync protocol data stream." ;; 13) error "RSYNC: Errors with program diagnostics." ;; 14) error "RSYNC: Error in IPC code." ;; 20) error "RSYNC: Received SIGUSR1 or SIGINT." ;; 21) error "RSYNC: Some error returned by waitpid()." ;; 22) error "RSYNC: Error allocating core memory buffers." ;; 23) error "RSYNC: Partial transfer due to error." ;; 24) error "RSYNC: Partial transfer due to vanished source files." ;; 25) error "RSYNC: The --max-delete limit stopped deletions." ;; 30) error "RSYNC: Timeout in data send/receive." ;; *) error "RSYNC: Unknown error $1." ;; esac } if [ -f ${LOCKFILE} ] ; then kill -0 $(cat ${LOCKFILE}) >/dev/null 2>&1 if [ $? -eq 0 ] ; then error "Previous process still running." exit 1 else log "Deprecated lock file found. Remove lock file." rm -f ${LOCKFILE} fi fi echo $$ >${LOCKFILE} # Create local mirror directories if not exists if [ ! -d ${TARGET} ] ; then log "Diretorio do repositorio criado." mkdir -p ${TARGET} fi #Comando rsync log "Iniciando o download do repositorio CentOS 6." >> ${DEBUGFILE} 2>&1 echo ">>>>>" `date +%d.%m.%Y%t%H:%M:%S` "<<<<<" >>${DEBUGFILE} rsync -av --bwlimit=4096 --exclude=repodata --exclude=debug --exclude=isos ${SOURCE1} ${TARGET} >> ${DEBUGFILE} 2>&1 rsync -av --bwlimit=4096 --exclude=repodata --exclude=debug --exclude=isos ${SOURCE2} ${TARGET} >> ${DEBUGFILE} 2>&1 status $? #usa o cat para esvaziar o arquivo $CRIAR. cat /dev/null > $CREATE # cria o script para executar pos download cat << EOF > $CREATE #!/bin/bash #Esse script executa o comando createrepo em todos os diretórios com arquivos .rpm. # Criado em: `date` EOF # aqui buscamos os arquivos das arquiteturar x86_64 e i386 para rodarmos o createrepo # isso evita erro no clientes find /var/www/html/centos/6/ -name "x86_64" >> $CREATE find /var/www/html/centos/6/ -name "i386" >> $CREATE # colocando o createrepo ates do var # na primeira execucao atere createrepo --update para createrepo sed -i "s/\/var/createrepo --update \/var/g" $CREATE # Alterando as permissoes e executando chmod 750 $CREATE log "Iniciando a criacao da base de dados." >> ${DEBUGFILE} 2>&1 echo ">>>>>" `date +%d.%m.%Y%t%H:%M:%S` "<<<<<" >>${DEBUGFILE} /bin/bash $CREATE status $? rm -f ${LOCKFILE} exit 0