2 /** FusionForge CPOLD plugin
4 * Copyright 2009-2011, Roland Mas
6 * This file is part of FusionForge.
8 * FusionForge is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published
10 * by the Free Software Foundation; either version 2 of the License,
11 * or (at your option) any later version.
13 * FusionForge is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 forge_define_config_item ('default_server', 'scmcpold', forge_get_config ('web_host')) ;
24 forge_define_config_item ('repos_path', 'scmcpold', forge_get_config('chroot').'/scmrepos/cpold') ;
26 class CpoldPlugin extends SCMPlugin {
27 function CpoldPlugin () {
30 $this->name = 'scmcpold';
31 $this->text = 'CPOLD';
32 $this->hooks[] = 'scm_generate_snapshots' ;
33 $this->hooks[] = 'scm_cpold_do_nothing' ;
38 function CallHook ($hookname, &$params) {
42 case 'scm_cpold_do_nothing':
46 parent::CallHook ($hookname, $params) ;
50 function getDefaultServer() {
51 return forge_get_config('default_server', 'scmcpold');
54 function getBlurb () {
55 return '<p>'._('This CPOLD plugin is only intended as a proof of concept.').'</p>';
58 function getInstructionsForAnon ($project) {
60 $b .= _('Anonymous CPOLD Access');
63 $b = sprintf (_('This project\'s CPOLD repository can be accessep anonymously at %s.'),
64 util_make_link ('/anonscm/cpold/'.$project->getUnixName().'/',
65 util_make_url ('/anonscm/cpold/'.$project->getUnixName().'/'))) ;
70 function getInstructionsForRW ($project) {
71 if (session_loggedin()) {
72 $u = user_get_object(user_getid()) ;
73 $d = $u->getUnixName() ;
75 $b .= sprintf(_('Developer %s Access via SSH'), 'CPOLD');
78 $b .= sprintf(_('Only project developers can access the %s tree via this method.'), 'CPOLD');
80 $b .= _('SSH must be installed on your client machine.');
82 $b .= _('Enter your site password when prompted.');
84 $b .= '<p><tt>scp -r '.$d.'@' . $project->getSCMBox() . ':'. forge_get_config('repos_path', 'scmcpold') .'/'. $project->getUnixName().'/ .</tt></p>' ;
87 $b .= sprintf(_('Developer %s Access via SSH'), 'CPOLD');
90 $b .= sprintf(_('Only project developers can access the %s tree via this method.'), 'CPOLD');
92 $b .= _('SSH must be installed on your client machine.');
94 $b .= _('Substitute <em>developername</em> with the proper value.');
96 $b .= _('Enter your site password when prompted.');
98 $b .= '<p><tt>scp -r <i>'._('developername').'</i>@' . $project->getSCMBox() . ':'. forge_get_config('repos_path', 'scmcpold') .'/'. $project->getUnixName().'/ .</tt></p>' ;
103 function getSnapshotPara ($project) {
107 function getBrowserLinkBlock ($project) {
111 function getStatsBlock ($project) {
115 function createOrUpdateRepo ($params) {
116 $project = $this->checkParams ($params) ;
121 if (! $project->usesPlugin ($this->name)) {
125 $repo = forge_get_config('repos_path', 'scmcpold') . '/' . $project->getUnixName() ;
126 $unix_group = 'scm_' . $project->getUnixName() ;
128 system ("mkdir -p $repo") ;
129 system ("chgrp -R $unix_group $repo") ;
130 system ("find $repo -type d | xargs chmod g+s") ;
132 if ($project->enableAnonSCM()) {
133 system ("chmod -R g+wX,o+rX-w $repo") ;
135 system ("chmod -R g+wX,o-rwx $repo") ;
139 function generateSnapshots ($params) {
141 $project = $this->checkParams ($params) ;
146 $group_name = $project->getUnixName() ;
148 $tarball = forge_get_config('scm_tarballs_path').'/'.$group_name.'-scmroot.tar.gz';
150 if (! $project->usesPlugin ($this->name)) {
154 if (! $project->enableAnonSCM()) {
155 if (file_exists ($tarball)) unlink ($tarball) ;
159 $toprepo = forge_get_config('repos_path', 'scmcpold') ;
160 $repo = $toprepo . '/' . $project->getUnixName() ;
162 if (!is_dir ($repo)) {
163 if (file_exists ($tarball)) unlink ($tarball) ;
167 $tmp = trim (`mktemp -d`) ;
171 system ("tar czCf $toprepo $tmp/tarball.tar.gz " . $project->getUnixName()) ;
172 chmod ("$tmp/tarball.tar.gz", 0644) ;
173 copy ("$tmp/tarball.tar.gz", $tarball) ;
174 unlink ("$tmp/tarball.tar.gz") ;
175 system ("rm -rf $tmp") ;
181 // c-file-style: "bsd"