| 1 | #!/usr/bin/env perl | ||||||||||||||||||||
| 2 | 4 | ▶ | use v5.24; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 4 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 4 | ▶ | use Yukki::Web; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 4 | ▶ | use Yukki::TextUtil qw( load_file ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 4 | ▶ | use autodie; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 4 | ▶ | use File::ShareDir qw( module_dir ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 4 | ▶ | use Path::Tiny; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 4 | my $site_dir = shift; | |||||||||||||||||||
| 13 | 4 | my $skel_dir = shift; | |||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 4 | ▶ | die "usage: $0 path/to/new-site-directory [path/to/skel]\n" unless $site_dir; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 16 | 4 | ▶ | die qq[A file or directory named "$site_dir" already exists, will not overwrite.\n] | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 17 | if -e $site_dir; | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 4 | my $root = path($site_dir)->absolute; | |||||||||||||||||||
| 20 | 4 | ▶ | my $module_dir = path($skel_dir // module_dir('Yukki::Web')); | ||||||||||||||||||
|
Condition33%1/3
$skel_dir // module_dir("Yukki::Web")
MC/DC0%0/2
$skel_dir // module_dir("Yukki::Web")
$skel_dir
module_dir("Yukki::Web")
Truth table33%1/3
A // B
A= $skel_dirB= module_dir("Yukki::Web")
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 4 | $root->mkpath; | |||||||||||||||||||
| 23 | $module_dir->visit( | ||||||||||||||||||||
| 24 | sub { | ||||||||||||||||||||
| 25 | 572 | ▶ | my ($path, $state) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 26 | 572 | my $new_path = $path->relative($module_dir)->absolute($root); | |||||||||||||||||||
| 27 | 572 | ▶ | if ($path->is_dir) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | 96 | $new_path->mkpath; | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | else { | ||||||||||||||||||||
| 31 | 476 | $path->copy($new_path); | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | }, | ||||||||||||||||||||
| 34 | 4 | { recurse => 1 }, | |||||||||||||||||||
| 35 | ); | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 4 | my $yaml = path($root, 'etc', 'yukki.conf'); | |||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | # Don't use YAML to load the file or we'll lose spaces and comments | ||||||||||||||||||||
| 40 | 4 | rename $yaml, "$yaml~"; | |||||||||||||||||||
| 41 | 4 | open my $out_config, '>:encoding(UTF-8)', $yaml; | |||||||||||||||||||
| 42 | 4 | open my $in_config, '<:encoding(UTF-8)', "$yaml~"; | |||||||||||||||||||
| 43 | 4 | ▶ | while (my $line = <$in_config>) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 380 | ▶ | if ($line =~ /^root:/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | 4 | $line = "root: $root\n"; | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | 380 | print $out_config $line; | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | 4 | close $out_config; | |||||||||||||||||||
| 50 | 4 | close $in_config; | |||||||||||||||||||
| 51 | 4 | unlink "$yaml~"; | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 4 | chmod 0444, "$yaml"; | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 4 | my $config = load_file($yaml); | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 4 | say "Please read the installation instructions if you have not:\n"; | |||||||||||||||||||
| 58 | 4 | say "\tperldoc Yukki::Manual::Installation\n"; | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 4 | say "The rest of these remarks assume you run this first:\n"; | |||||||||||||||||||
| 61 | 4 | say "\tcd $site_dir\n"; | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 4 | say "You probably want to setup your repositories by running:\n"; | |||||||||||||||||||
| 64 | 4 | for (sort keys %{ $config->{repositories} }) { | |||||||||||||||||||
| 65 | 8 | ▶ | if (/^yukki$/) { say "\tyukki-git-init $_ git://github.com/zostay/yukki-help.git" } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | 4 | else { say "\tyukki-git-init $_" } | |||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | 4 | print "\n"; | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 4 | say "And then you'll want at least one user, so run:\n"; | |||||||||||||||||||
| 71 | 4 | say "\tyukki-add-user\n"; | |||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 4 | say "To start your Yukki server, run:\n"; | |||||||||||||||||||
| 74 | 4 | say "\tcd $site_dir; plackup yukki.psgi\n"; | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 4 | say "Have a nice day!"; | |||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | # ABSTRACT: constructs the boilerplate needed to start a Yukki site | ||||||||||||||||||||
| 79 | # PODNAME: yukki-setup | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | __END__ | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | =pod | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | =encoding UTF-8 | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | =head1 NAME | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | yukki-setup - constructs the boilerplate needed to start a Yukki site | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | =head1 VERSION | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | version 0.991_002 | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | =head1 SYNOPSIS | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | yukki-setup site-directory | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | =head1 DESCRIPTION | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | Creates a new Yukki site directory at the location named in the single command line argument. Everything else is automatic. | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | After it completes it reminds you to take a few additional required actions. | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | =head1 ENVIRONMENT | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | Normally, this script tries to find F<etc/yukki.conf> from the current working | ||||||||||||||||||||
| 108 | directory. If no configuraiton file is found, it checks C<YUKKI_CONFIG> for the | ||||||||||||||||||||
| 109 | path to this file. | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | =head1 AUTHOR | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | Andrew Sterling Hanenkamp <hanenkamp@cpan.org> | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | This software is copyright (c) 2017 by Qubling Software LLC. | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 120 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | =cut | ||||||||||||||||||||