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) {
59 $b = sprintf (_('<p><b>Anonymous CPOLD Access</b></p><p>This project\'s CPOLD repository can be accessep anonymously at %s.</p>'),
60 util_make_link ('/anonscm/cpold/'.$project->getUnixName().'/',
61 util_make_url ('/anonscm/cpold/'.$project->getUnixName().'/'))) ;
65 function getInstructionsForRW ($project) {
66 if (session_loggedin()) {
67 $u =& user_get_object(user_getid()) ;
68 $d = $u->getUnixName() ;
69 $b = _('<p><b>Developer CPOLD Access via SSH</b></p><p>Only project developers can access the CPOLD tree via this method. SSH must be installed on your client machine. Enter your site password when prompted.</p>');
70 $b .= '<p><tt>scp -r '.$d.'@' . $project->getSCMBox() . ':'. forge_get_config('repos_path', 'scmcpold') .'/'. $project->getUnixName().'/ .</tt></p>' ;
72 $b = _('<p><b>Developer CPOLD Access via SSH</b></p><p>Only project developers can access the CPOLD tree via this method. SSH must be installed on your client machine. Substitute <i>developername</i> with the proper value. Enter your site password when prompted.</p>');
73 $b .= '<p><tt>scp -r <i>'._('developername').'</i>@' . $project->getSCMBox() . ':'. forge_get_config('repos_path', 'scmcpold') .'/'. $project->getUnixName().'/ .</tt></p>' ;
78 function getSnapshotPara ($project) {
82 function getBrowserLinkBlock ($project) {
86 function getStatsBlock ($project) {
90 function createOrUpdateRepo ($params) {
91 $project = $this->checkParams ($params) ;
96 if (! $project->usesPlugin ($this->name)) {
100 $repo = forge_get_config('repos_path', 'scmcpold') . '/' . $project->getUnixName() ;
101 $unix_group = 'scm_' . $project->getUnixName() ;
103 system ("mkdir -p $repo") ;
104 system ("chgrp -R $unix_group $repo") ;
105 system ("find $repo -type d | xargs chmod g+s") ;
107 if ($project->enableAnonSCM()) {
108 system ("chmod -R g+wX,o+rX-w $repo") ;
110 system ("chmod -R g+wX,o-rwx $repo") ;
114 function generateSnapshots ($params) {
116 $project = $this->checkParams ($params) ;
121 $group_name = $project->getUnixName() ;
123 $tarball = forge_get_config('scm_tarballs_path').'/'.$group_name.'-scmroot.tar.gz';
125 if (! $project->usesPlugin ($this->name)) {
129 if (! $project->enableAnonSCM()) {
130 if (file_exists ($tarball)) unlink ($tarball) ;
134 $toprepo = forge_get_config('repos_path', 'scmcpold') ;
135 $repo = $toprepo . '/' . $project->getUnixName() ;
137 if (!is_dir ($repo)) {
138 if (file_exists ($tarball)) unlink ($tarball) ;
142 $tmp = trim (`mktemp -d`) ;
146 system ("tar czCf $toprepo $tmp/tarball.tar.gz " . $project->getUnixName()) ;
147 chmod ("$tmp/tarball.tar.gz", 0644) ;
148 copy ("$tmp/tarball.tar.gz", $tarball) ;
149 unlink ("$tmp/tarball.tar.gz") ;
150 system ("rm -rf $tmp") ;
156 // c-file-style: "bsd"