#!/usr/bin/perl use strict; use warnings; use Piny; use Getopt::Long qw(:config bundling auto_abbrev); my ( $fast, $user, $help ) = ( 0, 0, 0 ); GetOptions ( "fast|f" => \$fast, "user|u" => \$user, "help|h" => \$help ); my ( $reponame, $attr, $value ) = @ARGV; sub usage { print < [attribute] [value] Summary of options: --fast, -f Skip rebuild --user, -u Configure user EOF exit ( 1 ); }; if ( $help ) { &usage; }; my $repo; my $config; my $env = Piny::Environment->instance( ); if ( $user ) { ( $attr, $value ) = @ARGV; $config = $env->user->config; } else { ( $reponame, $attr, $value ) = @ARGV; if ( not defined $reponame ) { &usage; }; $repo = Piny::Repo->new( $reponame ); $config = $repo->config; }; if ( not defined $attr ) { my $tweakables = $config->all_tweakables; foreach my $t ( sort keys %$tweakables ) { my $v = $tweakables->{$t}; if ( defined $v ) { print "$t => $v\n"; } else { print "$t undefined\n"; }; }; } else { $attr = lc $attr; $attr =~ s/\./_/g; if ( defined $value ) { unless ( $env->user->uid == 0 or $user or $repo->owner->uid == $env->user->uid ) { print "You are not the owner of that repo!\n"; exit( 3 ); }; undef $@; eval { $config->$attr( $value ); }; if ( $@ ) { print STDERR "$attr is not a legal tweakable, or $value is not a legal value for that tweakable.\n$@\n"; exit( 4 ); }; if ( $value ne $config->$attr ) { print STDERR "Failed to set $attr (perhaps an override is in place)\n"; exit( 5 ); }; if ( $attr =~ /sharedrepository|ikiwiki/i and not $user and not $fast ) { # FIXME: define in Config.pm instead of here $repo->rebuild; }; }; undef $@; eval { print "$attr = " . $config->$attr . "\n"; }; if ( $@ ) { print STDERR "$attr is not a legal tweakable, or its current value is illegal.\n$@\n"; exit( 6 ); }; };