gc.sh: avoid unlikely ref name repack duplication
[girocco/readme.git] / toolbox / projtool.pl
blob395b8bf374eaf1bb41752805944873b037afeaef
1 #!/usr/bin/perl
3 # projtool.pl - command line Girocco project maintenance tool
4 # Copyright (C) 2016,2017 Kyle J. McKay. All rights reserved.
5 # License GPLv2+: GNU GPL version 2 or later.
6 # www.gnu.org/licenses/gpl-2.0.html
7 # This is free software: you are free to change and redistribute it.
8 # There is NO WARRANTY, to the extent permitted by law.
10 use strict;
11 use warnings;
12 use vars qw($VERSION);
13 BEGIN {*VERSION = \'1.0'}
14 use File::Basename;
15 use Digest::MD5 qw(md5_hex);
16 use IO::Socket;
17 use Cwd qw(realpath);
18 use lib "__BASEDIR__";
19 use Girocco::Config;
20 use Girocco::Util;
21 use Girocco::HashUtil;
22 use Girocco::CLIUtil;
23 use Girocco::Project;
24 use Girocco::User;
26 exit(&main(@ARGV)||0);
28 our $help;
29 BEGIN {$help = <<'HELP'}
30 Usage: %s [--quiet] <command> <options>
32 list [--verbose] [--sort=lcname|name|owner|gid|no] [--owner] [<regexp>]
33 list all projects (default is --sort=lcname)
34 limit to project names matching <regex> if given
35 match <regex> against owner instead of project name with --owner
37 create [--force] [--no-alternates] [--orphan] [<option>...] <project>
38 create new project <project> (prompted)
39 <option> can be:
40 --no-alternates skip setup of objects/info/alternates
41 --orphan allow creation of subproject w/o a parent
42 -p use mkdir -p during --orphan creation
43 --no-password set password crypt to invalid value "unknown"
44 --no-owner leave the gitweb.owner config unset
45 --mirror=<url> create a mirror from <url>
46 --full-mirror mirror all refs
47 --push[=<list>] create a push project
48 --desc=<string> specify project description w/o prompt
49 --defaults do no interactive prompting at all
50 Using --no-password skips the prompts for password, using
51 --no-owner skips the prompt for owner and using --mirror=<url>
52 or --push[=<list>] skips the prompts for mirror URL and
53 heads-only and push users. With --defaults if neither
54 --mirror=<url> nor --push[=<list>] is given then --push will
55 be implied. Using --desc=<string> will force a specific
56 description (including an empty string) and skip the prompt for
57 it. Otherwise a non-empty default description will always be
58 supplied in lieu of an empty or omitted description.
60 adopt [--force] [--type=mirror|push] [<option>...] <project> [<users>]
61 adopt project <project>
62 type of project is guessed if --type=<type> omitted
63 <users> is same as <newuserslist> for setusers command
64 <option> can be:
65 --dry-run do all the checks but don't perform adoption
66 --verbose show project info dump (useful with --dry-run)
67 --no-users no push users at all (<users> must be omitted)
68 --no-owner leave the gitweb.owner config totally unchanged
69 --owner=<val> set the gitweb.owner config to <val>
70 Both --no-owner and --owner=<val> may NOT be given, with neither
71 take owner from preexisting gitweb.owner else use admin setting.
72 For mirrors <users> is ignored otherwise if no <users> and no
73 --no-users option the push users list will consist of the single
74 user name matching the owner or empty if none or more than one.
75 With --dry-run <project> can be an absolute path to a git dir.
77 remove [--force] [--really-delete] [--keep-forks] <project>
78 remove project <project>
79 do not move to _recyclebin with --really-delete (just rm -rf)
80 remove projects with forks (by keeping forks) using --keep-forks
82 show <project>
83 show project <project>
85 listheads <project>
86 list all available heads for <project> and indicate current head
88 listtags [--verbose] <project>
89 list all ctags on project <project>
91 deltags <project> [-i] <tagstodel>
92 remove any ctags on project <project> present in <tagstodel>
93 <tagstodel> is space or comma separated list of tags to remove
94 with -i match against <tagstodel> without regard to letter case
96 addtags <project> <tagstoadd>
97 add ctags to project <project>
98 <tagstoadd> is space or comma separated list of tags to add
100 chpass [--force] <project> [random | unknown]
101 change project <project> password (prompted)
102 with "random" set to random password
103 with "unknown" set password hash to invalid value "unknown"
105 checkpw <project>
106 check project <project> password for a match (prompted)
108 gc [--force | --auto] [--redelta] <project>
109 run the gc.sh script on project <project>
110 with --auto let the gc.sh script decide what to do
111 with --force cause a full gc to take place (force_gc=1)
112 with neither --auto nor --force do a mini or if needed a full gc
113 (in other words just touch .needsgc and run gc.sh)
114 with --redelta a full gc will use pack-objects --no-reuse-delta
115 unless the global --quiet option is given show_progress=1 is used
117 remirror [--force] <project>
118 initiate a remirror of project <project>
120 [set]owner [--force] <project> <newowner>
121 set project <project> owner to <newowner>
122 without "set" and only 1 arg, just show current project owner
124 [set]desc [--force] <project> <newdesc>
125 set project <project> description to <newdesc>
126 without "set" and only 1 arg, just show current project desc
128 [set]readme [--force] <project> <newsetting>
129 set project <project> readme to <newsetting>
130 <newsetting> is automatic|suppressed|-|[@]filename
131 without "set" and only 2 args, just show current readme setting
133 [set]head <project> <newhead>
134 set project <project> HEAD symbolic ref to <newhead>
135 without "set" and only 1 arg, just show current project HEAD
137 [set]bool [--force] <project> <flagname> <boolvalue>
138 set project <project> boolean <flagname> to <boolvalue>
139 <flagname> is cleanmirror|reverseorder|summaryonly|statusupdtaes
140 without "set" and only 2 args, just show current flag value
142 [set]autogchack <project> <boolvalue> | unset
143 set project <project> autogchack to <boolvalue> or "unset" it
144 without "set" just show current autogchack setting if enabled
145 with "set" autogchack must be enabled in Config.pm for the
146 type of project and maintain-auto-gc-hack.sh is always run
148 [set]url [--force] <project> <urlname> <newurlvalue>
149 set project <project> url <urlname> to <newurlvalue>
150 <urlname> is baseurl|homepage|notifyjson
151 without "set" and only 2 args, just show current url value
153 [set]msgs [--force] <project> <msgsname> <eaddrlist>
154 set project <project> msgs <msgsname> to <addrlist>
155 <msgsname> is notifymail|notifytag
156 <eaddrlist> is space or comma separated list of email addresses
157 without "set" and only 2 args, just show current msgs value
159 [set]users [--force] <project> <newuserslist>
160 set push project <project> users list to <newuserslist>
161 <newuserslist> is space or comma separated list of user names
162 without "set" and only 1 arg, just show current users list
164 get <project> <fieldname>
165 show project <project> field <fieldname>
166 <fieldname> is owner|desc|readme|head|users
167 or <flagname>|autogchack|<urlname>|<msgsname>
169 set [--force] <project> <fieldname> <newfieldvalue>
170 set project <project> field <fieldname> to <newfieldvalue>
171 <fieldname> same as for get
172 <newfieldvalue> same as for corresponding set... command
173 HELP
175 our $quiet;
176 our $setopt;
177 sub die_usage {
178 my $sub = shift || diename;
179 if ($sub) {
180 die "Invalid arguments to $sub command -- try \"help\"\n";
181 } else {
182 die "Invalid arguments -- try \"help\"\n";
186 sub get_readme_desc {
187 my $rm = shift;
188 defined($rm) or $rm = '';
189 if (length($rm)) {
190 my $test = $rm;
191 $test =~ s/<!--(?:[^-]|(?:-(?!-)))*-->//gs;
192 $test =~ s/\s+//s;
193 return $test eq '' ? "suppressed" : "length " . length($rm);
194 } else {
195 return "automatic";
199 sub get_ctag_counts {
200 my $project = shift;
201 my $compact = shift;
202 my @ctags = ();
203 foreach ($project->get_ctag_names) {
204 my $val = 0;
205 my $ct;
206 if (open $ct, '<', $project->{path}."/ctags/$_") {
207 my $count = <$ct>;
208 close $ct;
209 defined $count or $count = '';
210 chomp $count;
211 $val = $count =~ /^[1-9]\d*$/ ? $count : 1;
213 if ($compact) {
214 if ($val == 1) {
215 push(@ctags, $_);
216 } elsif ($val > 1) {
217 push(@ctags, $_."(".$val.")");
219 } else {
220 push(@ctags, [$_, $val]) if $val;
223 @ctags;
226 sub get_clean_project {
227 my $project = get_project(@_);
228 delete $project->{loaded};
229 delete $project->{base_path};
230 delete $project->{ccrypt};
231 /^orig/i || !defined($project->{$_}) and delete $project->{$_} foreach keys %$project;
232 $project->{owner} = $project->{email}; delete $project->{email};
233 $project->{homepage} = $project->{hp}; delete $project->{hp};
234 $project->{baseurl} = $project->{url}; delete $project->{url};
235 my $owner = $project->{owner};
236 if ($owner) {
237 $owner = lc($owner);
238 my @owner_users = map {$owner eq lc($$_[4]) ? $$_[1] : ()} get_all_users;
239 $project->{owner_users} = \@owner_users if @owner_users;
241 my $projname = $project->{name};
242 my @forks = grep {$$_[1] =~ m,^$projname/,} get_all_projects;
243 $project->{has_forks} = 1 if @forks;
244 $project->{has_alternates} = 1 if $project->has_alternates;
245 my @bundles = $project->bundles;
246 delete $project->{bundles};
247 $project->{bundles} = \@bundles if @bundles;
248 $project->{mirror} = 0 unless $project->{mirror};
249 $project->{is_empty} = 1 if $project->is_empty;
250 delete $project->{showpush} unless $project->{showpush};
251 delete $project->{users} if $project->{mirror};
252 delete $project->{baseurl} unless $project->{mirror};
253 delete $project->{banged} unless $project->{mirror};
254 delete $project->{lastrefresh} unless $project->{mirror};
255 delete $project->{cleanmirror} unless $project->{mirror};
256 delete $project->{statusupdates} unless $project->{mirror};
257 delete $project->{lastparentgc} unless $projname =~ m,/,;
258 unless ($project->{banged}) {
259 delete $project->{bangcount};
260 delete $project->{bangfirstfail};
261 delete $project->{bangmessagesent};
263 $project->{README} = get_readme_desc($project->{README}) if exists($project->{README});
264 my @tags = get_ctag_counts($project, 1);
265 $project->{tags} = \@tags if @tags;
266 $project;
269 sub clean_addrlist {
270 my %seen = ();
271 my @newlist = ();
272 foreach (split(/[,\s]+/, $_[0])) {
273 next unless $_;
274 $seen{lc($_)} = 1, push(@newlist, $_) unless $seen{lc($_)};
276 return join(($_[1]||","), @newlist);
279 sub valid_addrlist {
280 my $cleaned = clean_addrlist(join(" ", @_));
281 return 1 if $cleaned eq "";
282 valid_email_multi($cleaned) && length($cleaned) <= 512;
285 sub validate_users {
286 my ($userlist, $force, $nodie, $quiet) = @_;
287 my @newusers = ();
288 my $badlist = 0;
289 my %seenuser = ();
290 my $mobok = $Girocco::Config::mob && $Girocco::Config::mob eq "mob";
291 my %users = map({($$_[1] => $_)} get_all_users);
292 foreach (split(/[\s,]+/, $userlist)) {
293 if (exists($users{$_}) || $_ eq "everyone" || ($mobok && $_ eq "mob")) {
294 $seenuser{$_}=1, push(@newusers, $_) unless $seenuser{$_};
295 next;
297 if (Girocco::User::does_exist($_, 1)) {
298 if ($force) {
299 $seenuser{$_}=1, push(@newusers, $_) unless $seenuser{$_};
300 } else {
301 $badlist = 1;
302 warn "refusing to allow questionable user \"$_\" without --force\n" unless $nodie && $quiet;
304 next;
306 $badlist = 1;
307 warn "invalid user: \"$_\"\n" unless $nodie && $quiet
309 die if $badlist && !$nodie;
310 return @newusers;
313 sub is_default_desc {
314 # "Unnamed repository; edit this file 'description' to name the repository."
315 # "Unnamed repository; edit this file to name it for gitweb."
316 local $_ = shift;
317 return 0 unless defined($_);
318 /Unnamed\s+repository;/i && /\s+edit\s+this\s+file\s+/i && /\s+to\s+name\s+/i;
321 sub valid_desc {
322 my $test = shift;
323 chomp $test;
324 return 0 if $test =~ /[\r\n]/;
325 $test =~ s/\s\s+/ /g;
326 $test =~ s/^\s+//;
327 $test =~ s/\s+$//;
328 return $test ne '';
331 sub clean_desc {
332 my $desc = shift;
333 defined($desc) or $desc = '';
334 chomp $desc;
335 $desc = to_utf8($desc, 1);
336 $desc =~ s/\s\s+/ /g;
337 $desc =~ s/^\s+//;
338 $desc =~ s/\s+$//;
339 return $desc;
342 sub parse_options {
343 Girocco::CLIUtil::_parse_options(
344 sub {
345 warn((($_[0]eq'?')?"unrecognized":"missing argument for")." option \"$_[1]\"\n")
346 unless $quiet;
347 die_usage;
348 }, @_);
351 sub cmd_list {
352 my %sortsub = (
353 lcname => sub {lc($$a[1]) cmp lc($$b[1])},
354 name => sub {$$a[1] cmp $$b[1]},
355 gid => sub {$$a[3] <=> $$b[3]},
356 owner => sub {lc($$a[4]) cmp lc($$b[4]) || lc($$a[1]) cmp lc($$b[1])},
357 no => sub {$$a[0] <=> $$b[0]},
359 my $sortopt = 'lcname';
360 my ($verbose, $owner);
361 parse_options(":sort" => \$sortopt, verbose => \$verbose, owner => \$owner);
362 my $regex;
363 if (@ARGV) {
364 my $val = shift @ARGV;
365 $regex = qr($val) or die "bad regex \"$val\"\n";
367 !@ARGV && exists($sortsub{$sortopt}) or die_usage;
368 my $sortsub = $sortsub{$sortopt};
369 my $grepsub = defined($regex) ? ($owner ? sub {$$_[4] =~ /$regex/} : sub {$$_[1] =~ /$regex/}) : sub {1};
370 my @projects = sort($sortsub grep {&$grepsub} get_all_projects);
371 if ($verbose) {
372 print map(sprintf("%s\n", join(":", (@$_)[1..5])), @projects);
373 } else {
374 print map(sprintf("%s: %s\n", $$_[1], $$_[5] =~ /^:/ ? "<mirror>" : $$_[5]), @projects);
376 return 0;
379 sub cmd_create {
380 my ($force, $noalternates, $orphanok, $optp, $nopasswd, $noowner, $defaults, $ispush, $pushusers,
381 $ismirror, $desc, $fullmirror);
382 parse_options(
383 force => \$force, "no-alternates" => \$noalternates, orphan => \$orphanok, p => \$optp,
384 "no-password" => \$nopasswd, "no-owner" => \$noowner, defaults => \$defaults,
385 "push" => \$ispush, ":push" => \$pushusers, ":mirror" => \$ismirror, ":desc" => \$desc,
386 "full-mirror" => \$fullmirror);
387 @ARGV == 1 or die_usage;
388 !defined($pushusers) || defined($ispush) or $ispush = 1;
389 defined($ismirror) && $ismirror =~ /^\s*$/ and die "--mirror url must not be empty\n";
390 die "--mirror and --push are mutually exclusive options\n" if $ismirror && $ispush;
391 die "--full-mirror requires use of --mirror=<url> option\n" if $fullmirror && !$ismirror;
392 !$defaults || defined($ispush) || defined($ismirror) or $ispush = 1;
393 !$defaults || defined($nopasswd) or $nopasswd = 1;
394 !$defaults || defined($noowner) or $noowner = 1;
395 !defined($ispush) || defined($pushusers) or $pushusers = "";
396 my $projname = $ARGV[0];
397 $projname =~ s/\.git$//i;
398 Girocco::Project::does_exist($projname, 1) and die "Project already exists: \"$projname\"\n";
399 if (!Girocco::Project::valid_name($projname, $orphanok, $optp)) {
400 warn "Refusing to create orphan project without --orphan\n"
401 if !$quiet && !$orphanok && Girocco::Project::valid_name($projname, 1, 1);
402 warn "Required orphan parent directory does not exist (use -p): ",
403 $Girocco::Config::reporoot.'/'.Girocco::Project::get_forkee_name($projname), "\n"
404 if !$quiet && $orphanok && Girocco::Project::valid_name($projname, 1, 1);
405 die "Invalid project name: \"$projname\"\n";
407 my ($forkee, $project) = ($projname =~ m#^(.*/)?([^/]+)$#);
408 my $newtype = $forkee ? 'fork' : 'project';
409 if (length($project) > 64) {
410 die "The $newtype name is longer than 64 characters. Do you really need that much?\n"
411 unless $force;
412 warn "Allowing $newtype name longer than 64 characters with --force\n" unless $quiet;
414 unless ($Girocco::Config::push || $Girocco::Config::mirror) {
415 die "Project creation disabled (no mirrors or push projects allowed)\n" unless $force;
416 warn "Continuing with --force even though both push and mirror projects are disabled\n" unless $quiet;
418 print "Enter settings for new project \"$projname\"\n" unless $defaults;
419 my %settings = ();
420 $settings{noalternates} = $noalternates;
421 if ($nopasswd) {
422 $settings{crypt} = "unknown";
423 } else {
424 my $np1 = prompt_noecho_nl_or_die("Admin password for project $projname (echo is off)");
425 $np1 ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
426 my $np2 = prompt_noecho_nl_or_die("Retype admin password for project $projname");
427 $np1 eq $np2 or die "Our high-paid security consultants have determined that\n" .
428 "the admin passwords you have entered do not match each other.\n";
429 $settings{crypt} = scrypt_sha1($np1);
431 my $owner = "";
432 unless ($noowner) {
433 $owner = prompt_or_die("Owner/email name for project $projname");
434 unless (valid_email($owner)) {
435 unless ($force) {
436 warn "Your email sure looks weird...?\n";
437 redo;
439 warn "Allowing invalid email with --force\n" unless $quiet;
441 if (length($owner) > 96) {
442 unless ($force) {
443 warn "Your email is longer than 96 characters. Do you really need that much?\n";
444 redo;
446 warn "Allowing email longer than 96 characters with --force\n" unless $quiet;
449 $settings{email} = $owner;
450 my $baseurl = "";
451 my $checkmirror = sub {
452 my $checkurl = shift;
453 unless (valid_repo_url($checkurl)) {
454 unless ($force) {
455 warn "Invalid mirror URL: \"$checkurl\"\n";
456 return undef;
458 warn "Allowing invalid mirror URL with --force\n" unless $quiet;
460 if ($Girocco::Config::restrict_mirror_hosts) {
461 my $mh = extract_url_hostname($checkurl);
462 unless (is_dns_hostname($mh)) {
463 unless ($force) {
464 warn "Invalid non-DNS mirror URL: \"$checkurl\"\n";
465 undef;
467 warn "Allowing non-DNS mirror URL with --force\n" unless $quiet;
469 if (is_our_hostname($mh)) {
470 unless ($force) {
471 warn "Invalid same-host mirror URL: \"$checkurl\"\n";
472 return undef;
474 warn "Allowing same-host mirror URL with --force\n" unless $quiet;
477 return $checkurl;
479 if ($ispush || $ismirror) {
480 !$ispush || $force || $Girocco::Config::push or
481 die "Push projects are disabled, create a mirror (or use --force)\n";
482 !$ismirror || $force || $Girocco::Config::mirror or
483 die "Mirror projects are disabled, create a push project (or use --force)\n";
484 if ($ismirror) {
485 &$checkmirror($ismirror) or die "Invalid --mirror URL\n";
486 $baseurl = $ismirror;
487 $settings{url} = $baseurl;
488 $settings{cleanmirror} = $fullmirror ? 0 : 1;
489 } else {
490 my @newusers = ();
491 if ($pushusers !~ /^[\s,]*$/) {
492 eval {@newusers = validate_users($pushusers, $force); 1;} or
493 die "Invalid --push user list\n";
495 $settings{users} = \@newusers;
497 } elsif ($force || $Girocco::Config::mirror) {{
498 if ($force || $Girocco::Config::push) {
499 $baseurl = prompt_or_die("URL to mirror from (leave blank for push project)", "");
500 } else {{
501 $baseurl = prompt_or_die("URL to mirror from");
502 unless ($baseurl ne "") {
503 warn "Push projects are disabled, you must enter a mirror URL (or use --force)\n";
504 redo;
507 if ($baseurl ne "") {
508 &$checkmirror($baseurl) or redo;
509 $settings{url} = $baseurl;
510 $settings{cleanmirror} =
511 ynprompt_or_die("Mirror only heads, tags and notes (Y/n)", "Yes");
514 my $mirror = ($baseurl eq "") ? 0 : 1;
515 my $checkdesc = sub {
516 my $d = shift;
517 if (length($d) > 1024) {
518 unless ($force) {
519 warn "Short description length greater than 1024 characters!\n";
520 return undef;
522 warn "Allowing short description length greater than 1024 characters\n" unless $quiet;
524 return $d;
526 if (defined($desc)) {
527 $desc =~ s/^\s+//; $desc =~ s/\s+$//;
528 $desc eq "" || &$checkdesc($desc) or
529 die "Invalid --desc description\n";
530 } elsif (!$defaults) {
531 $desc = prompt_or_die("Short description", "");
532 $desc =~ s/^\s+//; $desc =~ s/\s+$//;
533 $desc eq "" || &$checkdesc($desc) or redo;
534 $desc = undef if $desc eq "";
536 defined($desc) or $desc = $mirror ? "Mirror of $baseurl" : "Push project $projname";
537 $settings{desc} = $desc;
538 my $homepage = "";
539 if (!$defaults) {
540 $homepage = prompt_or_die("Home page URL", "");
541 if ($homepage ne "" && !valid_web_url($homepage)) {
542 unless ($force) {
543 warn "Invalid home page URL: \$homepage\"\n";
544 redo;
546 warn "Allowing invalid home page URL with --force\n" unless $quiet;
549 $settings{hp} = $homepage;
550 my $jsonurl = "";
551 if (!$defaults) {
552 $jsonurl = prompt_or_die("JSON notify POST URL", "");
553 if ($jsonurl ne "" && !valid_web_url($jsonurl)) {
554 unless ($force) {
555 warn "Invalid JSON notify POST URL: \$jsonurl\"\n";
556 redo;
558 warn "Allowing invalid JSON notify POST URL with --force\n" unless $quiet;
561 $settings{notifyjson} = $jsonurl;
562 my $commitaddrs = "";
563 if (!$defaults) {
564 $commitaddrs = clean_addrlist(prompt_or_die("Commit notify email addr(s)", ""));
565 if ($commitaddrs ne "" && !valid_addrlist($commitaddrs)) {
566 unless ($force) {
567 warn"invalid commit notify email address list (use --force to accept): \"$commitaddrs\"\n";
568 redo;
570 warn "using invalid commit notify email address list with --force\n" unless $quiet;
573 $settings{notifymail} = $commitaddrs;
574 $settings{reverseorder} = 1;
575 $settings{reverseorder} = ynprompt_or_die("Oldest-to-newest commit order in emails", "Yes")
576 if !$defaults && $commitaddrs ne "";
577 $settings{summaryonly} = ynprompt_or_die("Summary only (no diff) in emails", "No")
578 if !$defaults && $commitaddrs ne "";
579 my $tagaddrs = "";
580 if (!$defaults) {
581 $tagaddrs = clean_addrlist(prompt_or_die("Tag notify email addr(s)", ""));
582 if ($tagaddrs ne "" && !valid_addrlist($tagaddrs)) {
583 unless ($force) {
584 warn"invalid tag notify email address list (use --force to accept): \"$tagaddrs\"\n";
585 redo;
587 warn "using invalid tag notify email address list with --force\n" unless $quiet;
590 $settings{notifytag} = $tagaddrs;
591 if (!$mirror && !$ispush) {
592 my @newusers = ();
594 my $userlist = prompt_or_die("Push users", join(",", @newusers));
595 eval {@newusers = validate_users($userlist, $force); 1;} or redo;
597 $settings{users} = \@newusers;
599 my $newproj = Girocco::Project->ghost($projname, $mirror, $orphanok, $optp)
600 or die "Girocco::Project->ghost call failed\n";
601 my ($k, $v);
602 $newproj->{$k} = $v while ($k, $v) = each(%settings);
603 my $killowner = sub {
604 system($Girocco::Config::git_bin, '--git-dir='.$newproj->{path},
605 'config', '--unset', "gitweb.owner");
607 if ($mirror) {
608 $newproj->premirror or die "Girocco::Project->premirror failed\n";
609 !$noowner or &$killowner;
610 $newproj->clone or die "Girocco::Project->clone failed\n";
611 warn "Project $projname created and cloning successfully initiated.\n"
612 unless $quiet;
613 } else {
614 $newproj->conjure or die "Girocco::Project->conjure failed\n";
615 !$noowner or &$killowner;
616 warn "New push project fork is empty due to use of --no-alternates\n"
617 if !$quiet && $projname =~ m,/, && $noalternates;
618 warn "Project $projname successfully created.\n" unless $quiet;
620 return 0;
623 sub git_config {
624 my $gd = shift;
625 system($Girocco::Config::git_bin, "--git-dir=$gd", 'config', @_) == 0
626 or die "\"git --git-dir='$gd' config ".join(" ", @_)."\" failed.\n";
629 sub cmd_adopt {
630 my ($force, $type, $nousers, $dryrun, $noowner, $owner, $users, $verbose);
631 parse_options(force => \$force, ":type" => \$type, "no-users" => \$nousers, "dry-run" => \$dryrun,
632 "no-owner" => \$noowner,":owner" => \$owner, quiet => \$quiet, q =>\$quiet, verbose => \$verbose);
633 @ARGV or die "Please give project name on command line.\n";
634 my $projname = shift @ARGV;
635 (!$noowner || !defined($owner)) && (!$nousers || !@ARGV) or die_usage;
636 !defined($type) || $type eq "mirror" || $type eq "push" or die_usage;
637 defined($type) or $type = "";
638 my $projdir;
639 if ($dryrun && $projname =~ m,^/[^.\s/\\:], && is_git_dir(realpath($projname))) {
640 $projdir = realpath($projname);
641 $projname = $projdir;
642 $projname =~ s/\.git$//i;
643 $projname =~ s,/+$,,;
644 $projname =~ s,^.*/,,;
645 $projname ne "" or $projname = $projdir;
646 } else {
647 $projname =~ s/\.git$//i;
648 $projname ne "" or die "Invalid project name \"\".\n";
649 unless (Girocco::Project::does_exist($projname, 1)) {
650 Girocco::Project::valid_name($projname, 1, 1)
651 or die "Invalid project name \"$projname\".\n";
652 die "No such project to adopt: $projname\n";
654 defined(girocco::Project->load($projname))
655 and die "Project already known (no need to adopt): $projname\n";
656 $projdir = $Girocco::Config::reporoot . "/" . $projname . ".git";
657 is_git_dir($projdir) or die "Not a git directory: \"$projdir\"\n";
659 my $config = read_config_file($projdir . "/config");
660 my %config = ();
661 %config = map {($$_[0], defined($$_[1])?$$_[1]:"true")} @$config if defined($config);
662 git_bool($config{"core.bare"}) or die "Not a bare git repository: \"$projdir\"\n";
663 defined(read_HEAD_symref($projdir)) or die "Project with non-symbolic HEAD ref: \"$projdir\"\n";
664 @ARGV and $users = [validate_users(join(" ", @ARGV), $force, 1, $quiet)];
665 my $desc = "";
666 if (-e "$projdir/description") {
667 open my $fd, '<', "$projdir/description" or die "Cannot open \"$projdir/description\": $!\n";
669 local $/;
670 $desc = <$fd>;
672 close $fd;
673 defined $desc or $desc = "";
674 chomp $desc;
675 $desc = to_utf8($desc, 1);
676 is_default_desc($desc) and $desc = "";
677 if ($desc ne "" && !valid_desc($desc)) {
678 die "invalid 'description' file contents (use --force to accept): \"$desc\"\n"
679 unless $force;
680 warn "using invalid 'description' file contents with --force\n" unless $quiet;
682 $desc = clean_desc($desc);
683 if (length($desc) > 1024) {
684 die "description longer than 1024 chars (use --force to accept): \"$desc\"\n"
685 unless $force;
686 warn "using longer than 1024 char description with --force\n" unless $quiet;
689 my $readme = "";
690 if (-e "$projdir/README.html") {
691 open my $fd, '<', "$projdir/README.html" or die "Cannot open \"$projdir/README.html\": $!\n";
693 local $/;
694 $readme = <$fd>;
696 close $fd;
697 defined $readme or $readme = "";
698 $readme = to_utf8($readme, 1);
699 $readme =~ s/\r\n?/\n/gs;
700 $readme =~ s/^\s+//s;
701 $readme =~ s/\s+$//s;
702 $readme eq "" or $readme .= "\n";
703 if (length($readme) > 8192) {
704 die "readme greater than 8192 chars is too long (use --force to override)\n"
705 unless $force;
706 warn "using readme greater than 8192 chars with --force\n" unless $quiet;
708 my $rd = get_readme_desc($readme);
709 if ($rd ne "automatic" && $rd ne "suppressed") {
710 my $xmllint = qx(command -v xmllint); chomp $xmllint;
711 if (-f $xmllint && -x $xmllint) {
712 my $dummy = {README => $readme};
713 my ($cnt, $err) = Girocco::Project::_lint_readme($dummy, 0);
714 if ($cnt) {
715 my $msg = "xmllint: $cnt error";
716 $msg .= "s" unless $cnt == 1;
717 print STDERR "$msg\n", "-" x length($msg), "\n", $err
718 unless $force && $quiet;
719 exit(255) unless $force;
720 warn "$projname: using invalid raw HTML with --force\n" unless $quiet;
722 } else {
723 die "xmllint not available, refusing to use raw HTML without --force\n"
724 unless $force;
725 warn "xmllint not available using unchecked raw HTML with --force\n" unless $quiet;
729 # Inspect any remotes now
730 # Yes, Virginia, remote urls can be multi-valued
731 my %remotes = ();
732 foreach (@$config) {
733 my ($k,$v) = @$_;
734 next unless $k =~ /^remote\.([^\/].*?)\.([^.]+)$/; # remote name cannot start with "/"
735 my ($name, $subkey) = ($1, $2);
736 $remotes{$name}->{skip} = git_bool($v,1), next if $subkey eq "skipdefaultupdate" || $subkey eq "skipfetchall";
737 $remotes{$name}->{mirror} = git_bool($v,1), next if $subkey eq "mirror"; # we might want this
738 $remotes{$name}->{vcs} = $v, next if defined($v) && $v !~ /^\s*$/ && $subkey eq "vcs";
739 push(@{$remotes{$name}->{$subkey}}, $v), next if defined($v) && $v !~ /^\s*$/ &&
740 ($subkey eq "url" || $subkey eq "fetch" || $subkey eq "push" || $subkey eq "pushurl");
742 # remotes.default is the default remote group to fetch for "git remote update" otherwise --all
743 # the remote names in a group are separated by runs of [ \t\n] characters
744 # remote names "", ".", ".." and any name starting with "/" are invalid
745 # a remote with no url or vcs setting is not considered valid
746 my @check = ();
747 my $usingall = 0;
748 if (exists($config{"remotes.default"})) {
749 foreach (split(/[ \t\n]+/, $config{"remotes.default"})) {
750 next unless exists($remotes{$_});
751 my $rmt = $remotes{$_};
752 next if !exists($rmt->{url}) && !$rmt->{vcs};
753 push(@check, $_);
755 } else {
756 $usingall = 1;
757 my %seenrmt = ();
758 foreach (@$config) {
759 my ($k,$v) = @$_;
760 next unless $k =~ /^remote\.([^\/].*?)\.[^.]+$/;
761 next if $seenrmt{$1};
762 $seenrmt{$1} = 1;
763 next unless exists($remotes{$1});
764 my $rmt = $remotes{$1};
765 next if $rmt->{skip} || (!exists($rmt->{url}) && !$rmt->{vcs});
766 push(@check, $1);
769 my @needskip = (); # remotes that need skipDefaultUpdate set to true
770 my $foundvcs = 0;
771 my $foundfetch = 0;
772 my $foundfetchwithmirror = 0;
773 foreach (@check) {
774 my $rmt = $remotes{$_};
775 push(@needskip, $_) if $usingall && !exists($rmt->{fetch});
776 next unless exists($rmt->{fetch});
777 ++$foundfetch;
778 ++$foundfetchwithmirror if $rmt->{mirror};
779 ++$foundvcs if $rmt->{vcs} || (exists($rmt->{url}) && $rmt->{url}->[0] =~ /^[a-zA-Z0-9][a-zA-Z0-9+.-]*::/);
781 # if we have $foundvcs then we need to explicitly set fetch.prune to false
782 # if we have $foundfetch > 1 then we need to explicitly set fetch.prune to false
783 my $neednoprune = !exists($config{"fetch.prune"}) && ($foundvcs || $foundfetch > 1);
784 my $baseurl = "";
785 my $needfakeorigin = 0; # if true we need to set remote.origin.skipDefaultUpdate = true
786 # if remote "origin" exists we always pick up its first url or use ""
787 if (exists($remotes{origin})) {
788 my $rmt = $remotes{origin};
789 $baseurl = exists($rmt->{url}) ? $rmt->{url}->[0] : "";
790 $needfakeorigin = !exists($rmt->{url}) && !$rmt->{vcs} && !$rmt->{skip};
791 } else {
792 $needfakeorigin = 1;
793 # get the first url of the @check remotes
794 foreach (@check) {
795 my $rmt = $remotes{$_};
796 next unless exists($rmt->{url});
797 next unless defined($rmt->{url}->[0]) && $rmt->{url}->[0] ne "";
798 $baseurl = $rmt->{url}->[0];
799 last;
802 my $makemirror = $type eq "mirror" || ($type eq "" && $foundfetch);
804 # If we have $foundfetch we want to make a mirror but complain if
805 # we $foundfetchwithmirror as well unless we have --type=mirror.
806 # Warn if we have --type=push and $foundfetch and !$foundfetchwithmirror.
807 # Warn if we need to set fetch.prune=false when making a mirror
808 # Warn if we need to create remote.origin.skipDefaultUpdate when making a mirror
809 # Complain if @needskip AND !$usingall (warn with --force but don't set skip)
810 # Warn if $usingall and any @needskip (and set them) if making a mirror
811 # Warn if making a mirror and $baseurl eq ""
812 # Warn if we have --type=mirror and !$foundfetch
814 if ($makemirror) {
815 warn "No base URL to mirror from for adopted \"$projname\"\n" unless $quiet || $baseurl ne "";
816 warn "Adopting mirror \"$projname\" without any fetch remotes\n" unless $quiet || $foundfetch;
817 if ($foundfetchwithmirror) {
818 warn "Refusing to adopt mirror \"$projname\" with active remote.<name>.mirror=true remote(s)\n".
819 "(Use --type=mirror to override)\n"
820 unless $type eq "mirror";
821 exit(255) unless $type eq "mirror" || $dryrun;
822 warn "Adopting mirror \"$projname\" with active remote.<name>.mirror=true remotes\n"
823 unless $quiet || $type ne "mirror";
825 warn "Setting explicit fetch.prune=false for adoption of mirror \"$projname\"\n"
826 if !$quiet && $neednoprune;
827 warn "Setting remote.origin.skipDefaultUpdate=true for adoption of mirror \"$projname\"\n"
828 if !$quiet && $needfakeorigin;
829 if (!$usingall && @needskip) {
830 warn "Refusing to adopt mirror empty fetch remote(s) (override with --force)\n"
831 unless $force;
832 exit(255) unless $force || $dryrun;
833 warn "Adopting mirror with empty fetch remote(s) with --force\n"
834 unless $quiet || !$force;
836 warn "Will set skipDefaultUpdate=true on non-fetch remote(s)\n" if !$quiet && $usingall && @needskip;
837 warn "Adopting mirror with base URL \"$baseurl\"\n" unless $quiet || $baseurl eq "";
838 } else {
839 warn "Adopting push \"$projname\" but active non-mirror remotes are present\n"
840 if !$quiet && $foundfetch && !$foundfetchwithmirror;
843 if (!$noowner && !defined($owner)) {
844 # Select the owner
845 $owner = $config{"gitweb.owner"};
846 if (!defined($owner) || $owner eq "") {
847 $owner = $Girocco::Config::admin;
848 warn "Using owner \"$owner\" for adopted project\n" unless $quiet;
851 if (!$nousers && !$makemirror && !defined($users)) {
852 # select user list for push project
853 my $findowner = $owner;
854 defined($findowner) or $findowner = $config{"gitweb.owner"};
855 $findowner = lc($findowner) if defined($findowner);
856 my @owner_users = ();
857 @owner_users = map {$findowner eq lc($$_[4]) ? $$_[1] : ()} get_all_users
858 if defined($findowner) && $findowner ne "";
859 if (@owner_users <= 1) {
860 $users = \@owner_users;
861 warn "No users found that match owner \"$findowner\"\n" unless @owner_users || $quiet;
862 } else {
863 $users = [];
864 warn "Found ".scalar(@owner_users)." users for owner \"$findowner\" (" .
865 join(" ", @owner_users) . ") not setting any\n" unless $quiet;
868 defined($users) or $users = [];
870 # Warn if we preserve an existing receive.denyNonFastForwards or receive.denyDeleteCurrent setting
871 # Complain if core.logallrefupdates or logs subdir exists and contains any files (allow with --force
872 # and warn about preserving the setting)
874 warn "Preserving existing receive.denyNonFastForwards=true\n"
875 if !$quiet && git_bool($config{"receive.denynonfastforwards"});
876 warn "Preserving existing receive.denyDeleteCurrent=$config{'receive.denydeletecurrent'}\n"
877 if !$quiet && exists($config{"receive.denydeletecurrent"}) &&
878 $config{"receive.denydeletecurrent"} ne "warn";
880 my $reflogfiles = Girocco::Project::_contains_files("$projdir/logs");
881 my $reflogactive = git_bool($config{"core.logallrefupdates"});
882 if ($reflogactive || $reflogfiles) {
883 warn "Refusing to adopt \"$projname\" with active ref logs without --force\n" if $reflogfiles && !$force;
884 warn "Refusing to adopt \"$projname\" with core.logAllRefUpdates=true without --force\n" if $reflogactive && !$force;
885 exit(255) unless $force || $dryrun;
886 warn "Adopting \"$projname\" with active ref logs with --force\n" unless $quiet || ($reflogfiles && !$force);
887 warn "Adopting \"$projname\" with core.logAllRefUpdates=true with --force\n" unless $quiet || ($reflogactive && !$force);
890 return 0 if $dryrun && !$verbose;
892 my $newproj = eval {Girocco::Project->ghost($projname, $makemirror, 1, $dryrun)};
893 defined($newproj) or die "Girocco::Project::ghost failed: $@\n";
894 $newproj->{desc} = $desc;
895 $newproj->{README} = $readme;
896 $newproj->{url} = $baseurl if $makemirror || exists($config{"gitweb.baseurl"});
897 $newproj->{email} = $owner if defined($owner);
898 $newproj->{users} = $users;
899 $newproj->{crypt} = "unknown";
900 $newproj->{reverseorder} = 1 unless exists($config{"hooks.reverseorder"});
901 $newproj->{summaryonly} = 1 unless exists($config{"hooks.summaryonly"});
902 my $dummy = bless {}, "Girocco::Project";
903 $dummy->{path} = "$projdir";
904 $dummy->{configfilehash} = \%config;
905 $dummy->_properties_load;
906 delete $dummy->{origurl};
907 foreach my $k (keys(%$dummy)) {
908 $newproj->{$k} = $dummy->{$k}
909 if exists($dummy->{$k}) && !exists($newproj->{$k});
912 if ($verbose) {
913 use Data::Dumper;
914 my %info = %$newproj;
915 $info{README} = get_readme_desc($info{README}) if exists($info{README});
916 my $d = Data::Dumper->new([\%info], ['*'.$newproj->{name}]);
917 $d->Sortkeys(sub {[sort({lc($a) cmp lc($b)} keys %{$_[0]})]});
918 print $d->Dump([\%info], ['*'.$newproj->{name}]);
920 return 0 if $dryrun;
922 # Make any changes as needed for @needskip, $neednoprune and $needfakeorigin
923 if ($makemirror) {
924 git_config($projdir, "fetch.prune", "false") if $neednoprune;
925 git_config($projdir, "remote.origin.skipDefaultUpdate", "true") if $needfakeorigin;
926 if ($usingall && @needskip) {
927 git_config($projdir, "remote.$_.skipDefaultUpdate", "true") foreach @needskip;
931 # Perform the actual adoption
932 $newproj->adopt or die "Girocco::Project::adopt failed\n";
934 # Perhaps restore core.logAllRefUpdates, receive.denyNonFastForwards and receive.denyDeleteCurrent
935 git_config($projdir, "receive.denyNonFastForwards", "true")
936 if git_bool($config{"receive.denynonfastforwards"});
937 git_config($projdir, "receive.denyDeleteCurrent", $config{"receive.denydeletecurrent"})
938 if exists($config{"receive.denydeletecurrent"}) &&
939 $config{"receive.denydeletecurrent"} ne "warn";
940 git_config($projdir, "core.logAllRefUpdates", "true")
941 if $reflogactive;
943 # Success
944 if ($makemirror) {
945 warn "Mirror project \"$projname\" successfully adopted.\n" unless $quiet;
946 } else {
947 warn "Push project \"$projname\" successfully adopted.\n" unless $quiet;
949 return 0;
952 sub cmd_remove {
953 my ($force, $reallydel, $keepforks);
954 parse_options(force => \$force, "really-delete" => \$reallydel,
955 "keep-forks" => \$keepforks, quiet => \$quiet, q =>\$quiet);
956 @ARGV or die "Please give project name on command line.\n";
957 @ARGV == 1 or die_usage;
958 my $project = get_project($ARGV[0]);
959 my $projname = $project->{name};
960 my $isempty = !$project->{mirror} && $project->is_empty;
961 if (!$project->{mirror} && !$isempty && $reallydel) {
962 die "refusing to remove and delete non-empty push project without --force: $projname\n" unless $force;
963 warn "allowing removal and deletion of non-empty push project with --force\n" unless $quiet;
965 my $altwarn;
966 my $removenogc;
967 if ($project->has_forks) {
968 die "refusing to remove project with forks (use --keep-forks): $projname\n" unless $keepforks;
969 warn "allowing removal of forked project while preserving its forks with --keep-forks\n" unless $quiet;
970 # Run pseudo GC on that repository so that objects don't get lost within forks
971 my $basedir = $Girocco::Config::basedir;
972 my $projdir = $project->{path};
973 warn "We have to run pseudo GC on the repo so that the forks don't lose data. Hang on...\n" unless $quiet;
974 my $nogcrunning = sub {
975 die "Error: GC appears to be currently running on $projname\n"
976 if -e "$projdir/gc.pid" || -e "$projdir/.gc_in_progress";
978 &$nogcrunning;
979 $removenogc = ! -e "$projdir/.nogc";
980 recreate_file("$projdir/.nogc") if $removenogc;
981 die "unable to create \"$projdir/.nogc\"\n" unless -e "$projdir/.nogc";
982 delete $ENV{show_progress};
983 $ENV{'show_progress'} = 1 unless $quiet;
984 sleep 2; # *cough*
985 &$nogcrunning;
986 system("$basedir/toolbox/perform-pre-gc-linking.sh", "--include-packs", $projname) == 0
987 or die "Running pseudo GC on project $projname failed\n";
988 $altwarn = 1;
990 my $archived;
991 if (!$project->{mirror} && !$isempty && !$reallydel) {
992 $archived = $project->archive_and_delete;
993 unlink("$archived/.nogc") if $removenogc && defined($archived) && $archived ne "";
994 } else {
995 $project->delete;
997 warn "Project '$projname' removed from $Girocco::Config::name" .
998 ($archived ? ", backup in '$archived'" : "") .".\n" unless $quiet;
999 warn "Retained forks may now have unwanted objects/info/alternates lines\n" if $altwarn && !$quiet;
1000 return 0;
1003 sub cmd_show {
1004 use Data::Dumper;
1005 @ARGV == 1 or die_usage;
1006 my $project = get_clean_project($ARGV[0]);
1007 my %info = %$project;
1008 my $d = Data::Dumper->new([\%info], ['*'.$project->{name}]);
1009 $d->Sortkeys(sub {[sort({lc($a) cmp lc($b)} keys %{$_[0]})]});
1010 print $d->Dump([\%info], ['*'.$project->{name}]);
1011 return 0;
1014 sub cmd_listheads {
1015 @ARGV == 1 or die_usage;
1016 my $project = get_project($ARGV[0]);
1017 my @heads = sort({lc($a) cmp lc($b)} $project->get_heads);
1018 my $cur = $project->{HEAD};
1019 defined($cur) or $cur = '';
1020 my $curmark = '*';
1021 my $headhash = get_git("--git-dir=$project->{path}", 'rev-parse', '--quiet', '--verify', 'HEAD');
1022 defined($headhash) or $headhash = '';
1023 chomp $headhash;
1024 $headhash or $curmark = '!';
1025 foreach (@heads) {
1026 my $mark = $_ eq $cur ? $curmark : ' ';
1027 print "$mark $_\n";
1029 return 0;
1032 sub cmd_listtags {
1033 my $vcnt = 0;
1034 shift(@ARGV), $vcnt=1 if @ARGV && ($ARGV[0] eq '--verbose' || $ARGV[0] eq '-v');
1035 @ARGV == 1 or die_usage;
1036 my $project = get_project($ARGV[0]);
1037 if ($vcnt) {
1038 print map("$$_[0]\t$$_[1]\n", get_ctag_counts($project));
1039 } else {
1040 print map("$_\n", $project->get_ctag_names);
1042 return 0;
1045 sub cmd_deltags {
1046 my $ic = 0;
1047 shift(@ARGV), $ic=1 if @ARGV && $ARGV[0] =~ /^(?:--?ignore-case|-i)$/i;
1048 @ARGV >= 2 or die_usage;
1049 my $project = get_project(shift @ARGV);
1050 my %curtags;
1051 if ($ic) {
1052 push(@{$curtags{lc($_)}}, $_) foreach $project->get_ctag_names;
1053 } else {
1054 push(@{$curtags{$_}}, $_) foreach $project->get_ctag_names;
1056 my @deltags = ();
1057 my %seentag = ();
1058 my $ctags = join(" ", @ARGV);
1059 $ctags = lc($ctags) if $ic;
1060 foreach (split(/[\s,]+/, $ctags)) {
1061 next unless exists($curtags{$_});
1062 $seentag{$_}=1, push(@deltags, $_) unless $seentag{$_};
1064 if (!@deltags) {
1065 warn $project->{name}, ": skipping removal of only non-existent tags\n" unless $quiet;
1066 } else {
1067 # Avoid touching anything other than the ctags
1068 foreach my $tg (@deltags) {
1069 $project->delete_ctag($_) foreach @{$curtags{$tg}};
1071 $project->_set_changed;
1072 $project->_set_forkchange;
1073 warn $project->{name}, ": specified tags have been removed\n" unless $quiet;
1075 return 0;
1078 sub cmd_addtags {
1079 @ARGV >= 2 or die_usage;
1080 my $project = get_project(shift @ARGV);
1081 my $ctags = join(" ", @ARGV);
1082 $ctags =~ /[^, a-zA-Z0-9:.+#_-]/ and
1083 die "Content tag(s) \"$ctags\" contain(s) evil character(s).\n";
1084 my $oldmask = umask();
1085 umask($oldmask & ~0060);
1086 my $changed = 0;
1087 foreach (split(/[\s,]+/, $ctags)) {
1088 ++$changed if $project->add_ctag($_, 1);
1090 if ($changed) {
1091 $project->_set_changed;
1092 $project->_set_forkchange;
1094 umask($oldmask);
1095 my $cnt = ($changed == 1) ? "1 content tag has" : $changed . " content tags have";
1096 warn $project->{name}, ": $cnt been added/updated\n" unless $quiet;
1097 return 0;
1100 sub _get_random_val {
1101 my $p = shift;
1102 my $md5;
1104 no warnings;
1105 $md5 = md5_hex(time . $$ . rand() . join(':',%$p));
1107 $md5;
1110 sub cmd_chpass {
1111 my $force = 0;
1112 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1113 my $random = undef;
1114 pop(@ARGV), $random=lc($ARGV[1]) if @ARGV==2 && $ARGV[1] =~ /^(?:random|unknown)$/i;
1115 @ARGV == 1 or die_usage;
1116 my $project = get_project($ARGV[0]);
1117 die "refusing to change locked password of project \"$ARGV[0]\" without --force\n"
1118 if $project->is_password_locked;
1119 my ($newpw, $rmsg);
1120 if ($random) {
1121 if ($random eq "random") {
1122 die "refusing to set random password without --force\n" unless $force;
1123 $rmsg = "set to random value";
1124 $newpw = _get_random_val($project);
1125 } else {
1126 die "refusing to set password hash to '$random' without --force\n" unless $force;
1127 $rmsg = "hash set to '$random'";
1128 $newpw = $random;
1130 } else {
1131 $rmsg = "updated";
1132 if (-t STDIN) {
1133 print "Changing admin password for project $ARGV[0]\n";
1134 my $np1 = prompt_noecho_nl_or_die("New password for project $ARGV[0] (echo is off)");
1135 $np1 ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
1136 my $np2 = prompt_noecho_nl_or_die("Retype new password for project $ARGV[0]");
1137 $np1 eq $np2 or die "Our high-paid security consultants have determined that\n" .
1138 "the admin passwords you have entered do not match each other.\n";
1139 $newpw = $np1;
1140 } else {
1141 $newpw = <STDIN>;
1142 defined($newpw) or die "missing new password on STDIN\n";
1143 chomp($newpw);
1146 $newpw ne "" or die "empty passwords are not permitted (brokenness will ensue)\n";
1147 my $old = $project->{crypt};
1148 $project->{crypt} = (defined($random) && $random ne "random") ? $newpw : scrypt_sha1($newpw);
1149 if (defined($old) && $old eq $project->{crypt}) {
1150 warn $project->{name}, ": skipping update of password hash to same value\n" unless $quiet;
1151 } else {
1152 # Avoid touching anything other than the password hash
1153 $project->_group_update;
1154 warn $project->{name}, ": admin password $rmsg (new hash stored)\n" unless $quiet;
1156 return 0;
1159 sub cmd_checkpw {
1160 @ARGV == 1 or die_usage;
1161 my $project = get_project($ARGV[0]);
1162 my $pwhash = $project->{crypt};
1163 defined($pwhash) or $pwhash = "";
1164 if ($pwhash eq "") {
1165 warn $project->{name}, ": no password required\n" unless $quiet;
1166 return 0;
1168 if ($project->is_password_locked) {
1169 warn $project->{name}, ": password is locked\n" unless $quiet;
1170 exit 1;
1172 my $checkpw;
1173 if (-t STDIN) {
1174 $checkpw = prompt_noecho_nl_or_die("Admin password for project $ARGV[0] (echo is off)");
1175 $checkpw ne "" or warn "checking for empty password as hash (very unlikely)\n" unless $quiet;
1176 } else {
1177 $checkpw = <STDIN>;
1178 defined($checkpw) or die "missing admin password on STDIN\n";
1179 chomp($checkpw);
1181 unless (Girocco::CLIUtil::check_passwd_match($pwhash, $checkpw)) {
1182 warn "password check failure\n" unless $quiet;
1183 exit 1;
1185 warn "admin password match\n" unless $quiet;
1186 return 0;
1189 sub cmd_gc {
1190 my ($force, $auto, $redelta);
1191 parse_options(force => \$force, quiet => \$quiet, q => \$quiet, auto => \$auto,
1192 redelta => \$redelta, "no-reuse-delta" => \$redelta, aggressive => \$force);
1193 $force && $auto and die "--force and --auto are mutually exclusive options\n";
1194 @ARGV or die "Please give project name on command line.\n";
1195 @ARGV == 1 or die_usage;
1196 my $project = get_project($ARGV[0]);
1197 $quiet or $ENV{"show_progress"} = 1;
1198 $force and $ENV{"force_gc"} = 1;
1199 if (!$auto && !$force && ! -e $project->{path}."/.needsgc") {
1200 open NEEDSGC, '>', $project->{path}."/.needsgc" and close NEEDSGC;
1202 my @args = ($Girocco::Config::basedir . "/jobd/gc.sh", $project->{name});
1203 $redelta and push(@args, "-f");
1204 my $lastgc = $project->{lastgc};
1205 system({$args[0]} @args) != 0 and return 1;
1206 # Do it again Sam, but only if lastgc was set, gc.sh succeeded and now it's not set
1207 if ($lastgc) {
1208 my $newlastgc = get_git("--git-dir=$project->{path}", 'config', '--get', 'gitweb.lastgc');
1209 if (!$newlastgc) {
1210 system({$args[0]} @args) != 0 and return 1;
1213 return 0;
1216 sub cmd_remirror {
1217 my $force = 0;
1218 parse_options(force => \$force, quiet => \$quiet, q => \$quiet);
1219 @ARGV or die "Please give project name on command line.\n";
1220 @ARGV == 1 or die_usage;
1221 my $project = get_project($ARGV[0]);
1222 $project->{mirror} or die "Project \"$ARGV[0]\" is a push project, not a mirror project.\n";
1223 if ($project->{clone_in_progress} && !$project->{clone_failed}) {
1224 warn "Project \"$ARGV[0]\" already seems to have a clone underway at this moment.\n" unless $quiet && $force;
1225 exit(255) unless $force;
1226 yes_to_continue_or_die("Are you sure you want to force a remirror");
1228 unlink($project->_clonefail_path);
1229 unlink($project->_clonelog_path);
1230 recreate_file($project->_clonep_path);
1231 my $sock = IO::Socket::UNIX->new($Girocco::Config::chroot.'/etc/taskd.socket') or
1232 die "cannot connect to taskd.socket: $!\n";
1233 select((select($sock),$|=1)[0]);
1234 $sock->print("clone ".$project->{name}."\n");
1235 # Just ignore reply, we are going to succeed anyway and the I/O
1236 # would apparently get quite hairy.
1237 $sock->flush();
1238 sleep 2; # *cough*
1239 $sock->close();
1240 warn "Project \"$ARGV[0]\" remirror initiated.\n" unless $quiet;
1241 return 0;
1244 sub cmd_setowner {
1245 my $force = 0;
1246 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1247 @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage;
1248 my $project = get_project($ARGV[0]);
1249 if (@ARGV == 2 && !valid_email($ARGV[1])) {
1250 die "invalid owner/email (use --force to accept): \"$ARGV[1]\"\n"
1251 unless $force;
1252 warn "using invalid owner/email with --force\n" unless $quiet;
1254 if (@ARGV == 2 && length($ARGV[1]) > 96) {
1255 die "owner/email longer than 96 chars (use --force to accept): \"$ARGV[1]\"\n"
1256 unless $force;
1257 warn "using longer than 96 char owner/email with --force\n" unless $quiet;
1259 my $old = $project->{email};
1260 if (@ARGV == 1) {
1261 print "$old\n" if defined($old);
1262 return 0;
1264 if (defined($old) && $old eq $ARGV[1]) {
1265 warn $project->{name}, ": skipping update of owner/email to same value\n" unless $quiet;
1266 } else {
1267 # Avoid touching anything other than "gitweb.owner"
1268 $project->_property_fput("email", $ARGV[1]);
1269 $project->_update_index;
1270 $project->_set_changed;
1271 warn $project->{name}, ": owner/email updated to \"$ARGV[1]\"\n" unless $quiet;
1273 return 0;
1276 sub cmd_setdesc {
1277 my $force = 0;
1278 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1279 @ARGV >= 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage;
1280 my $project = get_project(shift @ARGV);
1281 if (@ARGV && !valid_desc(join(" ", @ARGV))) {
1282 die "invalid description (use --force to accept): \"".join(" ", @ARGV)."\"\n"
1283 unless $force;
1284 warn "using invalid description with --force\n" unless $quiet;
1286 my $desc = clean_desc(join(" ", @ARGV));
1287 if (@ARGV && length($desc) > 1024) {
1288 die "description longer than 1024 chars (use --force to accept): \"$desc\"\n"
1289 unless $force;
1290 warn "using longer than 1024 char description with --force\n" unless $quiet;
1292 my $old = $project->{desc};
1293 if (!@ARGV) {
1294 print "$old\n" if defined($old);
1295 return 0;
1297 if (defined($old) && $old eq $desc) {
1298 warn $project->{name}, ": skipping update of description to same value\n" unless $quiet;
1299 } else {
1300 # Avoid touching anything other than description file
1301 $project->_property_fput("desc", $desc);
1302 $project->_set_changed;
1303 warn $project->{name}, ": description updated to \"$desc\"\n" unless $quiet;
1305 return 0;
1308 sub cmd_setreadme {
1309 my $force = 0;
1310 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1311 @ARGV == 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage;
1312 my $project = get_project($ARGV[0]);
1313 my $old = $project->{README};
1314 if (@ARGV == 1) {
1315 chomp $old if defined($old);
1316 print "$old\n" if defined($old) && $old ne "";
1317 return 0;
1319 my ($new, $raw, $newname);
1320 $newname = '';
1321 if ($ARGV[1] eq "-") {
1322 local $/;
1323 $new = <STDIN>;
1324 $raw = 1;
1325 $newname = "contents of <STDIN>";
1326 } elsif (lc($ARGV[1]) eq "automatic" || lc($ARGV[1]) eq "auto") {
1327 $new = "";
1328 } elsif (lc($ARGV[1]) eq "suppressed" || lc($ARGV[1]) eq "suppress") {
1329 $new = "<!-- suppress -->";
1330 } else {
1331 my $fn = $ARGV[1];
1332 $fn =~ s/^\@//;
1333 die "missing filename for README\n" unless $fn ne "";
1334 die "no such file: \"$fn\"\n" unless -f $fn && -r $fn;
1335 open F, '<', $fn or die "cannot open \"$fn\" for reading: $!\n";
1336 local $/;
1337 $new = <F>;
1338 close F;
1339 $raw = 1;
1340 $newname = "contents of \"$fn\"";
1342 defined($new) or $new = '';
1343 $project->{README} = to_utf8($new, 1);
1344 $project->_cleanup_readme;
1345 if (length($project->{README}) > 8192) {
1346 die "readme greater than 8192 chars is too long (use --force to override)\n"
1347 unless $force;
1348 warn "using readme greater than 8192 chars with --force\n" unless $quiet;
1350 if ($raw) {
1351 my $rd = get_readme_desc($project->{README});
1352 if ($rd ne "automatic" && $rd ne "suppressed") {
1353 my $xmllint = qx(command -v xmllint); chomp $xmllint;
1354 if (-f $xmllint && -x $xmllint) {
1355 my ($cnt, $err) = $project->_lint_readme(0);
1356 if ($cnt) {
1357 my $msg = "xmllint: $cnt error";
1358 $msg .= "s" unless $cnt == 1;
1359 print STDERR "$msg\n", "-" x length($msg), "\n", $err
1360 unless $force && $quiet;
1361 exit(255) unless $force;
1362 warn $project->{name} . ": using invalid raw HTML with --force\n" unless $quiet;
1364 } else {
1365 die "xmllint not available, refusing to use raw HTML without --force\n"
1366 unless $force;
1367 warn "xmllint not available using unchecked raw HTML with --force\n" unless $quiet;
1371 if (defined($old) && $old eq $project->{README}) {
1372 warn $project->{name}, ": skipping update of README to same value\n" unless $quiet;
1373 } else {
1374 # Avoid touching anything other than README.html file
1375 $project->_property_fput("README", $project->{README});
1376 $project->_set_changed;
1377 my $desc = get_readme_desc($project->{README});
1378 if ($newname) {
1379 $newname .= " ($desc)";
1380 } else {
1381 $newname = $desc;
1383 warn $project->{name}, ": README updated to $newname\n" unless $quiet;
1385 return 0;
1388 sub valid_head {
1389 my ($proj, $newhead) = @_;
1390 my %okheads = map({($_ => 1)} $proj->get_heads);
1391 exists($okheads{$newhead});
1394 sub cmd_sethead {
1395 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage;
1396 my $project = get_project($ARGV[0]);
1397 if (@ARGV == 2 && !valid_head($project, $ARGV[1])) {
1398 die "invalid head (try \"@{[basename($0)]} listheads $ARGV[0]\"): \"$ARGV[1]\"\n";
1400 my $old = $project->{HEAD};
1401 if (@ARGV == 1) {
1402 print "$old\n" if defined($old);
1403 return 0;
1405 if (defined($old) && $old eq $ARGV[1]) {
1406 warn $project->{name}, ": skipping update of HEAD symref to same value\n" unless $quiet;
1407 } else {
1408 # Avoid touching anything other than the HEAD symref
1409 $project->set_HEAD($ARGV[1]);
1410 warn $project->{name}, ": HEAD symref updated to \"refs/heads/$ARGV[1]\"\n" unless $quiet;
1412 return 0;
1415 our %boolfields;
1416 BEGIN {
1417 %boolfields = (
1418 cleanmirror => 1,
1419 reverseorder => 0,
1420 summaryonly => 0,
1421 statusupdates => 1,
1425 sub cmd_setbool {
1426 my $force = 0;
1427 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1428 @ARGV == 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage;
1429 my $project = get_project($ARGV[0]);
1430 if (!exists($boolfields{$ARGV[1]})) {
1431 die "invalid boolean field name: \"$ARGV[1]\" -- try \"help\"\n";
1433 if (@ARGV == 3 && $boolfields{$ARGV[1]} && !$project->{mirror}) {
1434 die "invalid boolean field for non-mirror (use --force to accept): \"$ARGV[1]\"\n"
1435 unless $force;
1436 warn "using mirror field on non-mirror with --force\n" unless $quiet;
1438 if (@ARGV == 3 && !valid_bool($ARGV[2])) {
1439 die "invalid boolean value: \"$ARGV[2]\"\n";
1441 my $bool = clean_bool($ARGV[2]);
1442 my $old = $project->{$ARGV[1]};
1443 if (@ARGV == 2) {
1444 print "$old\n" if defined($old);
1445 return 0;
1447 if (defined($old) && $old eq $bool) {
1448 warn $project->{name}, ": skipping update of $ARGV[1] to same value\n" unless $quiet;
1449 } else {
1450 # Avoid touching anything other than $ARGV[1] field
1451 $project->_property_fput($ARGV[1], $bool);
1452 warn $project->{name}, ": $ARGV[1] updated to $bool\n" unless $quiet;
1454 return 0;
1457 sub cmd_setautogchack {
1458 @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage;
1459 my $project = get_project($ARGV[0]);
1460 my $aghok = $Girocco::Config::autogchack &&
1461 ($project->{mirror} || $Girocco::Config::autogchack ne "mirror");
1462 my $old = defined($project->{autogchack}) ? clean_bool($project->{autogchack}) : "unset";
1463 if (@ARGV == 1) {
1464 print "$old\n" if $aghok;
1465 return 0;
1467 my $bool;
1468 if (lc($ARGV[1]) eq "unset") {
1469 $bool = "unset";
1470 } else {
1471 valid_bool($ARGV[1]) or die "invalid boolean value: \"$ARGV[1]\"\n";
1472 $bool = clean_bool($ARGV[1]);
1474 if (!$aghok) {
1475 die "\$Girocco::Config::autogchack is false\n" unless $Girocco::Config::autogchack;
1476 die "\$Girocco::Config::autogchack is only enabled for mirrors\n";
1478 if ($old eq $bool) {
1479 warn $project->{name}, ": autogchack value unchanged\n" unless $quiet;
1480 } else {
1481 if ($bool eq "unset") {
1482 system($Girocco::Config::git_bin, '--git-dir='.$project->{path},
1483 'config', '--unset', "girocco.autogchack");
1484 } else {
1485 system($Girocco::Config::git_bin, '--git-dir='.$project->{path},
1486 'config', '--bool', "girocco.autogchack", $bool);
1489 return system($Girocco::Config::basedir . "/jobd/maintain-auto-gc-hack.sh", $project->{name}) == 0
1490 ? 0 : 1;
1493 sub valid_url {
1494 my ($url, $type) = @_;
1495 $type ne 'baseurl' and return valid_web_url($url);
1496 valid_repo_url($url) or return 0;
1497 if ($Girocco::Config::restrict_mirror_hosts) {
1498 my $mh = extract_url_hostname($url);
1499 is_dns_hostname($mh) or return 0;
1500 !is_our_hostname($mh) or return 0;
1502 return 1;
1505 our %urlfields;
1506 BEGIN {
1507 %urlfields = (
1508 baseurl => ["url" , 1],
1509 homepage => ["hp" , 0],
1510 notifyjson => ["notifyjson", 0],
1514 sub cmd_seturl {
1515 my $force = 0;
1516 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1517 @ARGV == 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage;
1518 my $project = get_project($ARGV[0]);
1519 if (!exists($urlfields{$ARGV[1]})) {
1520 die "invalid URL field name: \"$ARGV[1]\" -- try \"help\"\n";
1522 if (@ARGV == 3 && ${$urlfields{$ARGV[1]}}[1] && !$project->{mirror}) {
1523 die "invalid URL field for non-mirror (use --force to accept): \"$ARGV[1]\"\n"
1524 unless $force;
1525 warn "using mirror field on non-mirror with --force\n" unless $quiet;
1527 if (@ARGV == 3 && !valid_url($ARGV[2], $ARGV[1])) {
1528 die "invalid URL (use --force to accept): \"$ARGV[2]\"\n"
1529 unless $force;
1530 warn "using invalid URL with --force\n" unless $quiet;
1532 my $old = $project->{${$urlfields{$ARGV[1]}}[0]};
1533 if (@ARGV == 2) {
1534 print "$old\n" if defined($old);
1535 return 0;
1537 if (defined($old) && $old eq $ARGV[2]) {
1538 warn $project->{name}, ": skipping update of $ARGV[1] to same value\n" unless $quiet;
1539 } else {
1540 # Avoid touching anything other than $ARGV[1]'s field
1541 $project->_property_fput(${$urlfields{$ARGV[1]}}[0], $ARGV[2]);
1542 if ($ARGV[1] eq "baseurl") {
1543 $project->{url} = $ARGV[2];
1544 $project->_set_bangagain;
1546 $project->_set_changed unless $ARGV[1] eq "notifyjson";
1547 warn $project->{name}, ": $ARGV[1] updated to $ARGV[2]\n" unless $quiet;
1549 return 0;
1552 our %msgsfields;
1553 BEGIN {
1554 %msgsfields = (
1555 notifymail => 1,
1556 notifytag => 1,
1560 sub cmd_setmsgs {
1561 my $force = 0;
1562 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1563 @ARGV >= 3 || (@ARGV == 2 && !$force && !$setopt) or die_usage;
1564 my $project = get_project(shift @ARGV);
1565 my $field = shift @ARGV;
1566 if (!exists($msgsfields{$field})) {
1567 die "invalid msgs field name: \"$field\" -- try \"help\"\n";
1569 if (@ARGV && !valid_addrlist(@ARGV)) {
1570 die "invalid email address list (use --force to accept): \"".join(" ",@ARGV)."\"\n"
1571 unless $force;
1572 warn "using invalid email address list with --force\n" unless $quiet;
1574 my $old = $project->{$field};
1575 if (!@ARGV) {
1576 printf "%s\n", clean_addrlist($old, " ") if defined($old);
1577 return 0;
1579 my $newlist = clean_addrlist(join(" ",@ARGV));
1580 if (defined($old) && $old eq $newlist) {
1581 warn $project->{name}, ": skipping update of $field to same value\n" unless $quiet;
1582 } else {
1583 # Avoid touching anything other than $field's field
1584 $project->_property_fput($field, $newlist);
1585 warn $project->{name}, ": $field updated to \"$newlist\"\n" unless $quiet;
1587 return 0;
1590 sub cmd_setusers {
1591 my $force = 0;
1592 shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force';
1593 @ARGV >= 2 || (@ARGV == 1 && !$force && !$setopt) or die_usage;
1594 my $project = get_project(shift @ARGV);
1595 my $projname = $project->{name};
1596 !@ARGV || !$project->{mirror} or die "cannot set users list for mirror project: \"$projname\"\n";
1597 my @newusers = ();
1598 if (@ARGV) {
1599 eval {@newusers = validate_users(join(" ", @ARGV), $force); 1;} or exit 255;
1600 die "refusing to set empty users list without --force\n" unless @newusers || $force;
1602 return 0 if !@ARGV && $project->{mirror};
1603 my $oldusers = $project->{users};
1604 if ($oldusers && ref($oldusers) eq "ARRAY") {
1605 $oldusers = join("\n", @$oldusers);
1606 } else {
1607 $oldusers = "";
1609 if (!@ARGV) {
1610 print "$oldusers\n" if $oldusers ne "";
1611 return 0;
1613 if ($oldusers eq join("\n", @newusers)) {
1614 warn "$projname: skipping update of users list to same value\n" unless $quiet;
1615 } else {
1616 # Avoid touching anything other than the users list
1617 $project->{users} = \@newusers;
1618 $project->_update_users;
1619 warn "$projname: users list updated to \"@{[join(',',@newusers)]}\"\n" unless $quiet;
1621 return 0;
1624 our %fieldnames;
1625 BEGIN {
1626 %fieldnames = (
1627 owner => [\&cmd_setowner, 0],
1628 desc => [\&cmd_setdesc, 0],
1629 description => [\&cmd_setdesc, 0],
1630 readme => [\&cmd_setreadme, 0],
1631 head => [\&cmd_sethead, 0],
1632 HEAD => [\&cmd_sethead, 0],
1633 cleanmirror => [\&cmd_setbool, 1],
1634 reverseorder => [\&cmd_setbool, 1],
1635 summaryonly => [\&cmd_setbool, 1],
1636 statusupdates => [\&cmd_setbool, 1],
1637 autogchack => [\&cmd_setautogchack, 0],
1638 baseurl => [\&cmd_seturl, 1],
1639 homepage => [\&cmd_seturl, 1],
1640 notifyjson => [\&cmd_seturl, 1],
1641 notifymail => [\&cmd_setmsgs, 1],
1642 notifytag => [\&cmd_setmsgs, 1],
1643 users => [\&cmd_setusers, 0],
1647 sub do_getset {
1648 $setopt = shift;
1649 my @newargs = ();
1650 push(@newargs, shift) if @_ && $_[0] eq '--force';
1651 my $field = $_[1];
1652 (($setopt && @_ >= 3) || @_ == 2) && exists($fieldnames{$field}) or die_usage;
1653 push(@newargs, shift);
1654 shift unless ${$fieldnames{$field}}[1];
1655 push(@newargs, @_);
1656 diename(($setopt ? "set " : "get ") . $field);
1657 @ARGV = @newargs;
1658 &{${$fieldnames{$field}}[0]}(@ARGV);
1661 sub cmd_get {
1662 do_getset(0, @_);
1665 sub cmd_set {
1666 do_getset(1, @_);
1669 our %commands;
1670 BEGIN {
1671 %commands = (
1672 list => \&cmd_list,
1673 create => \&cmd_create,
1674 adopt => \&cmd_adopt,
1675 remove => \&cmd_remove,
1676 trash => \&cmd_remove,
1677 delete => \&cmd_remove,
1678 show => \&cmd_show,
1679 listheads => \&cmd_listheads,
1680 listtags => \&cmd_listtags,
1681 listctags => \&cmd_listtags,
1682 deltags => \&cmd_deltags,
1683 delctags => \&cmd_deltags,
1684 addtags => \&cmd_addtags,
1685 addctags => \&cmd_addtags,
1686 chpass => \&cmd_chpass,
1687 checkpw => \&cmd_checkpw,
1688 gc => \&cmd_gc,
1689 remirror => \&cmd_remirror,
1690 setowner => \&cmd_setowner,
1691 setdesc => \&cmd_setdesc,
1692 setdescription => \&cmd_setdesc,
1693 setreadme => \&cmd_setreadme,
1694 sethead => \&cmd_sethead,
1695 setbool => \&cmd_setbool,
1696 setautogchack => \&cmd_setautogchack,
1697 setflag => \&cmd_setbool,
1698 seturl => \&cmd_seturl,
1699 setmsgs => \&cmd_setmsgs,
1700 setusers => \&cmd_setusers,
1701 get => \&cmd_get,
1702 set => \&cmd_set,
1706 sub dohelp {
1707 my $bn = basename($0);
1708 printf "%s version %s\n\n", $bn, $VERSION;
1709 printf $help, $bn;
1710 exit 0;
1713 sub main {
1714 local *ARGV = \@_;
1715 shift, $quiet=1 if @ARGV && $ARGV[0] =~ /^(?:-q|--quiet)$/i;
1716 dohelp if !@ARGV || @ARGV && $ARGV[0] =~ /^(?:-h|-?-help|help)$/i;
1717 my $command = shift;
1718 diename($command);
1719 $setopt = 1;
1720 if (!exists($commands{$command}) && exists($commands{"set".$command})) {
1721 $setopt = 0;
1722 $command = "set" . $command;
1724 exists($commands{$command}) or die "Unknown command \"$command\" -- try \"help\"\n";
1725 dohelp if @ARGV && $ARGV[0] =~ /^(?:-h|-?-help|help)$/i && !Girocco::Project::does_exist("help",1);
1726 &{$commands{$command}}(@ARGV);