diff --git a/en/gallery/fixurls.pl b/en/gallery/fixurls.pl new file mode 100755 index 0000000000..e4dd3ae804 --- /dev/null +++ b/en/gallery/fixurls.pl @@ -0,0 +1,54 @@ +#!/usr/bin/perl + +# This script is dedicated to check existing gallery XML file. +# Check its URLs for duplicates and fixup incorrectly submitted ones. +# +# History: +# 31082001 Alexey Zelkin Initial version +# +# Usage: +# fixurls.pl gallery.xml output.xml +# +# $FreeBSD$ + +if (-f $ARGV[0]) { + $src = $ARGV[0]; +} else { + die "Could not open source file!" +} + +if ($ARGV[1] eq "") { + die "Could not open output file!" +} else { + $dst = $ARGV[1]; +} + +open (SRC, $src); +open (DST, ">$dst"); + +while () { + if ($_ =~ /\.*\<\/url\>/) { + chomp; + s/.*url\>(.*)\<\/url.*/$1/; + next if ($_ eq ""); + # add "http://" at the begining of the url unless it (or any + # other (like "ftp://") protocol is already specified + $_ = "http://" . $_ unless (m/^[a-z]*:\/\/.*$/); + if (defined $hhash{$_}) { + $hhash{$_}++; + } else { + $hhash{$_} = 1; + } + print DST " $_\n"; + } else { + print DST $_; + } +} + +close (SRC); +close (DST); + +print "Duplicated URLs:\n"; +foreach $key (sort keys %hhash) { + print "$hhash{$key}: $key\n" if ($hhash{$key} > 1); +} diff --git a/en/gallery/merge-mbox.sh b/en/gallery/merge-mbox.sh new file mode 100755 index 0000000000..fea393a244 --- /dev/null +++ b/en/gallery/merge-mbox.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +# This script is dedicated to help gallery maintainer to parse source +# mailbox which contains letters submitted by +# http://www.FreeBSD.org/cgi/gallery.cgi and merge parsed information into +# existing gallery.xml file. +# +# History: +# 31082001 Alexey Zelkin Initial version +# +# Usage: +# merge-mbox.sh src.mbox output.xml +# +# $FreeBSD$ + +# source file +if ! [ -f "$1" ]; then + echo "Could not open source mbox!" + exit 1 +fi + +# destination file (copy of gallery.xml plus new items) +if [ "$2" = "" ]; then + echo "You must specify output file name!" + exit 1 +fi + +# cleanup mailbox +/usr/bin/egrep "^[commercial,nonprofit,personal]" $1 | /usr/bin/uniq | /usr/bin/sort > TMP.mbox + +# make a copy of gallery.xml except closing tag +/usr/bin/grep -v "^<\/gallery>$" gallery.xml > $2 + +# add XMLized new items +awk -F'\t' '{ \ + print " "; \ + print " "$2""; \ + print " "$3""; \ + print " "$4""; \ + print " "$5""; \ + print " "; \ + print ""; \ +}' TMP.mbox >> $2 + +# add closing XML tag +echo "" >> $2 + +# fixup URLs +mv $2 $2.tmp +/usr/bin/perl fixurls.pl $2.tmp $2 + +# cleanup +rm $2.tmp +rm TMP.mbox