From tchemit@users.forge.codelutin.com Thu Oct 9 11:49:03 2014 From: tchemit@users.forge.codelutin.com To: adminsys-commits@list.forge.codelutin.com Subject: [Adminsys-commits] r111 - scripts/redmine-tools Date: Thu, 09 Oct 2014 11:49:03 +0200 Message-ID: <20141009094903.3020A1821F9@goh.codelutin.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0947059076290864577==" --===============0947059076290864577== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Author: tchemit Date: 2014-10-09 11:49:02 +0200 (Thu, 09 Oct 2014) New Revision: 111 Url: http://forge.codelutin.com/projects/adminsys/repository/revisions/111 Log: refs #5074: Mise en place git (mise a jour des sites techniques) amelioration autres script du cron Added: scripts/redmine-tools/project-site.rb scripts/redmine-tools/project-technical-site.rb scripts/redmine-tools/update_technical_site.sh Modified: scripts/redmine-tools/create-project-site.sh scripts/redmine-tools/cron-redmine scripts/redmine-tools/project-scm.rb Modified: scripts/redmine-tools/create-project-site.sh =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- scripts/redmine-tools/create-project-site.sh 2014-10-09 08:52:14 UTC (rev= 110) +++ scripts/redmine-tools/create-project-site.sh 2014-10-09 09:49:02 UTC (rev= 111) @@ -5,6 +5,7 @@ =20 FORGE=3D$1 PROJECT=3D$2 +PROJECT_NAME=3D$3 =20 #TODO Add dns entry=20 =20 @@ -49,3 +50,59 @@ mkdir /var/lib/doc/maven-site/$FORGE/$PROJECT 2> /dev/null =20 a2ensite $APACHE_SITE_NAME > /dev/null + +INDEX_FILE=3D/var/lib/doc/site/$FORGE/$PROJECT/index.html + +if [ ! -f $INDEX_FILE ]; +then + echo "Create default index.html file at $INDEX_FILE" + +cat << EOF >> $INDEX_FILE + + +$PROJECT_NAME + + + +

$PROJECT_NAME

+ +

+The main site of $PROJECT_NAME will be soon realized. +

+ +

+Meanwhile, you can consult technical sites generated by Maven +for each release (see Releases section). +

+ +

Enjoy! ($PROJECT_NAME Team)

+ +

Releases

+ + + + + + + + + + + + + + + + + + + + + +
versiondatesite
Latestsite
Nextsite

