вторник, 5 июня 2012 г.

Мониторинг изменений iptables на svn и redmine (debian)

        1.  Настройка сервера с SVN и Redmine

http://www.debuntu.org/2006/05/20/54-how-to-subversion-svn-with-apache2-and-dav


Neccessary packages:
First of all we need to install the required packages:
apt-get install subversion libapache2-svn
Repository structure:
The projects are going to be hosted on /var/svn/repository. We need to create to directories and give full permission to the apache user:
mkdir /var/svn
mkdir /var/svn/repository
Now that the directory exist, we need to give write access to the apache user:
chown www-data:www-data -R /var/svn/repository
chmod 770 -R /var/svn/repository
Configuring Apache:
Now, we need to modify apache svn module configuration file, edit /etc/apache2/mods-available/dav_svn.conf and make sure the following argument are properly setted up:
...
SVNParentPath /var/svn/repository
#SVNPath /var/svn/repository
.....
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
Require valid-user
...
In order to be able to track who modify the different files of the project, we need to create users. Create the first user (tester) and supply a password:
htpasswd -c /etc/apache2/dav_svn.passwd client01_user
Creating a first repository:
Get apache user access (so files and directories are created with proper rights:
su www-data
and create your first repository (example):
svnadmin create /var/svn/repository/client01
Now, get back to root user (Ctrl-D) and restart apache:
/etc/init.d/apache2 restart
Your project is now avalaible to the different user you will add in /etc/apache2/dav_svn.passwd .
User tester can now access the project at http://svnhostaddress/example and checkout a first copy to his computer, modify files and commit back his changes to the server.

Установка redmine 

apt-get install redmine

      2.  Настройка клиента



Уcтановка необходимых пакетов

apt-get install subversion


Создадим папку репозитория
mkdir /var/svn

cd /var/svn

импортируем с сервера svn саму папку (не забыть точку в конце)
root@client01:/var/svn# svn co http://192.168.55.9/svn/client01 .


Далее пропатчим iptables.sh

root@client01:/etc/network# tail -n3 iptables.sh
iptables-save | egrep -v '^(#|:)' > /var/svn/iptables_svn
/usr/local/sbin/commit_svn $@



сам файлик /usr/local/sbin/commit_svn
root@client01:/etc/network# cat /usr/local/sbin/commit_svn
#!/bin/bash
comment=$@
if [ -z "$comment" ]; then
    comment="no comments"
fi

if [ $USER = "root" ]; then
    user=$SUDO_USER
else
    user=$USER
fi

if [ -n "$user" ]; then
    svn ci --username $user --config-dir /home/$user/.subversion/ -m"$comment" /var/svn/iptables_svn
fi



Выполним вручную iptables.sh,  чтобы создался файл  /var/svn/iptables_svn

Добавим новый файл в репозиторий

root@client01:/var/svn#svn add iptables_svn

Логин и пароль на доступ к svn  сохраняется в домашней директории /home/$user/.subversion/

      3.  Настройка redmine

 Создадим проект iptables. Далее подпроект client01
В настройках хранилища указываем параметры svn  сервера
http://192.168.55.9/svn/client01

Для  redmine на сервере svn можно создать отдельного ползователя  redmine
root@svn:/tmp#htpasswd /etc/apache2/dav_svn.passwd redmine



SVN auto Commit cron 

1 вариант 

отсюда... http://snippet.espend.de/ssh/svn-auto-commit-cron-54.html

#!/bin/bash
 
# CHANGES:
# Feb 2nd 2010: Fixing a nasty bug found bug Jason Judge that would make
#  the script fail once in a while;
 
#------------------------------- Subroutines ---------------------------------
usage(){
echo " Usage: $(basename $0) PATH" 
echo ""
echo "Automatically commits the changes of svn working copy located in PATH."
echo "The new files are automatically added and the files that have been removed"
echo "are removed."
echo ""
echo "By Gael Varoquaux"
}
 
#------------------------------- Process the options -------------------------
if [ $# -eq 1 ]
then
    workingdir="$1"
else
    usage
    exit 1
fi
 
if ! cd $workingdir
then
    echo $workingdir is not a accessible path.
    usage
    exit 1
fi
 
#------------------------------- Find out what has changed -------------------
 
# A warning if this fails :
echo "SVN autocommit failed or nothing todo" 
 
svnstatus=$(svn status $workingdir)
added=$(printf "%s" "$svnstatus" | sed -n 's/^[A?] *\(.*\)/\1/p')
removed=$(printf "%s" "$svnstatus" | sed -n 's/^! *\(.*\)/\1/p')
 
if [ "x$added" != "x" ]
then
    echo adding "$added" to repository
    svn add $added
fi
 
if [ "x$removed" != "x" ]
then
    echo removing "$removed" to repository
    svn remove $removed
fi
 
svn commit -m "autocommit" 
 
 
 
2 вариант 
 
 
#!/bin/bash
# Run commit every second.
# Why? Cron can't do that.
# This can be used combined with a post-commit hook to make a kind of a versioned FTP :P

# This script needs a initial checkout! A working copy must exist a priori!

# You need to set-up a "svn-path" file in the same directory as the script with one working copy a line
# /absolute/working-copy/
# /absolute/working-copy2/

# Bugs: 
# Sometimes when you work with someone else on the same file it can overwrite others modifications with yours without throwing a conflict
# Good thing it's svn and you can easily merge the modifications afterwards. Still this bug is annoying

# Change this to your paths
script_path="/home/sasha/Scripts/"
paths_file="/home/sasha/Scripts/svn-paths"

while [ true ]; do
 message="*Auto-message*"
 for local_path in `cat $paths_file| grep -v "#"`; do
  stat=`svn status $local_path`
  if [[ $stat != '' ]]; then #Are there any changes?
   delete_files=`echo $stat|grep -e "^\!"|cut -d" " -f2`
   if [[ $delete_files != '' ]]; then
    svn delete $delete_files>/dev/null 2>/dev/null
    svn commit --non-interactive -m "$message (delete)" $remote_url >/dev/null 2>>"$script_path"commit_log
   fi
   # Do we have any files to add
   add_files=`echo $stat|grep -e "^\?"|cut -d" " -f2`
   if [[ $add_files != '' ]]; then
    svn add $add_files >/dev/null 2>/dev/null # Add new files if there are any
    svn commit --non-interactive -m "$message (add)" $remote_url >/dev/null 2>>"$script_path"commit_log # Finaly commit
   fi
   svn update $local_path >/dev/null 2>>/dev/null #Checkout first
   svn commit --non-interactive -m "$message (modified)" $local_path >/dev/null 2>>"$script_path"commit_log # Finaly commit
  fi
 done
 sleep 1
done
 
 

Комментариев нет:

Отправить комментарий