Créer des dépôts facilement sur un serveur SVN
Deux petits scripts très pratique pour ajouter des dépôts sur votre serveur Subversion et pour ajouter des utilisateurs en écriture, par la suite.
Ce sont les scripts utilisés pour le serveur de CodingTeam !
Pour installer Subversion sur ma Debian, je n'ai eu qu'à faire :
apt-get install libapache2-svn subversion subversion-tools
Pour ajouter un dépôt à mon serveur SVN, voici le script (très facilement modifiable pour votre utilisation) :
#!/usr/bin/env python
# -*- coding: UTF8 -*-
###
#
# svn-create.py is the legal property of Erwan Briand <xbright2005@gmail.com>
# Copyright (c) 2007 Erwan Briand
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation
#
# This program 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
#
###
import os
base = "http://svn.codingteam.net"
svn_repository = "/var/www/code/"
svn_msg = "[CodingTeam] Subversion : "
svn_suffix = "/src"
apache_config = "/etc/apache2/projectalias.conf"
print "#################################################"
print "Créer un dépôt SVN sur CodingTeam"
print "#################################################"
try:
nom_projet = raw_input("Nom du projet : ")
## Création du projet
os.system("mkdir " + svn_repository + nom_projet)
os.system("chown www-data " + svn_repository + nom_projet)
os.system(" su www-data -c \"svnadmin create " + svn_repository + nom_projet + svn_suffix + "\" ")
print "\nCréation du projet\t\t\t\t[OK]"
## Configuration du serveur
file = open(apache_config,"a")
file.write("##### Serveur pour " + nom_projet + "\n")
file.write("<Location /code/" + nom_projet + ">\n")
file.write(" DAV svn\n")
file.write(" DavDepthInfinity on\n")
file.write(" SVNPath " + svn_repository + nom_projet + svn_suffix + "\n")
file.write(" AuthType Basic\n")
file.write(" AuthName \"" + svn_msg + nom_projet + "\"\n")
file.write(" AuthUserFile "+ svn_repository + nom_projet +"/.dav_svn.passwd\n")
file.write(" <LimitExcept GET PROPFIND OPTIONS REPORT>\n")
file.write(" Require valid-user\n")
file.write(" </LimitExcept>\n")
file.write("</Location>\n\n")
file.close()
print "\nConfiguration du serveur (VirtualHost)\t\t[OK]"
## Ajout des droits
admin_projet = raw_input("\nNom de l'administrateur : ")
os.system(" su www-data -c \"htpasswd2 -c -m "+ svn_repository + nom_projet +"/.dav_svn.passwd " + admin_projet + "\" ")
#print "Pour ajouter des droits par la suite, il faudra exécuter cette commande :"
#print "=>\tsu www-data -c \"htpasswd2 -m "+ svn_repository + nom_projet +"/.dav_svn.passwd user\" "
print "\nAjout des droits\t\t\t\t[OK]"
## Redémarrage du serveur Apache
print ""
os.system("/etc/init.d/apache2 force-reload")
print "\nRedémarrage du serveur\t\t\t\t[OK]"
print "\n\n"
print "Dépôt Subversion\t\t\t[Créé]"
print "Nom du serveur\t\t\t\t" + nom_projet
print "Nom de l'administrateur\t\t\t" + admin_projet
print "Adresse du dépôt\t\t\t" + base + "/" + nom_projet
print "\nTravail effectué."
except:
print "\nErreur ! Abandon."Enfin, pour ajouter un utilisateur en écriture à un dépôt :
#!/usr/bin/env python
# -*- coding: UTF8 -*-
###
#
# svn-adduser.py is the legal property of Erwan Briand <xbright2005@gmail.com>
# Copyright (c) 2007 Erwan Briand
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation
#
# This program 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
#
###
import os
svn_repository = "/var/www/code/"
print "#################################################"
print "Ajouter un utilisateur à un dépôt SVN"
print "#################################################"
try:
nom_projet = raw_input("Nom du projet : ")
if os.path.isdir(svn_repository + nom_projet) == False:
print "\nErreur ! Abandon."
else:
## Ajout des droits
admin_projet = raw_input("\nNom de l'utilisateur : ")
os.system(" su www-data -c \"htpasswd2 -m "+ svn_repository + nom_projet +"/.dav_svn.passwd " + admin_projet + "\" ")
print "\nAjout des droits\t\t\t\t[OK]"
print "\n\n"
print "Dépôt Subversion\t\t\t[Modifié]"
print "Nom du dépôt\t\t\t\t" + nom_projet
print "Nouvel utilisateur\t\t\t" + admin_projet
print "\nTravail effectué."
except:
print "\nErreur ! Abandon."Voilà, en espérant que ces scripts puissent vous servir ;)
En effet, j'ai eu du mal à trouver de la bonne doc pour administrer un serveur Subversion et ces scripts me permettent en fait d'optimiser ce très bon How To : Subversion in Debian !
terr1en
# | 58 commentaire(s) - Grand floodeur | mardi 30 octobre 2007, 21:13
Ha c'est comme ça le truc, okay maintenant j'comprend mieux le pourquoi du comment !
elghinn
# | 203 commentaire(s) - Nolife | mercredi 31 octobre 2007, 01:06
Depuis le temps, t'as dû les mettre à jour tes scripts, non ?
xbright
# | 303 commentaire(s) - Vrai trolleur | jeudi 1 novembre 2007, 10:37
Oui, je crois.
elghinn
# | 203 commentaire(s) - Nolife | jeudi 1 novembre 2007, 19:57
Et ça te viendrait pas à l'idée de partager les nouveaux ? :s
xbright
# | 303 commentaire(s) - Vrai trolleur | jeudi 1 novembre 2007, 20:40
Il faudrait que je les améliore.
De toute façon, les dépôts SVN sur CT en ce moment, c'est du bricolage. Vivement CT 0.9.x \o/
elghinn
# | 203 commentaire(s) - Nolife | jeudi 1 novembre 2007, 21:16
0.9 alors que la 0.42 est sortie ? xD
CT, le premier logiciel qui régresse :D
Fil des commentaires de ce billet
Ajouter un commentaire