Commit 43a1be80 authored by Nigel McNie's avatar Nigel McNie

Added scripts as imported from the mahara.git public repository. Not all have...

Added scripts as imported from the mahara.git public repository. Not all have been migrated as some were useless.

Some of these scripts will need updating over time to fix bugs caused by them not being run in a Mahara checkout.
parents
#!/usr/bin/perl -w
#
# add_copyright_notice.pl
# Copyright (C) 2006-2007 Catalyst IT Ltd (http://www.catalyst.net.nz)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 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, see <http://www.gnu.org/licenses/>.
#
# This file incorporates work covered by the following copyright and
# permission notice:
#
# Copyright (C) 2006 Serious Hack Inc. (http://www.serioushack.com)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA
#
use strict;
use File::Copy;
use File::Find;
use File::Temp;
# Directories which contain files to be "licensified"
my @SRC_DIRS = ('htdocs', 'test');
# When changing the copyright notice, one must also change the appropriate
# strings in:
# - COPYING
# - debian/copyright
my $copyright_text = <<END_OF_COPYRIGHT_TEXT;
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2007 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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, see <http://www.gnu.org/licenses/>.
END_OF_COPYRIGHT_TEXT
sub process_file
{
my $filename = shift;
print "Processing $filename... ";
open INPUT, "$filename" or die "Cannot open $filename as input.";
my $in_copyright = 0; # 0 = before the header
my $copyright_holder = 'unknown';
my $product = 'unknown';
my @lines;
my @after_license_lines;
while (<INPUT>) {
if (0 == $in_copyright and m|^/\*\*|) {
$in_copyright = 1; # 1 = inside the header
}
elsif (1 == $in_copyright and m|^ \* This program is part of (.*)$|) {
$product = $1;
}
elsif (2 == $in_copyright and
m|^ \* \@copyright.*\([cC]\)\w*(.*)Catalyst IT Ltd http://catalyst.net.nz|) {
$copyright_holder = 'Catalyst IT';
push @after_license_lines, $_;
}
elsif (1 == $in_copyright and
m|^ \* Foundation, Inc\., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA|) {
$in_copyright = 2; # 2 = after the license text
}
elsif (m|\*/| and (1 == $in_copyright or 2 == $in_copyright)) {
$in_copyright = 3; # 3 = after the header
push @lines, $copyright_text;
push @lines, @after_license_lines;
push @lines, " */\n";
}
elsif (0 == $in_copyright or 3 == $in_copyright) {
push @lines, $_;
}
elsif (2 == $in_copyright) {
push @after_license_lines, $_;
}
}
close INPUT;
if ($in_copyright == 0) {
# No header was found, insert copyright text at the front?
#unshift @lines, $copyright_text;
}
die "$filename: Bad header." if $in_copyright == 1;
if ($copyright_holder eq 'Catalyst IT') {
if ($product eq 'Mahara') {
open OUTPUT, ">$filename" or die "Cannot open $filename as output.";
print OUTPUT foreach @lines;
close OUTPUT;
print "done.\n";
} else {
print "skipped (product is $product).\n";
}
} else {
print "skipped (copyright holder is $copyright_holder).\n";
}
}
sub process_standard_files
{
# Find all php and javascript files in the standard directories
File::Find::find sub { /^.*\.(php|js)$/s && process_file($_) }, @SRC_DIRS;
}
sub main
{
if (@ARGV > 0) {
while (@ARGV > 0) {
process_file(shift @ARGV);
}
} else {
&process_standard_files;
}
}
&main;
#!/bin/bash
#
# Builds release tarballs of Mahara at the given version, ready for
# distribution
set -e
print_usage() {
echo "Usage is $0 [version]"
echo "e.g. $0 0.6.2"
echo "e.g. $0 1.0.0alpha1"
}
if [ -z "$1" ]; then
print_usage
exit 1
fi
MAJOR=${1:0:3}
MINOR=${1:4:1}
MICRO=${1:5}
BUILDDIR="/tmp/mahara_release"
CURRENTDIR="`pwd`"
if [ -z "${MAJOR}" ] || [ -z "${MINOR}" ]; then
print_usage
exit 1
fi
VERSION="${MAJOR}.${MINOR}${MICRO}"
if [ -d ${BUILDDIR} ]; then
rm -rf ${BUILDDIR}
fi
mkdir ${BUILDDIR}
pushd ${BUILDDIR}
# Get the stable branch
git clone -n "http://git.catalyst.net.nz/mahara.git" mahara
pushd ${BUILDDIR}/mahara
# Switch to the release tag
#git checkout -b "${MAJOR}_STABLE" "origin/${MAJOR}_STABLE"
RELEASETAG="`echo $VERSION | tr '[:lower:]' '[:upper:]'`_RELEASE"
git checkout $RELEASETAG
# Remove git stuff
rm .git -rf
find . -name '.gitignore' -exec rm {} \;
# Pack MochiKit
bash scripts/pack.sh
popd
mv mahara mahara-${VERSION}
tar zcf ${CURRENTDIR}/mahara-${VERSION}.tar.gz mahara-${VERSION}
tar jcf ${CURRENTDIR}/mahara-${VERSION}.tar.bz2 mahara-${VERSION}
zip -qrT9 ${CURRENTDIR}/mahara-${VERSION}.zip mahara-${VERSION}
popd
#rm -rf ${BUILDDIR}
#!/bin/bash
#
# Builds and releases Mahara to the debian repo
#
# This script can release just one version (stable|testing|unstable), or all at
# once
#
set -e
BUILDDIR="/tmp/mahara_release"
REPODIR="/tmp/mahara_repo"
ARCHLIST="i386 amd64"
DATE="`date`"
print_usage() {
echo "Usage: ./scripts/catalyst-packages.sh [stable|unstable]"
echo "Run this script from the root directory of a Mahara checkout"
echo ""
}
if [ ! -d .git ]; then
print_usage
exit 1
fi
echo " *** STOP *** "
echo " Make sure you have merged master into pkg-catalyst, and the latest"
echo " stable branch into the appropriate pkg-catalyst-* branch. If you"
echo " have not done this, hit Ctrl-C now and do so."
read junk
RELEASE=$1
if [ "$RELEASE" = "" ]; then
echo -n "Building ALL versions: are you sure? (y/N) "
read ANS
if [ "$ANS" != "y" ] && [ "$ANS" != "Y" ]; then
echo "Abort."
exit 1
fi
RELEASELIST="stable unstable"
elif [ "$RELEASE" != "stable" ] && [ "$RELEASE" != "unstable" ]; then
echo "Invalid release: $RELEASE"
exit 1
else
RELEASELIST=$RELEASE
fi
if [ -d ${BUILDDIR} ]; then
rm -rf ${BUILDDIR}
fi
if [ -d ${REPODIR} ]; then
rm -rf ${REPODIR}
fi
mkdir ${BUILDDIR}
# Create repo dirs
for release in $RELEASELIST; do
mkdir -p ${REPODIR}/dists/${release}/mahara
pushd ${REPODIR}/dists/${release}/mahara
mkdir binary-all
for arch in ${ARCHLIST}; do mkdir binary-${arch}; done
popd
mkdir -p ${REPODIR}/pool/${release}
done
# If done properly, we don't need this here - the build can happen from any place that has this script
git-fetch -t
STABLE_RELEASE="`ls -1 .git/refs/tags | egrep '[0-9]+\.[0-9]+\.[0-9]+_RELEASE$' | tail -n1`"
TESTING_RELEASE="`git branch -a | grep "origin.*STABLE$" | sort | tail -1 | sed 's/origin\///' | tr -d ' '`"
STABLE_DEBIAN_BRANCH=${STABLE_RELEASE:0:3}
pushd ${BUILDDIR}
# Build Stable
if [ "$RELEASE" = "" ] || [ "$RELEASE" = "stable" ]; then
echo
echo "Building ${STABLE_RELEASE} ..."
git clone -n "git+ssh://git.catalyst.net.nz/git/public/mahara.git" mahara
( cd mahara && git checkout -b "pkg-catalyst-${STABLE_DEBIAN_BRANCH}" "origin/pkg-catalyst-${STABLE_DEBIAN_BRANCH}" )
rm -f *.deb
pushd ${BUILDDIR}/mahara
make
popd
cp *.deb ${REPODIR}/pool/stable/
rm ${BUILDDIR}/mahara -rf
fi
# Build Unstable
if [ "$RELEASE" = "" ] || [ "$RELEASE" = "unstable" ]; then
echo
echo "Building Unstable ..."
git clone "git+ssh://git.catalyst.net.nz/git/public/mahara.git" mahara
( cd mahara && git checkout -b pkg-catalyst origin/pkg-catalyst )
rm -f *.deb
pushd ${BUILDDIR}/mahara
make
popd
cp *.deb ${REPODIR}/pool/unstable/
rm ${BUILDDIR}/mahara -rf
fi
# Link other arches into all and build packages
for release in $RELEASELIST; do
pushd ${REPODIR}/pool
for arch in all ${ARCHLIST}; do
dpkg-scanpackages ${release} /dev/null /pool/ | /bin/gzip -9 > ${REPODIR}/dists/${release}/mahara/binary-${arch}/Packages.gz
dpkg-scanpackages ${release} /dev/null /pool/ > ${REPODIR}/dists/${release}/mahara/binary-${arch}/Packages
done
popd
pushd ${REPODIR}/dists/${release}
# Create Release file
cat <<EOHDR >Release
Origin: Mahara
Label: Mahara
Suite: ${release}
Date: ${DATE}
Architectures: ${ARCHLIST}
Components: mahara
Description: Mahara ${release} repository
MD5Sum:
EOHDR
for file in `find mahara -type f -name 'Packages*'`; do
MD5="`md5sum $file | cut -c1-32`"
SIZE="`cat $file | wc -c`"
printf " %s %16d %s\n" "${MD5}" "${SIZE}" "${file}" >>Release
done
gpg --yes --armour --sign-with 1D18A55D --detach-sign --output Release.gpg Release
popd
done
popd
# Steal the latest index.html and dump into
git cat-file blob origin/pkg-catalyst:debian/index.html > ${REPODIR}/index.html
# Now (optionally) sync the repo to the git repository
echo " The repo has now been set up in ${REPODIR}. If you're really sure,"
echo " this script can rsync this to the git repository."
echo " rsync to git repository? [y/N] "
read ANS
if [ "$ANS" != "y" ] && [ "$ANS" != "Y" ]; then
echo "Abort."
exit 1
fi
if [ "$RELEASE" = "" ]; then
rsync -PIlvr --delete-after --no-p --no-g --chmod=Dg+ws,Fg+w ${REPODIR}/* locke.catalyst.net.nz:/home/ftp/pub/mahara/
else
rsync -PIlvr --no-p --no-g --chmod=Dg+ws,Fg+w ${REPODIR}/* locke.catalyst.net.nz:/home/ftp/pub/mahara/
fi
#!/usr/bin/perl -w
#
# check_copyright.pl
# Copyright (C) 2007 Catalyst IT Ltd (http://www.catalyst.net.nz)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 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, see <http://www.gnu.org/licenses/>.
#
# This file incorporates work covered by the following copyright and
# permission notice:
#
# Copyright (C) 2006 Serious Hack Inc. (http://www.serioushack.com)
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA
#
use strict;
use Cwd;
use File::Copy;
use File::Find;
use File::Temp;
# Directories which contain licensed files
my @SRC_DIRS = ('htdocs', 'test');
my %detected;
sub process_file
{
my $filename = shift;
open INPUT, "$filename" or die "Cannot open $filename as input.";
my $in_copyright = 0; # 0 = before the header
my @copyright_holders;
my $license = '';
my $license_version = 0;
my $license_upgradable = 0;
my $check_carefully = 0; # Could indicate proprietary code
while (<INPUT>) {
s/\r//g;
if ('' eq $license) {
# We only look at the first license statement
if (m/under (the terms of )?the GNU (General Public|GPL)/) {
$license = 'GPL';
}
elsif (m/under (the terms of )?the GNU (Lesser General|LGPL|Lesser GPL)/) {
$license = 'LGPL';
}
elsif (m|subject to version ([\d.]+) of the PHP license|) {
$license = 'PHP';
$license_version = $1;
}
elsif (m|\@license\s+(http://[^\s]+)?(.*?)$|) {
if ($1 and !$2) {
$license = $1;
} else {
$license = $2;
}
}
elsif (m|see\s+<?([^\s]+?)>?\s+.*for.*license|i) {
$license = $1;
}
elsif (m/released under (the|a)?(.+?) Licen[cs]e/i) {
my $s = $2;
$s =~ s/both //gi;
$s =~ s/license and/and/gi;
$s =~ s/GNU //gi;
$s =~ s/Lesser GPL library/LGPL/gi;
# Trim the string
$s =~ s/^\s+//g;
$s =~ s/\s+$//g;
$license = $s;
}
elsif (m/Licen[cs]e:\s+(GPL|LGPL|BSD)/i) {
$license = uc($1);
}
}
if ($license eq 'GPL' or $license eq 'LGPL') {
if (0 == $license_version and m|version ([\d.]+) of the License|) {
$license_version = $1;
}
if ($license_version and m|any later version|) {
$license_upgradable = 1;
}
}
my $potential_holder = '';
if (m/(copyright(\s+\(c\))?|\(c\))\s+([\d\-,; ]+\s+)?(.*?)$/i) {
$potential_holder = $4;
}
elsif (m|authors?:?\s+([^,;]+)|i) {
$potential_holder = $1;
}
if ($potential_holder) {
my $s = $potential_holder;
# Ignore contributors
if ($s =~ m/Contributions from/i or $s =~ m/credits? to/i) {
$s = '';
}
# Ignore specific sentences
$s = '' if $s =~ m/(notice|legislation|statement|field for)/i;
$s = '' if $s =~ m/based on work by/i;
# That's a bad sign... Should double-check these ones
if ($s =~ m/All rights reserved/i) {
$check_carefully = 1;
}
$s =~ s/All rights reserved//gi;
$s =~ s/All rights//gi;
# Useless words
$s =~ s/the authors//gi;
$s =~ s/and others//gi;
$s =~ s/author://gi;
$s =~ s/copyright//gi;
$s =~ s/\xA9//gi;
$s =~ s/&copy;//gi;
$s =~ s/((199\d|20\d\d)[,\-]?)+//gi;
$s =~ s/onwards//gi;
$s =~ s/portions from//gi;
$s =~ s/additional modifications//gi;
$s =~ s/(and )?released (under)?.*$//gi;
$s =~ s/don't translate.*$//g;
$s =~ s/USER->get//g;
$s =~ s/userid//g;
$s =~ s/names in.*$//g;
$s =~ s/data (for|at).*$//g;
# Remove emails and URLs
$s =~ s/<[^>]+>//gi;
$s =~ s/\([^)]+\)//gi;
$s =~ s{http://[^\s]+}{}gi;
# Remove useless whitespace and punctuation
$s =~ s{[\(\),:;=\|\$+"]}{}g;
$s =~ s{\\n}{}g;
$s =~ s{//$}{}g;
$s =~ s{[{}]}{}g;
$s =~ s/\s{2,}/ /g;
$s =~ s{\s[.'/]}{}gi;
$s =~ s{^[/']}{}gi;
$s =~ s{['/]\s}{}gi;
$s =~ s{['/]$}{}gi;
$s =~ s{\s-\s}{}gi;
$s =~ s/\s{2,}/ /g;
$s =~ s{^\s+}{}g;
$s =~ s{\s+$}{}g;
if ($s) {
push @copyright_holders, $s;
}
}
}
close INPUT;
# Fill-in which license these files/URL refer to
$license = 'MIT or Academic Free License 2.1' if $license eq 'http://mochikit.com/';
$license = 'MIT' if $license eq 'scriptaculous.js';
$license = 'BSD' if $license eq 'http://www.opensource.org/licenses/bsd-license.php';
$license .= $license_version if $license_version != 0;
$license .= '+' if $license_upgradable;
if ($check_carefully and !$license) {
# These ones need to be considered carefully since the default
# is full copyright, not public domain
$license = 'proprietary?';
}
my %saw;
my @unique_copyright_holders = grep(!$saw{$_}++, @copyright_holders);
if (@unique_copyright_holders > 0) {
if ($license) {
print &Cwd::cwd()."/$filename: $license, ".join(', ', @unique_copyright_holders)."\n";
} else {
# This is fine, the overall project license applies.
#print STDERR &Cwd::cwd()."/$filename: copyright holders, but no license information\n";
}
} elsif ($license) {
print &Cwd::cwd()."/$filename: $license, unknown author(s)\n";
} else {
# This is not a problem in itself, the overall project license applies.
#print STDERR &Cwd::cwd()."/$filename\n";#": no license information or copyright holders\n";
}
}
sub process_standard_files
{
# Find all php and javascript files in the standard directories
File::Find::find sub { /^.*\.(php|js)$/s && process_file($_) }, @SRC_DIRS;
}
sub main
{
if (@ARGV > 0) {
while (@ARGV > 0) {
process_file(shift @ARGV);
}
} else {
&process_standard_files;
}
}
&main;
#
# Handles available actions for maharactl
#
# Author: Nigel McNie <nigel@catalyst.net.nz>
#
package Mahara::Action;
use strict;
use warnings;
use Carp;
use DBI;
use Data::RandomPerson;
use Data::Random::WordList;
#use Smart::Comments;
use Data::Dumper;
use IO::Prompt;
sub new {
my ($class,$config) = @_;
croak 'Need to specify config object' unless defined $config;
my $self = {};
$self->{config} = $config;
my $connect_string = 'dbi:Pg:dbname=' . $config->get('dbname');
my $host = $config->get('dbhost');
$connect_string .= ';host=' . $host if $host and $host =~ /\S/;
my $port = $config->get('dbport');
$connect_string .= ';port=' . $port if $port and $port =~ /\S/;
$self->{dbh} = DBI->connect($connect_string, $config->get('dbuser'), $config->get('dbpass'), { RaiseError => 1, PrintError => 0 });
$self->{dbh}->{HandleError} = sub { confess(shift) };
bless $self, $class;
return $self;
}
sub add_user {
my ($self) = @_;
my ($username, $password, $institution, $firstname, $lastname, $studentid, $preferredname, $email);
my $prefix = $self->{config}->get('dbprefix');
print "Creating a new user\n";
# IOprompt's interface is poos...
$username = prompt("Username: ", -while => qr{^[a-zA-Z0-9]+$}) until $username;
$password = prompt("Password: ", -echo => '*');
$institution = prompt("Institution: ", -while => qr{^[a-z]+$}, -default => 'mahara') until $institution;
$email = prompt("E-mail: ") until $email;
$firstname = prompt("First Name: ") until $firstname;
$preferredname = prompt("Preferred Name: ", -default => $firstname);
$lastname = prompt("Last Name: ") until $lastname;
$studentid = prompt("Student ID: ");
print "Creating user '$username'\n";
$self->{dbh}->begin_work;
$self->{dbh}->do('INSERT INTO ' . $prefix . 'usr
(username,password,institution,passwordchange,firstname,lastname,studentid,preferredname,email,quota)
VALUES (?,?,?,?,?,?,?,?,?,
(SELECT value::bigint FROM ' . $prefix . 'artefact_config WHERE plugin = \'file\' AND field = \'defaultquota\')
)',
undef,
$username,
$password,
$institution,
1,
$firstname,
$lastname,
$studentid,
$preferredname,
$email
);
# First name, last name and e-mail address are all required
$self->{dbh}->do('INSERT INTO ' . $prefix . 'artefact
(artefacttype,owner,ctime,mtime,atime,title)
VALUES (?,currval(\'' . $prefix . 'usr_id_seq\'),current_timestamp,current_timestamp,current_timestamp,?)', undef,
'firstname',
$firstname
);
$self->{dbh}->do('INSERT INTO ' . $prefix . 'artefact
(artefacttype,owner,ctime,mtime,atime,title)
VALUES (?,currval(\'' . $prefix . 'usr_id_seq\'),current_timestamp,current_timestamp,current_timestamp,?)', undef,
'lastname',
$lastname
);
$self->{dbh}->do('INSERT INTO ' . $prefix . 'artefact
(artefacttype,owner,ctime,mtime,atime,title)
VALUES (?,currval(\'' . $prefix . 'usr_id_seq\'),current_timestamp,current_timestamp,current_timestamp,?)', undef,
'email',
$email
);
# Insert record for primary e-mail address
$self->{dbh}->do('INSERT INTO ' . $prefix . 'artefact_internal_profile_email
(owner, email, verified, principal, artefact)
VALUES (currval(\'' . $prefix . 'usr_id_seq\'), ?, 1, 1, currval(\'' . $prefix . 'artefact_id_seq\'))', undef,
$email,
);
# These fields are optional
$self->{dbh}->do('INSERT INTO ' . $prefix . 'artefact
(artefacttype,owner,ctime,mtime,atime,title)
VALUES (?,currval(\'' . $prefix . 'usr_id_seq\'),current_timestamp,current_timestamp,current_timestamp,?)', undef,
'studentid',
$studentid
) if $studentid;
$self->{dbh}->do('INSERT INTO ' . $prefix . 'artefact
(artefacttype,owner,ctime,mtime,atime,title)
VALUES (?,currval(\'' . $prefix . 'usr_id_seq\'),current_timestamp,current_timestamp,current_timestamp,?)', undef,
'preferredname',
$preferredname
) if $preferredname;
$self->{dbh}->commit;
}
1;