+ + + + +EOF +fi \ No newline at end of file Modified: scripts/redmine-tools/cron-redmine =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- scripts/redmine-tools/cron-redmine 2014-10-09 08:52:14 UTC (rev 110) +++ scripts/redmine-tools/cron-redmine 2014-10-09 09:49:02 UTC (rev 111) @@ -67,3 +67,10 @@ ruby /opt/redmine-tools/project-site.rb -f nuiton.org -k $nuiton_key >> $nui= ton_log #ruby /opt/redmine-tools/project-site.rb -f chorem.org -k $chorem_key >> $ch= orem_log #ruby /opt/redmine-tools/project-site.rb -f codelutin.com -k $codelutin_key = >> codelutin_log + +# Update project technical site +# TODO Do it for chorem.org and codelutin.com sites + +ruby /opt/redmine-tools/project-technical-site.rb -f nuiton.org -k $nuiton_k= ey >> $nuiton_log +#ruby /opt/redmine-tools/project-technical-site.rb -f chorem.org -k $chorem_= key >> $chorem_log +#ruby /opt/redmine-tools/project-technical-site.rb -f codelutin.com -k $code= lutin_key >> codelutin_log Modified: scripts/redmine-tools/project-scm.rb =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- scripts/redmine-tools/project-scm.rb 2014-10-09 08:52:14 UTC (rev 110) +++ scripts/redmine-tools/project-scm.rb 2014-10-09 09:49:02 UTC (rev 111) @@ -36,7 +36,7 @@ #=20 # You can find more information on the redmine's wiki : http://www.redmine.o= rg/wiki/redmine/HowTos =20 -print "run /opt/redmine-tools/project-site.rb #{ARGV}\n" +print "run /opt/redmine-tools/project-scm.rb #{ARGV}\n" =20 #tchemit - fix verbose deprecated warning about iconv (since it used in cron= , don't want to header about it) oldverb =3D $VERBOSE; $VERBOSE =3D nil Added: scripts/redmine-tools/project-site.rb =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- scripts/redmine-tools/project-site.rb (rev 0) +++ scripts/redmine-tools/project-site.rb 2014-10-09 09:49:02 UTC (rev 111) @@ -0,0 +1,176 @@ +#!/usr/bin/env ruby + +# =3D=3D changelog +# 20111029 chemit@codelutin.com +# - do not check list existance with his domain name but just his list name= (all our lists for all our forge are on this very server) +# 20090827 poussin +# - add call to config_list after list creation to update some list configur= ation +# +# =3D=3D Synopsis +# +# project-site: create site structure for all projects in a Redmine +# +# =3D=3D Usage +# +# project-site [OPTIONS...] -r [HOST] +# =20 +# Examples: +# project-site --forge=3Dnuiton.org|chorem.org|codelutin.com +# +# =3D=3D Arguments (mandatory) +# +# -f, --forge=3DHOST nuiton.org|chorem.org|codelutin.com +# -k, --key=3DKEY use KEY as the Redmine API key +# +# =3D=3D Options +# +# -h, --help show help and exit +# -v, --verbose verbose +# -V, --version print version and exit +# -q, --quiet no log +# +# + +print "run /opt/redmine-tools/project-site.rb #{ARGV}\n" + +#tchemit - fix verbose deprecated warning about iconv (since it used in cron= , don't want to header about it) +oldverb =3D $VERBOSE; $VERBOSE =3D nil +require 'iconv' +$VERBOSE =3D oldverb + +require 'getoptlong' +#require 'rdoc/usage' +require 'find' +require 'etc' + +Version =3D "1.0" + +opts =3D GetoptLong.new( + ['--forge', '-f', GetoptLong::REQUIRED_ARGUMENT= ], + ['--key', '-k', GetoptLong::REQUIRED_ARGUMENT= ], + ['--verbose', '-v', GetoptLong::NO_ARGUMENT], + ['--version', '-V', GetoptLong::NO_ARGUMENT], + ['--help' , '-h', GetoptLong::NO_ARGUMENT], + ['--quiet' , '-q', GetoptLong::NO_ARGUMENT] + ) + +$verbose =3D 0 +$quiet =3D false +$forge =3D '' + +def log(text, options=3D{}) + level =3D options[:level] || 0 + puts text unless $quiet or level > $verbose + exit 1 if options[:exit] +end + +def system_or_raise(command) + raise "\"#{command}\" failed" unless system command +end + +begin + opts.each do |opt, arg| + case opt + when '--forge'; $forge =3D arg.dup + when '--key'; $api_key =3D arg.dup + when '--verbose'; $verbose +=3D 1 + when '--version'; puts Version; exit + when '--help'; RDoc::usage + when '--quiet'; $quiet =3D true + end + end +rescue + exit 1 +end + +if ($forge.empty? or $api_key.empty?) + RDoc::usage +end + +begin + require 'active_resource' +rescue LoadError =20 + log("This script requires activeresource.\nRun 'gem install activeresource= ' to install it.", :exit =3D> true) =20 +end =20 + +class Project < ActiveResource::Base +#include Redmine::SafeAttributes +# acts_as_customizable +#class Project < ActiveRecord::Base + + self.headers["User-agent"] =3D "Redmine repository manager/#{Version}" +end + =20 +log("querying Redmine for projects...", :level =3D> 1); + +#$redmine_host.gsub!(/^/, "http://") unless $redmine_host.match("^https?://") +#$redmine_host.gsub!(/\/$/, '') + +Project.site =3D "http://forge.#{$forge}/sys"; + +begin + # Get all active projects that have the Repository module enabled + projects =3D Project.find(:all, :conditions =3D> "status =3D 1 AND parent = IS NOT NULL", :params =3D> {:key =3D> $api_key}) +rescue =3D> e + log("Unable to connect to #{Project.site}: #{e}", :exit =3D> true) +end + +if projects.nil? + log('no project found, perhaps you forgot to "Enable WS for repository man= agement"', :exit =3D> true) +end + +log("retrieved #{projects.size} projects", :level =3D> 1) + =20 +def apache_site_not_exists(forge, projectId) + cmd =3D"ls /etc/apache2/sites-available | grep -i \"site-#{projectId}.#{fo= rge}\" > /dev/null" + system(cmd) && $? && $?.exitstatus =3D=3D 0 ? false : true =20 +end + +def apache_site_create(forge, projectId, projectName) + log("will create apache site-#{projectId}.#{forge}") + cmd =3D "/opt/redmine-tools/create-project-site.sh #{forge} #{projectId} #= {projectName}" +# cmd =3D "/opt/redmine-tools/ #{forge} #{listname}" + =20 + result =3D system(cmd) && $? && $?.exitstatus =3D=3D 0 ? true : false + =20 + if result + log("apache site #{projectId}@#{forge} created", :level =3D> 1) + else + log("apache site failed #{projectId}@#{forge}", :level =3D> 1) + end + result =20 +end + +def reload_apache() + log("will reload apache") + system("service apache2 reload") +end + +update_apache =3D 0 +=20 +projects.each do |project| + log("treating project #{project.name} #{project.attributes}", :level =3D> = 1) + =20 + if project.identifier.empty? + log("\tno identifier for project #{project.name}") + next + elsif not project.identifier.match(/^[a-z0-9\-]+$/) + log("\tinvalid identifier for project #{project.name} : #{project.identi= fier}"); + next; + end + + projectId =3D "#{project.identifier}" + projectName =3D "#{project.name}" + =20 + # check apache site existance + if apache_site_not_exists($forge, projectId) + apache_site_create($forge, projectId, projectName) + update_apache =3D 1 + end + =20 + =20 +end + +if update_apache =3D 1 + reload_apache() +end Property changes on: scripts/redmine-tools/project-site.rb ___________________________________________________________________ Added: svn:executable + * Added: scripts/redmine-tools/project-technical-site.rb =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- scripts/redmine-tools/project-technical-site.rb (= rev 0) +++ scripts/redmine-tools/project-technical-site.rb 2014-10-09 09:49:02 UTC (= rev 111) @@ -0,0 +1,143 @@ +#!/usr/bin/env ruby + +# =3D=3D changelog +# +# =3D=3D Synopsis +# +# project-tecnical-site: update technical site (latest link + index.html pag= e) for all projects in a Redmine +# +# =3D=3D Usage +# +# project-technical-site [OPTIONS...] -r [HOST] +# =20 +# Examples: +# project-technical-site --forge=3Dnuiton.org|chorem.org|codelutin.com +# +# =3D=3D Arguments (mandatory) +# +# -f, --forge=3DHOST nuiton.org|chorem.org|codelutin.com +# -k, --key=3DKEY use KEY as the Redmine API key +# +# =3D=3D Options +# +# -h, --help show help and exit +# -v, --verbose verbose +# -V, --version print version and exit +# -q, --quiet no log +# +# + +print "run /opt/redmine-tools/project-technical-site.rb #{ARGV}\n" + +#tchemit - fix verbose deprecated warning about iconv (since it used in cron= , don't want to header about it) +oldverb =3D $VERBOSE; $VERBOSE =3D nil +require 'iconv' +$VERBOSE =3D oldverb + +require 'getoptlong' +#require 'rdoc/usage' +require 'find' +require 'etc' + +Version =3D "1.0" + +opts =3D GetoptLong.new( + ['--forge', '-f', GetoptLong::REQUIRED_ARGUMENT= ], + ['--key', '-k', GetoptLong::REQUIRED_ARGUMENT= ], + ['--verbose', '-v', GetoptLong::NO_ARGUMENT], + ['--version', '-V', GetoptLong::NO_ARGUMENT], + ['--help' , '-h', GetoptLong::NO_ARGUMENT], + ['--quiet' , '-q', GetoptLong::NO_ARGUMENT] + ) + +$verbose =3D 0 +$quiet =3D false +$forge =3D '' + +def log(text, options=3D{}) + level =3D options[:level] || 0 + puts text unless $quiet or level > $verbose + exit 1 if options[:exit] +end + +def system_or_raise(command) + raise "\"#{command}\" failed" unless system command +end + +begin + opts.each do |opt, arg| + case opt + when '--forge'; $forge =3D arg.dup + when '--key'; $api_key =3D arg.dup + when '--verbose'; $verbose +=3D 1 + when '--version'; puts Version; exit + when '--help'; RDoc::usage + when '--quiet'; $quiet =3D true + end + end +rescue + exit 1 +end + +if ($forge.empty? or $api_key.empty?) + RDoc::usage +end + +begin + require 'active_resource' +rescue LoadError =20 + log("This script requires activeresource.\nRun 'gem install activeresource= ' to install it.", :exit =3D> true) =20 +end =20 + +class Project < ActiveResource::Base +#include Redmine::SafeAttributes +# acts_as_customizable +#class Project < ActiveRecord::Base + + self.headers["User-agent"] =3D "Redmine repository manager/#{Version}" +end + =20 +log("querying Redmine for projects...", :level =3D> 1); + +#$redmine_host.gsub!(/^/, "http://") unless $redmine_host.match("^https?://") +#$redmine_host.gsub!(/\/$/, '') + +Project.site =3D "http://forge.#{$forge}/sys"; + +begin + =20 + # Get all active projects that have the Repository module enabled + projects =3D Project.find(:all, :conditions =3D> "status =3D 1 AND parent = IS NOT NULL", :params =3D> {:key =3D> $api_key}) +rescue =3D> e + log("Unable to connect to #{Project.site}: #{e}", :exit =3D> true) +end + +if projects.nil? + log('no project found, perhaps you forgot to "Enable WS for repository man= agement"', :exit =3D> true) +end + +log("retrieved #{projects.size} projects", :level =3D> 1) + =20 +def update_technical_site(forge, projectId) + =20 + log("will update technical site of #{projectId}.#{forge}") + cmd =3D "/opt/redmine-tools/update_technical_site.sh #{forge} #{projectId}" + system(cmd) + =20 +end +=20 +projects.each do |project| + =20 + log("treating project #{project.name}", :level =3D> 1) + =20 + if project.identifier.empty? + log("\tno identifier for project #{project.name}") + next + elsif not project.identifier.match(/^[a-z0-9\-]+$/) + log("\tinvalid identifier for project #{project.name} : #{project.identi= fier}"); + next; + end + =20 + update_technical_site($forge, "#{project.identifier}") =20 + =20 +end \ No newline at end of file Property changes on: scripts/redmine-tools/project-technical-site.rb ___________________________________________________________________ Added: svn:executable + * Added: scripts/redmine-tools/update_technical_site.sh =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- scripts/redmine-tools/update_technical_site.sh (r= ev 0) +++ scripts/redmine-tools/update_technical_site.sh 2014-10-09 09:49:02 UTC (r= ev 111) @@ -0,0 +1,87 @@ +#!/bin/bash + +# usage: update_technical_site.sh nuiton.org|chorem.org|codelutin.com=20 +# +# Will regenerate the index.html if necessary with last version found on red= mine +# Will link to latest if necessary with last version found on redmine +# +# History +# 2014-10-08 tchemit@codelutin.com : initial version +# +# + +FORGE=3D$1 +PROJECT=3D$2 + + +VERSIONS_FILE=3D/tmp/$FORGE-$PROJECT.versions + +curl http://forge.$FORGE/jredmine/get_project_closed_versions.json/$PROJECT = -s > $VERSIONS_FILE + +LAST_VERSION_NAME=3D$(cat $VERSIONS_FILE |sed -e 's/[{}]/''/g' | awk -v RS= =3D',"' -F: '/^name/ {print $2}'|cut -d\" -f 2| head -n 1) +LAST_VERSION_DATE=3D$(cat $VERSIONS_FILE |sed -e 's/[{}]/''/g' | awk -v RS= =3D',"' -F: '/^effective/ {print $2}'|cut -d\" -f 2| head -n 1) + +if [ "" =3D "$LAST_VERSION_NAME" ];=20 +then + echo "Skip - No version found for $PROJECT.$FORGE" + exit 0 +fi + +echo "Last version: $LAST_VERSION_NAME - $LAST_VERSION_DATE" + +DOC_DIR=3D/var/lib/doc/maven-site/$FORGE/$PROJECT + +if [ ! -d $DOC_DIR/$LAST_VERSION_NAME ]; +then + echo "Skip - Last version technical site not found at $DOC_DIR/$LAST_VERSI= ON_NAME" + exit 0 +fi + +unlink $DOC_DIR/latest 2> /dev/null + +(cd $DOC_DIR ; ln -s $LAST_VERSION_NAME latest) +chown www-data. $DOC_DIR/latest + +SITE_DIR=3D/var/lib/doc/site/$FORGE/$PROJECT + +INDEX_FILE=3D$SITE_DIR/index.html +INDEX_FILE2=3D/tmp/$FORGE-$PROJECT-index.html +rm -rf $INDEX_FILE2 + + +grep -e "UPDATE_START" $INDEX_FILE > /dev/null +if [ $? -eq 1 ]; +then + echo "Skip - $INDEX_FILE does not contains the UPDATE_START field, do nothi= ng" + exit 0 +fi + +grep -e "_UPDATE_ $LAST_VERSION_NAME _" $INDEX_FILE > /dev/null + +if [ $? -eq 0 ]; +then + echo "$INDEX_FILE is up-to-date" +else + echo "update $INDEX_FILE" + cat $INDEX_FILE | while read line=20 + do + echo "$line" >> $INDEX_FILE2=20 + echo $line | grep -e 'UPDATE_START' > /dev/null + if [ $? -eq 0 ] ; then + # Add new version + cat <> $INDEX_FILE2 + + =20 + $LAST_VERSION_NAME + $LAST_VERSION_DATE + site + =20 +EOF + fi + done + #cat $INDEX_FILE2 =20 + cp -f $INDEX_FILE $INDEX_FILE"_backup" + mv -f $INDEX_FILE2 $INDEX_FILE + chown www-data. $INDEX_FILE +fi + Property changes on: scripts/redmine-tools/update_technical_site.sh ___________________________________________________________________ Added: svn:executable + * --===============0947059076290864577==--