#!/usr/bin/perl use strict; use warnings; use Getopt::Tabular qw( ); use Moose::Util::TypeConstraints qw( find_type_constraint ); use Piny; my ( $batch ) = ( 0 ); my ( $name, $remote, $ikiwiki ); Getopt::Tabular::SetOptionPatterns( "(--)[\\w-]+", "(-)\\w" ); Getopt::Tabular::SetHelpOption( "--help" ); Getopt::Tabular::GetOptions( [ [ "--batch", "const", 1, \$batch, "enable batch mode, for use as a backend by other scripts" ], [ "--enable-ikiwiki|--disable-ikiwiki", "boolean", 0, \$ikiwiki, "enable or disable creation of an ikiwiki site for this repo" ] ], \@ARGV ) or exit( 0 ); ( $name, $remote ) = @ARGV; if ( not defined $name ) { print( "Usage: newrepo REPONAME\n" ); exit( 1 ); }; if ( not find_type_constraint( "Reponame" )->check( $name ) ) { print "That is not a valid repo name; must be at least 1 character long, begin with a lowercase alphanumeric character, and contain only alphanumeric characters and dashes.\n"; exit( 2 ); }; my $description; while( 1 ) { print "Provide a one-line description to be used in repo listings, the shorter the better:\n"; chomp( $description = ); if ( not find_type_constraint( "SimpleText" )->check( $description ) ) { print "Must be 1-80 characters long; control characters (including tab) not allowed.\n"; if ( $batch ) { exit( 3 ); }; next; }; print "Okay! Working, please wait...\n"; last; }; my $config = Piny::Config->new( ); my $dest = $config->piny_adminemail; unless( open( MAIL, "|/usr/lib/sendmail -t" ) ) { die "Couldn't execute sendmail: $!\n"; }; print MAIL <create( $name, $description, $remote ); } else { $repo = Piny::Repo->create( $name, $description ); }; if ( defined( $ikiwiki ) ) { $repo->config->piny_ikiwiki( $ikiwiki ); if ( $repo->config->piny_ikiwiki ne $ikiwiki ) { print( "Override in place for piny.ikiwiki.\n" ); }; }; $repo->rebuild; if ( $repo->config->piny_ikiwiki ) { $repo->rebuild_ikiwiki; print( "Repo URL: " . $repo->ikiwiki_url . "\n" ); } else { print( "Ikiwiki disabled.\n" ); }; print( "Repo URL: " . $repo->cgit_url . "\n" );