tcms-hostname 966 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. use FindBin::libs;
  5. use Trog::Config();
  6. use Getopt::Long qw{GetOptionsFromArray};
  7. my $user;
  8. GetOptionsFromArray(\@ARGV,
  9. 'user' => \$user,
  10. );
  11. my $hostname = $ARGV[0];
  12. my $conf = Trog::Config->get();
  13. if ($hostname) {
  14. $conf->param('general.hostname', $hostname);
  15. # write(), not save(). save() writes back to whatever file get() loaded,
  16. # which is the tracked config/default.cfg until the instance has saved a
  17. # configuration of its own.
  18. $conf->write($Trog::Config::home_cfg) or die "Could not write $Trog::Config::home_cfg";
  19. }
  20. my $domain = $conf->param('general.hostname');
  21. die "Hostname not set in tCMS configuration. Please set this first by passing the hostname to bin/tcms-hostname." unless $domain;
  22. # Transform the domain name into something maximally compatible with being a username.
  23. if ($user) {
  24. $domain = substr($domain, 0, 32);
  25. $domain =~ s/\./-/g;
  26. }
  27. print "$domain\n";