<% use Cwd qw/getcwd realpath/; use File::Copy 'copy'; # Parameter my $op = param('op') || ''; # Outputs my @outputs; # Error my $error; # App absolute path my $app_abs_path; if ($op eq 'setup') { # Setup directory my $setup_dir = getcwd; # Home directory my $home_dir = realpath($setup_dir . '/..'); # Script directory my $script_dir = realpath($setup_dir . '/../script'); # cpanm Path my $cpanm_path = "$home_dir/cpanm"; # cpanm home directory $ENV{PERL_CPANM_HOME} = $setup_dir; # Setup script absolute path my $setup_script_abs_path = url_for->to_string; # Application script absolute path $app_abs_path = $setup_script_abs_path; $app_abs_path =~ s#\Q/setup/setup.cgi#.cgi#; # Application script name my ($app_name) = $app_abs_path =~ /([0-9a-zA-Z-_]+\.cgi)$/; # Application script file my $app_file = "$script_dir/$app_name"; # Place application script is moved to my $app_to = realpath("$home_dir/../$app_name"); # Change directory if (chdir $home_dir) { # Install Module::CoreList my $cmd = 'perl cpanm -n -l extlib Module::CoreList 2>&1'; if (open my $fh, "$cmd |") { local $/; my $output = <$fh>; push @outputs, $output; if (close $fh) { # Install modules my $cmd = 'perl -Iextlib/lib/perl5 ' . 'cpanm -n -L extlib --installdeps . 2>&1'; if (open my $fh, "$cmd |") { local $/; my $output = <$fh>; push @outputs, $output; if (close $fh) { # Copy application file if (copy $app_file, $app_to) { push @outputs, "$app_file is moved to $app_to"; # Change mode if (chmod(0755, $app_to)) { push @outputs, "change $app_to mode to 755"; } else { $error = 1; app->log->error("Can't change mode $app_to"); } } else { $error = 1; app->log->error("Can't move $app_file to $app_to"); } } else { $error = 1; app->log->error("Can't close pipe install modules: $!"); } } else { my $error = 1; app->log->error("Can't open pipe install modules: $!"); } } else { $error = 1; app->log->error("Can't close pipe install Module::CoreList: $!"); } } else { $error = 1; app->log->error("Can't open pipe install Module::CoreList: $!"); } } else { $error = 1; app->log->error("Can't cahgne directory: $!"); } } %> Setup

Setup


Click only once. Wait for a few minutes.

% if ($op eq 'setup') { Result
% if ($error) {
Error, Setup failed. See setup/log/production.log
% }
% unless ($error) {
% for my $line (@outputs) {
%= $line
% }
% }
% } % if ($op eq 'setup' && !$error) {
Go to Application
% }